protected override VerseData OnPostVerseForPoem(Poem poem, AddVerseModel verseModel, VerseEngineeringUser user) { Verse verse = verseService.GetById(verseModel.Id); if (verse == null) { verse = InsertCandidateVerseWithNoPreviousScratchVerseDefined(poem.Id, verseModel, user.UserId); return Mapper.Map<VerseData>(verse); } if ((verse.VerseType is ScratchVerseType) == false) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("Only Scratch verses can be submited to Candidates") }); } if (verse.AuthorProfileId != user.UserId) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("You are not allowed to modify verse which wasn't written by you") }); } if (poem.Id != verse.PoemId) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("Poem identifier is not equivalent with verse identifier") }); } verseService.UpdateVerse(verse, verseService.GetVerseType<CandidateVerseType>()); var response = Mapper.Map<VerseData>(verse); signalizerFactory.GetSignal<CandidateVerseAddedSignal<Raw>>() .FromUser(user.UserId, user.Name) .Send(poem.Id, response); return response; }
protected override VerseData OnPostVerseForPoem(Poem poem, AddVerseModel verseModel, VerseEngineeringUser user) { Verse verse = new Verse { AuthorProfileId = user.UserId, FromIpAddress = string.Empty, LastEdit = DateTime.UtcNow, WrittenAt = DateTime.UtcNow, Location = string.Empty, OrderNr = 0, PoemId = poem.Id, Text = verseModel.Text, }; verseService.Insert<ScratchVerseType>(verse); return Mapper.Map<VerseData>(verse); }
protected override VerseData OnPostVerseForPoem(Poem poem, AddVerseModel verseModel, VerseEngineeringUser user) { Verse verse = verseService.GetById(verseModel.Id); if (verse == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("No verse with such idetifier was found") }); } if (verse.VerseType is CandidateVerseType == false) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("Only Candidate verses can be submited to Poem") }); } if (poem.CurrentGm != user.UserId) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new StringContent("You are not allowed to post poem verses unless you are game master") }); } if (poem.Id != verse.PoemId) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent("Poem identifier is not equivalent with verse identifier") }); } verseService.UpdateVerse(verse, verseService.GetVerseType<PoemVerseType>()); VerseData response = Mapper.Map<VerseData>(verse); signalizerFactory.GetSignal<PoemVerseAddedSignal<Raw>>() .FromUser(user.UserId, user.Name) .Send(poem.Id, response); if (IsGameMasterChanged(poem.CurrentGm, verse.AuthorProfileId)) { UpdateGameMaster(poem, verse); signalizerFactory.GetSignal<PoemGameMasterChangedSignal<Raw>>() .FromUser(user.UserId, user.Name) .Send(poem.Id, Mapper.Map<UserProfileData>(poem.CurrentGameMasterUserProfile)); } return response; }
private bool IsUserInPlayersList(VerseEngineeringUser user, Poem poem) { return poem.Players.Any(player => player.UserProfileId == user.UserId); }
protected abstract VerseData OnPostVerseForPoem(Poem poem, AddVerseModel verseModel, VerseEngineeringUser user);
protected abstract IEnumerable<VerseData> OnGetVersesForPoem(Poem poem, VerseEngineeringUser user);
private void InsertInvitationToPoemEventsForEachPlayer(long authorId, IEnumerable<long> invitedPlayers, Poem poem) { foreach (var invitedPlayer in invitedPlayers) { eventService.GetInvitationToPoemEventBuilder() .WithSender(authorId) .WithNotifiedUser(invitedPlayer) .RelatedToPoem(poem) .Execute(); } }
public void Update(Poem poem) { poemRepository.Update(poem).Commit(); }
public IEnumerable<UserProfile> GetPlayersThatAcceptedGameInvitation(Poem poem) { return poem.PoemRequests.Where(request => !request.IsArchived) .Select(request => request.RequestedUserProfile); }
public IEnumerable<UserProfile> GetPendingGamePlayers(Poem poem) { return poem.PoemRequests.Where(request => request.IsArchived).Select( request => request.RequestedUserProfile); }
protected override IEnumerable<VerseData> OnGetVersesForPoem(Poem poem, VerseEngineeringUser user) { throw new System.NotImplementedException(); }
private void UpdateGameMaster(Poem poem, Verse verse) { if (poem.CurrentGm != verse.AuthorProfileId) { poem.CurrentGm = verse.AuthorProfileId; poemService.Update(poem); } }
protected override IEnumerable<VerseData> OnGetVersesForPoem(Poem poem, VerseEngineeringUser user) { return Mapper.Map<IEnumerable<VerseData>>( poem.Verses.Where(verse => verse.VerseTypeId == verseService.GetVerseType<ScratchVerseType>().Id)); }