public async Task <IDomainResult <BacklogItemCommentReference> > Delete(string backlogItemId, string commentId) { var ticketRes = await GetEntity(backlogItemId); if (!ticketRes.IsSuccess) { return(ticketRes.To <BacklogItemCommentReference>()); } var ticket = ticketRes.Value; var comment = ticket.Comments.SingleOrDefault(c => c.Id == commentId); if (comment == null) { return(DomainResult.NotFound <BacklogItemCommentReference>("Comment not found")); } var currentUser = await _userResolver.GetCurrentUserReference(); if (comment.Author.Id != currentUser.Id) { return(DomainResult.Unauthorized <BacklogItemCommentReference>("Cannot delete comments of other users")); } ticket.Comments.Remove(comment); ticket.AddHistoryRecord(currentUser, "Deleted a comment"); return(DomainResult.Success(GetCommentReference(ticket.Id, null, comment.Message))); }
public async Task <IDomainResult <BacklogItemCommentReference> > Update(string backlogItemId, string commentId, string message) { var ticketRes = await GetEntity(backlogItemId); if (!ticketRes.IsSuccess) { return(ticketRes.To <BacklogItemCommentReference>()); } var ticket = ticketRes.Value; var comment = ticket.Comments.SingleOrDefault(c => c.Id == commentId); if (comment == null) { return(DomainResult.NotFound <BacklogItemCommentReference>("Comment not found")); } var currentUser = await _userResolver.GetCurrentUserReference(); if (comment.Author.Id != currentUser.Id) { return(DomainResult.Unauthorized <BacklogItemCommentReference>("Cannot edit comments of other users")); } var mentionedUsers = await _mentionedUserResolver.GetMentionedUsers(message); comment.Message = message; comment.MentionedUserIds = mentionedUsers.Any() ? mentionedUsers : null; comment.LastModified = DateTime.UtcNow; ticket.AddHistoryRecord(currentUser, "Updated a comment"); return(DomainResult.Success(GetCommentReference(ticket.Id, commentId, message))); }
public IDomainResult GetUnauthorizedWithMessage() => DomainResult.Unauthorized("No, no access");
public IDomainResult GetUnauthorizedWithNoMessage() => DomainResult.Unauthorized();
public IDomainResult <int> GetUnauthorizedWithMessageWhenExpectedNumber() => DomainResult.Unauthorized <int>("No, no access");
public IDomainResult <int> GetUnauthorizedWithNoMessageWhenExpectedNumber() => DomainResult.Unauthorized <int>();