public async Task UpdateAsync(CommunityUpdateViewModel communityVM) { var currentCommunity = await db.Communities.FindAsync(communityVM.ShortName).ConfigureAwait(false); currentCommunity.SetConfirmation(communityVM.Confirmed); currentCommunity.SetWebSite(new Uri(communityVM.WebSite)); var updateManagers = communityVM.Managers.ToList(); // Manager da rimuovere o già presenti foreach (var m in currentCommunity.Managers) { var foundManager = updateManagers.Find(x => x.Id == m.Id); if (foundManager == null) { currentCommunity.RemoveManager(m.Id); } else { updateManagers.Remove(foundManager); } } // Manager da aggiungere foreach (var m in updateManagers) { var person = await db.People.FindAsync(m.Id).ConfigureAwait(false); currentCommunity.AddManager(person.ToOwned()); } db.Communities.Update(currentCommunity); await db.SaveChangesAsync().ConfigureAwait(false); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); CommunityViewModel = AppStore.CommunityEdit; AppStore.CommunityImage = null; }
public async Task <string> RunOrchestrator( [OrchestrationTrigger] IDurableOrchestrationContext context) { var vm = context.GetInput <CommunityViewModel>(); string id = await context.CallActivityAsync <string>(ConfirmationTask.CreateCommunity, vm); var vmUpdate = CommunityUpdateViewModel.Create(vm); vmUpdate.ShortName = id; var activateSendMail = new ActivateCommunitySendMail { Data = vmUpdate, InstanceId = context.InstanceId }; await context.CallActivityAsync(ConfirmationTask.SendMailCommunity, activateSendMail); await HumanInteractionCommunity(context, vmUpdate); return(id); }
public async Task <CommunityUpdateViewModel> GetById(string id) { var currentCommunity = await db.Communities.FindAsync(id).ConfigureAwait(false); if (currentCommunity == null) { throw new ArgumentOutOfRangeException($"Community {id} not exists"); } CommunityUpdateViewModel communityVM = new CommunityUpdateViewModel { Name = currentCommunity.Name, Logo = currentCommunity.Logo, Confirmed = currentCommunity.Confirmed, ShortName = currentCommunity.ShortName, WebSite = currentCommunity.WebSite.ToString(), Managers = currentCommunity.ManagerCollection.Select(t => new PersonUpdateViewModel { Id = t }).ToList() }; for (int i = 0; i < communityVM.Managers.Count; i++) { var p = await db.People.FindAsync(communityVM.Managers.ElementAt(i).Id); communityVM.Managers[i] = new PersonUpdateViewModel { Id = p.Id, Name = p.Name, Surname = p.Surname, Picture = p.Picture, MVP_Code = p.MVP_Code, Confirmed = p.Confirmed }; } return(communityVM); }
public async Task <HttpResponseMessage> UpdateCommunity(CommunityUpdateViewModel vm) { return(await Http.PutAsJsonAsync($"Community", vm, JsonOption).ConfigureAwait(false)); }
public async Task <bool> HumanInteractionCommunity(IDurableOrchestrationContext context, CommunityUpdateViewModel vm) { using (var timeoutCts = new CancellationTokenSource()) { DateTime expiration = context.CurrentUtcDateTime.AddDays(6); Task timeoutTask = context.CreateTimer(expiration, timeoutCts.Token); bool authorized = false; for (int retryCount = 0; retryCount <= 3; retryCount++) { Task <bool> challengeResponseTask = context.WaitForExternalEvent <bool>(ConfirmationTask.ConfirmCommunityHuman); Task winner = await Task.WhenAny(challengeResponseTask, timeoutTask); if (winner == challengeResponseTask) { // We got back a response! Compare it to the challenge code. if (challengeResponseTask.Result) { vm.Confirmed = challengeResponseTask.Result; await context.CallActivityAsync(ConfirmationTask.ApproveCancelCommunityOnCosmos, vm); break; } } else { // Timeout expired break; } } if (!timeoutTask.IsCompleted) { // All pending timers must be complete or canceled before the function exits. timeoutCts.Cancel(); } return(authorized); } }
public async Task ApproveCancelCommunityOnCosmos([ActivityTrigger] CommunityUpdateViewModel vm, ILogger log) { await communityService.UpdateAsync(vm).ConfigureAwait(false); }
void Edit(CommunityUpdateViewModel args) { AppStore.CommunityEdit = args; NavigationManager.NavigateTo(Routes.CommunityEdit(AppStore.CommunityEdit.ShortName)); }