public async Task <bool> DeleteComment(TUser account, int newsId, int id) { using (var transaction = session.BeginTransaction()) { var commentInThread = await session.LoadAsync <TCommentInThread>(id, x => x.Comment, x => x.Commentable); if (!await forumUserService.IsUser(account, commentInThread.Comment.Author)) { return(false); } await session.DeleteAsync(commentInThread.Comment); await session.DeleteAsync(commentInThread); transaction.Commit(); return(true); } }
public async Task <IActionResult> Delete(int id) { using (var transaction = session.BeginTransaction()) { var link = await session.LoadAsync <ExternalLink>(id); await session.DeleteAsync(link); transaction.Commit(); return(Ok()); } }
public async Task <ActionResult> Delete(int id) { using (var transaction = session.BeginTransaction()) { var forum = await session.LoadAsync <Data.Forums.Forum>(id); await session.DeleteAsync(forum); transaction.Commit(); } return(Ok()); }
public async Task <IActionResult> Put(int id, [FromBody] PollView <TUserView> pollView) { using (var transaction = session.BeginTransaction()) { // Update poll var poll = await session.LoadAsync <Poll <TUser> >(id); poll.Question = pollView.Question; var newAnswers = pollView.PossibleAnswers.Where(a => a.Text != null).ToList(); // Update or add modified possible answers foreach (var possibleAnswerDto in newAnswers) { var possibleAnswer = poll.PossibleAnswers.SingleOrDefault(p => p.Id == possibleAnswerDto.Id); if (possibleAnswer != null) { possibleAnswer.Text = possibleAnswerDto.Text.Trim(); if (possibleAnswer.Text.Length >= 1) { possibleAnswer.Text = possibleAnswerDto.Text; await session.UpdateAsync(possibleAnswer); } } else { await session.SaveAsync(new PollPossibleAnswer <TUser> { Text = possibleAnswerDto.Text, Poll = poll }); } } // Delete from db possible answers no longer in the Dto (removed by user) foreach (var answer in poll.PossibleAnswers.Where(p => newAnswers.All(u => u.Id != p.Id))) { await session.DeleteAsync(answer); } await session.UpdateAsync(poll); transaction.Commit(); } return(Ok()); }
public async Task <IActionResult> Delete(int id) { using (var transaction = session.BeginTransaction()) { var thread = await session.LoadAsync <Thread <TUser> >(id); var account = await accountService.GetCurrentUserAsync(); if (!await accountService.IsUser(account, thread.Author)) { return(Unauthorized()); } await session.DeleteAsync(thread); transaction.Commit(); } return(Ok()); }
public async Task DeleteAsync(Adjective adj) { await _session.DeleteAsync(adj); }
public async Task DeleteAsync(Noun noun) { await _session.DeleteAsync(noun); }