/// <exception cref="InvalidOperationException">Thrown if the track was not created for any reason.</exception> public async Task CreateTrackAsync(MissionTrack newTrack) { Log.Info( $"Creating new Mission Track id={newTrack.Id} Name={newTrack.Name} in mission {newTrack.MissionLevelId} with badge id={newTrack.BadgeId}"); var maybeBadge = unitOfWork.Badges.GetMaybe(newTrack.BadgeId); if (maybeBadge.None) { Log.Error($"Create blocked because the target badge id={newTrack.BadgeId} does not exist"); throw new InvalidOperationException("The associated Mission Level could not be found"); } var targetLevel = unitOfWork.MissionLevels.GetMaybe(newTrack.MissionLevelId); if (targetLevel.None) { Log.Error($"Create blocked because the target level id={newTrack.MissionLevelId} does not exist"); throw new InvalidOperationException("The associated Mission Level could not be found"); } var missionTracks = unitOfWork.MissionTracks.GetAll(); if (missionTracks.Any(p => p.MissionLevelId == newTrack.MissionLevelId && p.Number == newTrack.Number)) { Log.Warn("Create blocked because the track already exists"); throw new InvalidOperationException("That track number already exists"); } unitOfWork.MissionTracks.Add(newTrack); await unitOfWork.CommitAsync(); Log.Info($"Successfully added track id={newTrack.Id}"); }
public MissionBuilder <TContoller> BuildTrack() { var track = new MissionTrack { Id = trackId, AwardTitle = trackAwardTitle, Challenges = challenges, Name = trackName, Number = trackNumber, BadgeId = badge.Id, Badge = badge }; mission.tracks.Add(track); return(mission); }
/// <summary> /// Notifies the user that they have been awarded a badge. /// </summary> /// <param name="badge">The badge that was awarded.</param> /// <param name="user">The recipient user.</param> /// <param name="track">The track that was completed resulting in the award.</param> public async Task BadgeAwarded(Badge badge, ApplicationUser user, MissionTrack track) { Log.Info($"Notifying user {user.Id} <{user.UserName}> of awarded badge id={badge.Id} name={badge.Name}"); var model = new BadgeAwardedEmailModel { Recipient = user.Email, MissionTitle = track.MissionLevel.Mission.Title, InformationUrl = HomePage, BadgeName = badge.Name, LevelAwardTitle = track.MissionLevel.AwardTitle, TrackName = track.Name }; var emailBody = razor.RunCompile("BadgeAwarded.cshtml", typeof(BadgeAwardedEmailModel), model); await userManager.SendEmailAsync(user.Id, "Badge Awarded", emailBody); Log.Info($"Successfully notified user {user.Id} <{user.UserName}> of awarded badge id={badge.Id} name={badge.Name}"); }
public Task BadgeAwarded(Badge badge, ApplicationUser user, MissionTrack track) { return(Task.FromResult(0)); }