示例#1
0
        public CloseTicketResponse Close(CloseTicketRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            using (var trans = transactionFactory.GetTransaction())
            {
                var ticket = repo.Get(request.Identity);
                if (ReferenceEquals(ticket, null))
                {
                    return new CloseTicketResponse {
                               TicketNotFound = true
                    }
                }
                ;

                if (ticket.Closed)
                {
                    return new CloseTicketResponse {
                               TicketAlreadyClosed = true
                    }
                }
                ;

                ticket.Closed = true;
                repo.Update(ticket);
                trans.Commit();
            }

            return(new CloseTicketResponse());
        }
        List <TheoreticalRelationship> GetAddedRelationships(IIdentity <Ticket> editedTicketIdentity, IEnumerable <AddRelationshipRequest> added)
        {
            if (added == null || !added.Any())
            {
                return(new List <TheoreticalRelationship>());
            }

            return(added
                   .Where(x => !ReferenceEquals(x.RelationshipId, null))
                   .Select(add => new {
                relatedTicket = ticketProvider.GetTicketByReference(add.RelatedTicketReference),
                relatedIsPrimary = add.ParticipationType == RelationshipParticipant.Secondary,
                relationshipType = data.Get(add.RelationshipId)
            })
                   .Where(x => x.relatedTicket != null)
                   .Select(x => {
                logger.Debug($"{nameof(GetAddedRelationships)} found added relationship {x.relationshipType}");

                return new TheoreticalRelationship {
                    Relationship = x.relationshipType,
                    PrimaryTicket = x.relatedIsPrimary? x.relatedTicket.GetIdentity() : editedTicketIdentity,
                    SecondaryTicket = x.relatedIsPrimary ? editedTicketIdentity : x.relatedTicket.GetIdentity(),
                    Type = TheoreticalRelationshipType.Added,
                };
            })
                   .ToList());
        }
示例#3
0
        public CreateCommentResponse Create(CreateCommentRequest request)
        {
            var validator        = validatorFactory.GetValidator();
            var validationResult = validator.Validate(request);

            if (!validationResult.IsSuccess)
            {
                return(responseCreator(validationResult, null));
            }

            Comment comment;

            using (var tran = transactionCreator.GetTransaction())
            {
                var ticket = ticketRepo.Get(request.TicketId);
                comment = commentFactory.Create(request.Body);
                ticket.Comments.Add(comment);

                ticketRepo.Update(ticket);
                commentRepo.Add(comment);

                tran.Commit();
            }

            return(responseCreator(validationResult, comment));
        }
示例#4
0
        public EditTicketResponse Edit(EditTicketRequest request)
        {
            logger.Debug("About to validate an edit-ticket request");
            var validationResult = ValidateRequest(request);

            logger.Debug(validationResult);

            if (!validationResult.IsSuccess)
            {
                return(responseCreator.GetResponse(validationResult, null));
            }

            using (var trans = transactionFactory.GetTransaction())
            {
                if (logger.IsDebugEnabled)
                {
                    logger.Debug($"Transaction used is a {trans.GetType().FullName}");
                }

                var ticket = ticketRepo.Get(request.Identity);

                editor.Edit(ticket, request);
                ticketRepo.Update(ticket);
                trans.Commit();

                return(responseCreator.GetResponse(validationResult, ticket));
            }
        }
示例#5
0
 public TEntity Resolve(object source,
                        object destination,
                        IIdentity <TEntity> sourceMember,
                        TEntity destMember,
                        ResolutionContext context)
 {
     return((sourceMember != null) ? repo.Get(sourceMember) : null);
 }
示例#6
0
        public Comment Read(IIdentity <Comment> id)
        {
            if (ReferenceEquals(id, null))
            {
                return(null);
            }

            return(commentRepo.Get(id));
        }
示例#7
0
        public LoginStateModel GetLoginState()
        {
            var userInfo = userReader.GetCurrentUserInfo();
            var user     = (userInfo?.Identity != null) ? data.Get(userInfo.Identity) : null;

            return(new LoginStateModel {
                UserInfo = userInfo,
                IsSiteAdmin = user?.SiteAdministrator == true,
            });
        }
        public TEntity Resolve(object source,
                               object destination,
                               long sourceMember,
                               TEntity destMember,
                               ResolutionContext context)
        {
            var identity = Identity.Create <TEntity>(sourceMember);

            if (ReferenceEquals(identity, null))
            {
                return(null);
            }

            return(repo.Get(identity));
        }
示例#9
0
        public AppCapability GetCapabilities(IIdentity <User> userIdentity, IIdentity <AgiilApp> targetEntity)
        {
            if (userIdentity == null)
            {
                throw new ArgumentNullException(nameof(userIdentity));
            }

            var user = data.Get(userIdentity);

            if (user.SiteAdministrator)
            {
                return(AppCapability.CreateProject);
            }

            return(default);
示例#10
0
        public EditProjectResponse EditProject(EditProjectRequest request)
        {
            var project = data.Get(request.Identity);

            if (project == null)
            {
                throw new ArgumentException($"The project {request.Identity} does not exist.", nameof(request));
            }

            mapper.Map(request, project);

            var response = responseFactory();

            response.Project = project;
            return(response);
        }
示例#11
0
        protected override RuleOutcome GetValueOutcome(IIdentity <TEntity> value)
        {
            if (ReferenceEquals(value, null))
            {
                return(Success);
            }

            var entity = repository.Get(value);

            if (ReferenceEquals(entity, null))
            {
                return(Failure);
            }

            return(Success);
        }
示例#12
0
        public Project GetCurrentProject()
        {
            if (session.TryGet(SessionKey.CurrentProjectIdentity, out IIdentity <Project> id))
            {
                return(data.Get(id));
            }

            var project = wrapped.GetCurrentProject();

            if (project != null)
            {
                session.Set(SessionKey.CurrentProjectIdentity, project.GetIdentity());
            }

            return(project);
        }
示例#13
0
        public DeleteCommentResponse Delete(DeleteCommentRequest request)
        {
            var validator        = validatorFactory.GetValidator();
            var validationResult = validator.Validate(request);

            if (!validationResult.IsSuccess)
            {
                return(responseCreator(validationResult));
            }

            using (var tran = transactionCreator.GetTransaction())
            {
                var comment = data.Get(request.CommentId);
                comment.Ticket.Comments.Remove(comment);
                tran.Commit();
            }

            return(responseCreator(validationResult));
        }
示例#14
0
        public EditCommentResponse Edit(EditCommentRequest request)
        {
            var validator        = validatorFactory.GetValidator();
            var validationResult = validator.Validate(request);

            if (!validationResult.IsSuccess)
            {
                return(responseCreator(validationResult));
            }

            using (var tran = transactionCreator.GetTransaction())
            {
                var comment = commentRepo.Get(request.CommentIdentity);
                comment.Body = request.Body;
                comment.LastEditTimestamp = environment.GetCurrentUtcTimestamp();
                commentRepo.Update(comment);
                tran.Commit();
            }

            return(responseCreator(validationResult));
        }
示例#15
0
        public EditSprintResponse Edit(EditSprintRequest request)
        {
            var validationResult = ValidateRequest(request);

            if (!validationResult.IsSuccess)
            {
                return(responseCreator(validationResult, null));
            }

            Sprint sprint;

            using (var trans = transactionFactory.GetTransaction())
            {
                sprint = sprintRepo.Get(request.SprintIdentity);
                mapper.Map(request, sprint);
                sprintRepo.Update(sprint);
                trans.Commit();
            }

            return(responseCreator(validationResult, sprint));
        }
示例#16
0
 public TicketReference GetTicketReference(IIdentity <Ticket> ticketId) => data.Get(ticketId)?.GetTicketReference();
示例#17
0
 protected User GetUser(ICurrentUserInfo userInfo)
 {
     return(query.Get(userInfo.Identity));
 }