-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #229 from pticostaricags/development
Adding functionality to import contacts from custom excel file
- Loading branch information
Showing
11 changed files
with
159 additions
and
20 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/FairPlayCombinedSln/FairPlayCRM.SharedUI/Components/Pages/User/ExcelContactsImport.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@implements IAsyncDisposable | ||
|
||
@using FairPlayCombined.Common | ||
@using FairPlayCombined.Interfaces.Common | ||
@attribute [Route(Constants.Routes.FairPlayCrmRoutes.UserRoutes.ExcelContactsImport)] | ||
@attribute [Authorize] | ||
|
||
@inject IContactService contactService | ||
@inject IToastService toastService | ||
|
||
<h3>Contacts Import</h3> | ||
|
||
|
||
<LoadingIndicator ShowSpinners="@this.IsBusy"></LoadingIndicator> | ||
|
||
<p> | ||
Select file to import | ||
</p> | ||
<InputFile OnChange="OnFileSelectedAsync"></InputFile> | ||
|
||
@code { | ||
private bool IsBusy { get; set; } | ||
private readonly CancellationTokenSource cancellationTokenSource = new(); | ||
|
||
private async Task OnFileSelectedAsync(InputFileChangeEventArgs inputFileChangeEventArgs) | ||
{ | ||
try | ||
{ | ||
this.IsBusy = true; | ||
StateHasChanged(); | ||
if (inputFileChangeEventArgs.FileCount == 1) | ||
{ | ||
var stream = inputFileChangeEventArgs.File.OpenReadStream(); | ||
MemoryStream streamCopy = new(); | ||
await stream.CopyToAsync(streamCopy); | ||
await this.contactService | ||
.ImportFromExcelFileAsync(streamCopy, this.cancellationTokenSource.Token); | ||
this.toastService.ShowSuccess("Contacts have been imported"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
this.toastService.ShowError(ex.Message); | ||
} | ||
finally | ||
{ | ||
this.IsBusy = false; | ||
StateHasChanged(); | ||
} | ||
} | ||
|
||
public ValueTask DisposeAsync() | ||
{ | ||
this.cancellationTokenSource.Dispose(); | ||
return ValueTask.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters