Gestito aggiornamento elenco contatti in caso di aggiunta o modifica del prospect / cliente
This commit is contained in:
@@ -7,7 +7,9 @@
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Components.SingleElements
|
||||
@using salesbook.Shared.Core.Entity
|
||||
@using salesbook.Shared.Core.Messages.Contact
|
||||
@inject IManageDataService ManageData
|
||||
@inject NewContactService NewContact
|
||||
|
||||
<HeaderLayout Title="Contatti"/>
|
||||
|
||||
@@ -65,6 +67,11 @@
|
||||
private FilterUserDTO Filter { get; set; } = new();
|
||||
private string TypeUser { get; set; } = "all";
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
NewContact.OnContactCreated += async activityId => await OnActivityCreated(activityId);
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
if (firstRender)
|
||||
@@ -186,6 +193,91 @@
|
||||
FilteredGroupedUserList = result;
|
||||
}
|
||||
|
||||
private async Task OnActivityCreated(CRMCreateContactResponseDTO response)
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
string codAnag;
|
||||
bool isContact;
|
||||
|
||||
switch (response)
|
||||
{
|
||||
case null:
|
||||
return;
|
||||
case { AnagClie: null, PtbPros: not null }:
|
||||
await ManageData.InsertOrUpdate(response.PtbPros);
|
||||
isContact = false;
|
||||
codAnag = response.PtbPros.CodPpro!;
|
||||
break;
|
||||
case { AnagClie: not null, PtbPros: null }:
|
||||
await ManageData.InsertOrUpdate(response.AnagClie);
|
||||
isContact = true;
|
||||
codAnag = response.AnagClie.CodAnag!;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
var contact = await ManageData.GetSpecificContact(codAnag, isContact);
|
||||
if (contact == null)
|
||||
{
|
||||
IsLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var firstChar = char.ToUpper(contact.RagSoc![0]);
|
||||
var currentLetter = char.IsLetter(firstChar) ? firstChar.ToString() : "#";
|
||||
|
||||
var insertIndex = -1;
|
||||
var foundHeader = false;
|
||||
|
||||
for (var i = 0; i < GroupedUserList.Count; i++)
|
||||
{
|
||||
var current = GroupedUserList[i];
|
||||
|
||||
if (!current.ShowHeader || current.HeaderLetter != currentLetter) continue;
|
||||
foundHeader = true;
|
||||
insertIndex = i + 1;
|
||||
|
||||
while (insertIndex < GroupedUserList.Count &&
|
||||
GroupedUserList[insertIndex].HeaderLetter == currentLetter &&
|
||||
string.Compare(contact.RagSoc, GroupedUserList[insertIndex].User.RagSoc, StringComparison.OrdinalIgnoreCase) > 0)
|
||||
{
|
||||
insertIndex++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (!foundHeader)
|
||||
{
|
||||
var headerItem = new UserDisplayItem
|
||||
{
|
||||
HeaderLetter = currentLetter,
|
||||
ShowHeader = true,
|
||||
User = contact
|
||||
};
|
||||
|
||||
GroupedUserList.Add(headerItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newItem = new UserDisplayItem
|
||||
{
|
||||
HeaderLetter = currentLetter,
|
||||
ShowHeader = false,
|
||||
User = contact
|
||||
};
|
||||
|
||||
GroupedUserList.Insert(insertIndex, newItem);
|
||||
}
|
||||
|
||||
FilterUsers();
|
||||
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
|
||||
private void ToggleFilter()
|
||||
{
|
||||
OpenFilter = !OpenFilter;
|
||||
|
||||
Reference in New Issue
Block a user