Beispiel #1
0
        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.GetShortId())
            {
                return(DomainResult.Failed <BacklogItemCommentReference>("Cannot delete comments of other users"));
            }

            ticket.Comments.Remove(comment);

            ticket.AddHistoryRecord(currentUser, "Deleted a comment");

            return(DomainResult.Success(ToLastCommentReference(ticket, true)));
        }
Beispiel #2
0
        public async Task <IDomainResult <BacklogItemCommentReference> > Update(string backlogItemId, string commentId, CommentAddUpdRequest dto)
        {
            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.GetShortId())
            {
                return(DomainResult.Failed <BacklogItemCommentReference>("Cannot edit comments of other users"));
            }

            var mentionedUsers = await _mentionedUserResolver.GetMentionedUsers(dto.Message);

            comment.Message          = dto.Message;
            comment.MentionedUserIds = mentionedUsers.Any() ? mentionedUsers : null;
            comment.LastModified     = DateTime.UtcNow;

            ticket.AddHistoryRecord(currentUser, "Updated a comment");

            return(DomainResult.Success(ToLastCommentReference(ticket)));
        }
        public void Errored_IDomainResult_Converts_To_IDomainResultOfT()
        {
            var domainResult    = DomainResult.Failed("Bla");
            var domainResultOfT = domainResult.To <int>();

            Assert.False(domainResultOfT.IsSuccess);
            Assert.Equal(0, domainResultOfT.Value);
            Assert.Equal("Bla", domainResultOfT.Errors.Single());
        }
        public void Errored_IDomainResultOfT_Converts_To_IDomainResultOfV()
        {
            var domainResult    = DomainResult.Failed <int>("Bla");
            var domainResultOfT = domainResult.To <char>();

            Assert.False(domainResultOfT.IsSuccess);
            Assert.Equal(default(char), domainResultOfT.Value);
            Assert.Equal("Bla", domainResultOfT.Errors.Single());
        }
Beispiel #5
0
        public async Task <DomainResult> AddToCategoryAsync(Guid categoryId, UgcBase ugc)
        {
            var category = await _categoryRepository.FirstOrDefaultAsync(categoryId);

            if (category == null)
            {
                return(DomainResult.Failed(new ArgumentNullException($"找不Id为{categoryId}的category")));
            }

            return(DomainResult.Success);
        }
Beispiel #6
0
        public async Task <IDomainResult <CustomFieldReferenceDto> > Create(CustomFieldAddRequest dto)
        {
            if (await DbSession.Query <CustomFieldIndexedForList, CustomFields_ForList>()
                .Where(cf => cf.Name == dto.Name)
                .AnyAsync())
            {
                return(DomainResult.Failed <CustomFieldReferenceDto>($"Custom Field with name '{dto.Name}' already exist"));
            }

            var entity = new CustomField
            {
                Name      = dto.Name,
                FieldType = dto.Type
            };
            await DbSession.StoreAsync(entity);

            return(DomainResult.Success(GetReference(entity)));
        }
Beispiel #7
0
        public async Task <IDomainResult <BacklogItemReference> > Create <T>(T dto) where T : BacklogItemAddUpdRequestBase
        {
            BacklogItem?ticket = dto switch
            {
                BugAddUpdRequest bug => await ConvertDtoToEntity <BacklogItemBug, BugAddUpdRequest>(bug),
                UserStoryAddUpdRequest story => await ConvertDtoToEntity <BacklogItemUserStory, UserStoryAddUpdRequest>(story),
                _ => null,
            };

            if (ticket == null)
            {
                return(DomainResult.Failed <BacklogItemReference>("Incorrect Backlog structure"));
            }

            await DbSession.StoreAsync(ticket);

            return(DomainResult.Success(
                       ticket.ToReference().RemoveEntityPrefixFromId()
                       ));
        }
        private async Task <IDomainResult> VerifyName(string?id, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(DomainResult.Failed($"Name is a mandatory field"));
            }
            var query = DbSession.Query <CustomFieldIndexedForList, CustomFields_ForList>()
                        .Where(cf => cf.Name == name);

            if (!string.IsNullOrEmpty(id))
            {
                query = query.Where(cf => cf.Id != GetFullId(id));
            }

            if (await query.AnyAsync())
            {
                return(DomainResult.Failed($"Custom Field with name '{name}' already exist"));
            }

            return(DomainResult.Success());
        }
        public async Task <IDomainResult <BacklogItem> > ConvertToEntity <TModel, TDto>(TDto dto, TModel?entity = null)
            where TModel : BacklogItem, new()
            where TDto : BacklogItemAddUpdRequestBase
        {
            entity ??= new TModel();

            entity.Title         = dto.Title;
            entity.State         = dto.State;
            entity.EstimatedSize = dto.EstimatedSize;
            entity.Assignee      = dto.AssigneeId != null ? await _userResolver.GetReferenceById(dto.AssigneeId) : null;

            if (dto.Tags?.Any(t => t.Length > 11) == true)
            {
                return(DomainResult <BacklogItem> .Failed("Each tag can't exceed 10 symbols"));
            }
            entity.Tags = dto.Tags?.Distinct().ToArray();

            entity.AddHistoryRecord(
                await _userResolver.GetCurrentUserReference(),
                entity.ModifiedBy.Any() ? "Modified" : "Created"                        // TODO: Provide more informative description in case of modifications
                );

            if (dto.ChangedCustomFields != null)
            {
                entity.CustomFields ??= new Dictionary <string, object>();
                await ResolveChangedCustomFields(entity.CustomFields, dto.ChangedCustomFields);
            }

            await ResolveChangedRelatedItems(entity.RelatedItems, dto.ChangedRelatedItems);

            if (dto is BugAddUpdRequest bugDto && entity is BacklogItemBug bugEntity)
            {
                bugEntity.Severity           = bugDto.Severity;
                bugEntity.Priority           = bugDto.Priority;
                bugEntity.StepsToReproduce   = bugDto.StepsToReproduce;
                bugEntity.AcceptanceCriteria = bugDto.AcceptanceCriteria;
            }
Beispiel #10
0
        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()
                       ));
        }
 public IDomainResult GetFailedWithMessage() => DomainResult.Failed("Ah, error");
 public IDomainResult GetErrorWithValidationMessages() =>
 DomainResult.Failed(new[]
 {
     new ValidationResult("Validation message1", new[] { "fieldName1" }),
     new ValidationResult("Validation message2", new[] { "fieldName2" })
 });
 public IDomainResult <int> GetFailedWithNoMessageWhenExpectedNumber() => DomainResult.Failed <int>();
 public IDomainResult <int> GetFailedWithMessageWhenExpectedNumber() => DomainResult.Failed <int>("Ah, error");
 public IDomainResult <int> GetFailedWithMessagesWhenExpectedNumber() => DomainResult.Failed <int>(new[] { "Ah, error", "Terrible error" });
 public IDomainResult <int> GetErrorWithValidationMessagesWhenExpectedNumber() =>
 DomainResult.Failed <int>(new[]
 {
     new ValidationResult("Validation message1", new[] { "fieldName1" }),
     new ValidationResult("Validation message2", new[] { "fieldName2" })
 });
 public IDomainResult GetFailedWithMessages() => DomainResult.Failed(new[] { "Ah, error", "Terrible error" });
 public IDomainResult GetFailedWithNoMessage() => DomainResult.Failed();