public async Task <ActionResult <PerformErrandResultViewModel> > Post([FromBody] PerformErrandViewModel performErrandViewModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var actor = await _botOMatContext.ErrandActors.Include(e => e.Errands).FirstOrDefaultAsync(e => e.Id == performErrandViewModel.ActorId); if (actor == null) { return(NotFound()); } await NotifyTaskStarted(actor, performErrandViewModel); var result = await _errandService.PerformErrand(actor, performErrandViewModel.ErrandType); await NotifyTaskCompletionStatus(result); return(new PerformErrandResultViewModel(result)); }
private async Task NotifyTaskStarted(Data.DbSets.ErrandActor actor, PerformErrandViewModel errand) { await _notificationHub.Clients.All.SendAsync("Notify", new Notification($"{actor.Name} ({Enum.GetName(typeof(ActorType), actor.ActorType)}) has started task: { Enum.GetName(typeof(ErrandType), errand.ErrandType) }!", SeverityLevel.Info)); }