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))); }
/// <inheritdoc/> public async Task <IDomainResult <BacklogItemGetResponseBase> > GetById(string id, BacklogItemCommentListGetRequest? @params = null) { @params ??= new BacklogItemCommentListGetRequest(); var fullId = GetFullId(id); var ticket = await DbSession.LoadAsync <BacklogItem>(fullId); if (ticket == null) { return(DomainResult.NotFound <BacklogItemGetResponseBase>()); } var comments = GetCommentsList(ticket, @params); var pagedComments = (comments?.Any() == true) ? new ListResponse <BacklogItemCommentListGetResponse>(comments, ticket.Comments.Count, @params.PageIndex, @params.PageSize) : null; var dto = (ticket.Type) switch { BacklogItemType.Bug => (ticket as BacklogItemBug)?.ConvertToDto <BacklogItemBug, BugGetResponse>(pagedComments) as BacklogItemGetResponseBase, BacklogItemType.UserStory => (ticket as BacklogItemUserStory)?.ConvertToDto <BacklogItemUserStory, UserStoryGetResponse>(pagedComments) as BacklogItemGetResponseBase, _ => throw new NotImplementedException($"Not supported Backlog Item Type: {ticket.Type}"), }; if (dto == null) { throw new NotSupportedException($"Failed to return Backlog Item type of {ticket.Type}"); } return(DomainResult.Success(dto)); }
public async Task <IDomainResult> AssignToUser(string backlogItemId, string?userShortenId) { var fullId = GetFullId(backlogItemId); if (!await DbSession.Advanced.ExistsAsync(fullId)) { return(IDomainResult.NotFound("The Backlog Item not found")); } UserReference?userRef = null; if (userShortenId != null) { userRef = await _userResolver.GetReferenceById(userShortenId); if (userRef == null) { return(DomainResult.NotFound("The user not found")); } userRef = userRef.RemoveEntityPrefixFromId(); } DbSession.Advanced.Patch <BacklogItem, UserReference?>(fullId, x => x.Assignee, userRef); await AddHistoryRecordPatch(backlogItemId, userRef == null? "Removed assigned user" : $"Assigned user '{userRef.MentionedName}'"); return(IDomainResult.Success()); }
public async Task <IDomainResult <BacklogItemReference> > Update <T>(string id, T dto) where T : BacklogItemAddUpdRequestBase { var entity = await DbSession.LoadAsync <BacklogItem>(GetFullId(id)); if (entity == null) { return(DomainResult.NotFound <BacklogItemReference>()); } var(_, status) = dto switch { BugAddUpdRequest bug => await _dtoToEntityConversion.ConvertToEntity(bug, entity as BacklogItemBug), UserStoryAddUpdRequest story => await _dtoToEntityConversion.ConvertToEntity(story, entity as BacklogItemUserStory), TaskAddUpdRequest task => await _dtoToEntityConversion.ConvertToEntity(task, entity as BacklogItemTask), FeatureAddUpdRequest feature => await _dtoToEntityConversion.ConvertToEntity(feature, entity as BacklogItemFeature), _ => throw new ArgumentException($"Unsupported type ${typeof(T)}", nameof(dto)) }; if (!status.IsSuccess) { return(status.To <BacklogItemReference>()); } var ticketRef = entity.ToReference().RemoveEntityPrefixFromId(); await UpdateRelatedItems(dto, ticketRef); return(DomainResult.Success(ticketRef)); }
public async Task <IDomainResult <BacklogItemReference> > Delete(string shortId) { var ticket = await DbSession.LoadAsync <BacklogItem>(GetFullId(shortId)); if (ticket == null) { return(DomainResult.NotFound <BacklogItemReference>()); } DbSession.Delete(ticket); // Remove references to the ticket from 'Related Items' of other tickets if (ticket.RelatedItems.Any()) { foreach (var item in ticket.RelatedItems) { DbSession.Advanced.Patch <BacklogItem, BacklogItemRelatedItem>(GetFullId(item.RelatedTo.Id !), x => x.RelatedItems, items => items.RemoveAll(i => i.RelatedTo.Id == shortId)); } } return(DomainResult.Success( ticket.ToReference().RemoveEntityPrefixFromId() )); }
public async Task <IDomainResult <BacklogItemReference> > AssignToUser(string backlogItemId, string?userShortenId) { var backlogItem = await DbSession.LoadAsync <BacklogItem>(GetFullId(backlogItemId)); if (backlogItem == null) { return(DomainResult.NotFound <BacklogItemReference>("The Backlog Item not found")); } if (userShortenId == null) { backlogItem.Assignee = null; } else { var userRef = await _userResolver.GetReferenceById(userShortenId); if (userRef == null) { return(DomainResult.NotFound <BacklogItemReference>("The user not found")); } backlogItem.Assignee = userRef; } backlogItem.AddHistoryRecord(await _userResolver.GetCurrentUserReference(), "Assigned a user"); return(DomainResult.Success( backlogItem.ToReference().RemoveEntityPrefixFromId() )); }
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))); }
private async Task <IDomainResult <BacklogItem> > GetEntity(string id) { var fullId = GetFullId(id); var ticket = await DbSession.LoadAsync <BacklogItem>(fullId); return(ticket == null ? DomainResult.NotFound <BacklogItem>("Backlog item not found") : DomainResult.Success(ticket)); }
public async Task <IDomainResult <UserGetByIdResponse> > GetById(string id) { var fullId = GetFullId(id); var user = await DbSession.LoadAsync <User>(fullId); if (user == null) { return(DomainResult.NotFound <UserGetByIdResponse>()); } return(DomainResult.Success(user.ConvertToUserDto())); }
public async Task <IDomainResult <CustomFieldReferenceDto> > Rename(string id, CustomFieldRenameRequest dto) { var entity = await DbSession.LoadAsync <CustomField>(GetFullId(id)); if (entity == null) { return(DomainResult.NotFound <CustomFieldReferenceDto>()); } entity.Name = dto.Name; return(DomainResult.Success(GetReference(entity))); }
public async Task <IDomainResult <CustomFieldReferenceDto> > Delete(string id) { // TODO: Prohibit deletion if there are any references var cf = await DbSession.LoadAsync <CustomField>(GetFullId(id)); if (cf == null) { return(DomainResult.NotFound <CustomFieldReferenceDto>()); } DbSession.Delete(cf); return(DomainResult.Success(GetReference(cf))); }
public async Task <IDomainResult <BacklogItemReference> > Delete(string id) { var ticket = await DbSession.LoadAsync <BacklogItem>(GetFullId(id)); if (ticket == null) { return(DomainResult.NotFound <BacklogItemReference>()); } DbSession.Delete(ticket); return(DomainResult.Success( ticket.ToReference().RemoveEntityPrefixFromId() )); }
public async Task <IDomainResult <CustomFieldReferenceDto> > Delete(string id) { var cf = await DbSession.LoadAsync <CustomField>(GetFullId(id)); if (cf == null) { return(DomainResult.NotFound <CustomFieldReferenceDto>()); } DbSession.Delete(cf); // Delete the ID in all references foreach (var clearFieldRef in _clearFieldReferences) { clearFieldRef.ClearCustomFieldId(id); } return(DomainResult.Success(GetReference(cf))); }
public async Task <IDomainResult <UserReference> > Update(string id, UserAddUpdRequest dto) { var fullId = GetFullId(id); var user = await DbSession.LoadAsync <User>(fullId); if (user == null) { return(DomainResult.NotFound <UserReference>()); } var newRef = dto.ConvertToUser(user).ToReference().RemoveEntityPrefixFromId(); // Update the name in all references to this user foreach (var updateUserRef in _updateUserReferences) { updateUserRef.UpdateReferences(newRef); } return(DomainResult.Success(newRef)); }
public async Task <IDomainResult <CustomFieldReferenceDto> > Update(string id, CustomFieldUpdateRequest dto) { var verificationResult = await VerifyName(id, dto.Name); if (!verificationResult.IsSuccess) { return(verificationResult.To <CustomFieldReferenceDto>()); } var entity = await DbSession.LoadAsync <CustomField>(GetFullId(id)); if (entity == null) { return(DomainResult.NotFound <CustomFieldReferenceDto>()); } entity.Name = dto.Name; entity.IsMandatory = dto.IsMandatory.HasValue && dto.IsMandatory.Value; entity.BacklogItemTypes = dto.BacklogItemTypes; return(DomainResult.Success(GetReference(entity))); }
public async Task <IDomainResult <CustomFieldItemResponse> > GetById(string id) { var fullId = GetFullId(id); var entity = await DbSession.LoadAsync <CustomField>(fullId); if (entity == null) { return(DomainResult.NotFound <CustomFieldItemResponse>()); } var item = new CustomFieldItemResponse { Name = entity.Name, FieldType = entity.FieldType, IsMandatory = entity.IsMandatory, BacklogItemTypes = entity.BacklogItemTypes, UsedInBacklogItemsCount = await _backlogService.GetCountOfBacklogItemsUsingCustomField(id) }; return(DomainResult.Success(item)); }
public async Task <IDomainResult <UserReference> > Delete(string id) { var fullId = GetFullId(id); var user = await DbSession.LoadAsync <User>(fullId); if (user == null) { return(DomainResult.NotFound <UserReference>()); } DbSession.Delete(fullId); // Delete the ID in all references to this user foreach (var updateUserRef in _updateUserReferences) { updateUserRef.ClearUserId(id); } var response = user.ToReference().RemoveEntityPrefixFromId(); return(DomainResult.Success(response)); }
public async Task <IDomainResult <BacklogItemReference> > Update <T>(string id, T dto) where T : BacklogItemAddUpdRequestBase { var entity = await DbSession.LoadAsync <BacklogItem>(GetFullId(id)); if (entity == null) { return(DomainResult.NotFound <BacklogItemReference>()); } entity = dto switch { BugAddUpdRequest bug => await ConvertDtoToEntity(bug, entity as BacklogItemBug), UserStoryAddUpdRequest story => await ConvertDtoToEntity(story, entity as BacklogItemUserStory), _ => null }; if (entity == null) { return(DomainResult.Failed <BacklogItemReference>("Incorrect Backlog structure")); } return(DomainResult.Success( entity.ToReference().RemoveEntityPrefixFromId() )); }
/// <inheritdoc/> public async Task <IDomainResult <BacklogItemGetResponseBase> > GetById(string id) { var fullId = GetFullId(id); var ticket = await DbSession.LoadAsync <BacklogItem>(fullId); if (ticket == null) { return(DomainResult.NotFound <BacklogItemGetResponseBase>()); } List <BacklogItemCustomFieldValue>?customFieldValues = null; if (ticket.CustomFields?.Any() == true) { customFieldValues = (await _customFieldsService.GetArray(new CustomFieldListGetRequest { Ids = ticket.CustomFields.Keys })).ConvertFieldToDto(ticket.CustomFields); } var dto = ticket.Type switch { BacklogItemType.Bug => (ticket as BacklogItemBug)?.ConvertToDto <BacklogItemBug, BugGetResponse> (customFieldValues) as BacklogItemGetResponseBase, BacklogItemType.UserStory => (ticket as BacklogItemUserStory)?.ConvertToDto <BacklogItemUserStory, UserStoryGetResponse> (customFieldValues) as BacklogItemGetResponseBase, BacklogItemType.Task => (ticket as BacklogItemTask)?.ConvertToDto <BacklogItemTask, TaskGetResponse> (customFieldValues) as BacklogItemGetResponseBase, BacklogItemType.Feature => (ticket as BacklogItemFeature)?.ConvertToDto <BacklogItemFeature, FeatureGetResponse> (customFieldValues) as BacklogItemGetResponseBase, _ => throw new NotImplementedException($"Not supported Backlog Item Type: {ticket.Type}"), }; if (dto == null) { throw new NotSupportedException($"Failed to return Backlog Item type of {ticket.Type}"); } return(DomainResult.Success(dto)); }
public IDomainResult GetNotFoundWithMessages() => DomainResult.NotFound(new[] { "No, really not found", "Searched everywhere" });
public IDomainResult GetNotFoundWithMessage() => DomainResult.NotFound("No, really not found");
public IDomainResult GetNotFoundWithNoMessage() => DomainResult.NotFound();
public IDomainResult <int> GetNotFoundWithMessagesWhenExpectedNumber() => DomainResult.NotFound <int>(new[] { "No, really not found", "Searched everywhere" });
public IDomainResult <int> GetNotFoundWithMessageWhenExpectedNumber() => DomainResult.NotFound <int>("No, really not found");
public IDomainResult <int> GetNotFoundWithNoMessageWhenExpectedNumber() => DomainResult.NotFound <int>();