public override async Task Handle(HandlerContext <Command> context) { IQueryable <string> query = from rosterMail in CompositionRoot.Databases.Snittlistan.RosterMails where rosterMail.RosterKey == context.Payload.RosterKey && rosterMail.PublishedDate == null select rosterMail.RosterKey; string[] rosterIds = await query.ToArrayAsync(); Logger.InfoFormat("roster mails found: {@rosterIds}", rosterIds); if (rosterIds.Any() == false) { TenantFeatures features = await CompositionRoot.GetFeatures(); _ = CompositionRoot.Databases.Snittlistan.RosterMails.Add( new(context.Payload.RosterKey)); PublishRosterMailsTask task = new( context.Payload.RosterKey, context.Payload.RosterLink, context.Payload.UserProfileLink); context.PublishMessage(task, DateTime.Now.AddMinutes(features.RosterMailDelayMinutes)); } }
public async Task <ActionResult> EditPlayers(string rosterId, RosterPlayersViewModel vm) { if (ModelState.IsValid == false) { return(EditPlayers(rosterId)); } Roster roster = CompositionRoot.DocumentSession.Load <Roster>(rosterId); if (roster == null) { throw new HttpException(404, "Roster not found"); } Roster.Update update = new( Roster.ChangeType.EditPlayers, User.CustomIdentity.PlayerId ?? User.CustomIdentity.Email) { Preliminary = vm.Preliminary }; List <string>?players = null; if (roster.IsFourPlayer) { players = new List <string> { vm.Player1 !, vm.Player2 !, vm.Player3 !, vm.Player4 ! }; } else { players = new List <string> { vm.Table1Player1 !, vm.Table1Player2 !, vm.Table2Player1 !, vm.Table2Player2 !, vm.Table3Player1 !, vm.Table3Player2 !, vm.Table4Player1 !, vm.Table4Player2 ! }; } if (vm.Reserve1 != null && CompositionRoot.DocumentSession.Load <Player>(vm.Reserve1) != null) { players.Add(vm.Reserve1); if (vm.Reserve2 != null && CompositionRoot.DocumentSession.Load <Player>(vm.Reserve2) != null) { players.Add(vm.Reserve2); } } // case where reserve1 is unselected while reserve2 is selected if (vm.Reserve2 != null && players.Find(x => x == vm.Reserve2) == null && CompositionRoot.DocumentSession.Load <Player>(vm.Reserve2) != null) { players.Add(vm.Reserve2); } update.Players = players; if (vm.TeamLeader != null && CompositionRoot.DocumentSession.Load <Player>(vm.TeamLeader) != null) { update.TeamLeader = vm.TeamLeader; } else { update.TeamLeader = new Some <string?>(null); } do { AuditLogEntry?auditLogEntry = roster.UpdateWith(CompositionRoot.CorrelationId, update); if (auditLogEntry is null) { Logger.InfoFormat( "roster saved without any registered changes: {rosterId} {@vm}", rosterId, vm); break; } TenantFeatures features = await CompositionRoot.GetFeatures(); if (features.RosterMailEnabled == false) { Logger.Info("RosterMailEnabled evaluated to false"); break; } if (roster.Preliminary) { Logger.InfoFormat( "Roster is preliminary, not sending requested update mail: {rosterId}", rosterId); break; } if (roster.Date < SystemTime.UtcNow.ToLocalTime()) { Logger.WarnFormat( "Roster date has passed, not sending requested update mail: {rosterId}", rosterId); break; } string uriString = Url.Action( "View", "Roster", new { roster.Season, roster.Turn }); string portPart = Request.Url.Port == 80 ? string.Empty : $":{Request.Url.Port}"; Uri rosterLink = CreateLink("View", "Roster", new { roster.Season, roster.Turn }); Uri userProfileLink = CreateLink("Index", "UserProfile"); await ExecuteCommand( new CreateRosterMailCommandHandler.Command( rosterId, rosterLink, userProfileLink)); }while (false); return(RedirectToAction("View", new { season = roster.Season, turn = roster.Turn })); }