Example #1
0
        public static TicketEditViewModel CreateNewViewModel(Domain.Ticket ticket, List <SelectListItem> developersToChooseFrom, List <SelectListItem> projectsToChooseFrom)
        {
            if (ticket == null || developersToChooseFrom == null || projectsToChooseFrom == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                return(new TicketEditViewModel()
                {
                    Id = ticket.Id,
                    Title = ticket.Title,
                    Description = ticket.Description,
                    Priority = (TicketPrioritiesEnum)ticket.PriorityId,
                    Status = (TicketStatusesEnum)ticket.StatusId,
                    Type = (TicketTypesEnum)ticket.TypeId,
                    ProjectId = ticket.ProjectId,
                    Projects = projectsToChooseFrom,
                    DeveloperUsers = developersToChooseFrom,
                    DeveloperId = ticket.AssignedUserId,
                });
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }
        }
        public static TicketAttachmentCreateViewModel CreateNewViewModel(Domain.Ticket ticket)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException(nameof(ticket));
            }

            return(new TicketAttachmentCreateViewModel()
            {
                TicketId = ticket.Id,
                TicketTitle = ticket.Title,
            });
        }
        public static TicketCommentCreateViewModel CreateNewViewModel(Domain.Ticket ticket, string userId)
        {
            if (ticket == null || string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException();
            }

            return(new TicketCommentCreateViewModel()
            {
                TicketId = ticket?.Id ?? throw new ArgumentException(),
                TicketTitle = ticket?.Title ?? throw new ArgumentException(),
                UserId = userId
            });
Example #4
0
        public static TicketIndexViewModel CreateNewViewModel(string currentUserId, Domain.Ticket ticket, [Optional] bool?isWatching)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException();
            }

            bool isCurrentUserTheAuthorOrIsAssigned = ticket.AuthorId == currentUserId;

            if (!isCurrentUserTheAuthorOrIsAssigned)
            {
                isCurrentUserTheAuthorOrIsAssigned = ticket?.AssignedUserId != null ? ticket.AssignedUserId == currentUserId : false;
            }

            try
            {
                return(new TicketIndexViewModel()
                {
                    Id = ticket.Id,
                    Title = ticket.Title,
                    Priority = ticket.Priority.PriorityString,
                    Type = ticket.Type.TypeString,
                    Status = ticket.Status.StatusString,
                    AttachmentCount = ticket.Attachments.Count,
                    CommentCount = ticket.Comments.Count,
                    DateCreated = ticket.DateCreated,
                    DateUpdated = ticket.DateUpdated,
                    AssignedUserId = ticket?.AssignedUserId,
                    AssignedUserName = ticket?.AssignedUser?.UserName,
                    AuthorId = ticket.AuthorId,
                    AuthorName = ticket.Author.UserName,
                    ProjectId = ticket.ProjectId,
                    ProjectName = ticket.Project.Name,
                    IsCurrentUserTheAuthorOrIsAssigned = isCurrentUserTheAuthorOrIsAssigned,
                    IsWatching = isWatching ?? false,
                });
            }
            catch (Exception e)
            {
                throw new Exception($"Something went wrong\n {e.Message}");
            }
        }
        public static TicketDetailsViewModel CreateNewViewModel(string currentUserId, Domain.Ticket ticket, ApplicationDbContext dbContext)
        {
            if (ticket == null || dbContext == null || !new UserRepository(dbContext).DoesUserExist(currentUserId))
            {
                throw new ArgumentNullException();
            }

            try
            {
                return(new TicketDetailsViewModel()
                {
                    Id = ticket.Id,
                    Title = ticket.Title,
                    Description = ticket.Description,
                    Priority = ticket.Priority.PriorityString,
                    Status = ticket.Status.StatusString,
                    Type = ticket.Type.TypeString,

                    Comments = ticket.Comments?
                               .OrderByDescending(comment => comment.DateCreated)
                               .Select(ticketComment => TicketCommentIndexViewModel.CreateNewViewModel(ticketComment))
                               .ToList() ?? new List <TicketCommentIndexViewModel>(),

                    Attachments = ticket.Attachments?
                                  .OrderByDescending(attachment => attachment.DateCreated)
                                  .Select(ticketAttachment => TicketAttachment.TicketAttachmentIndexViewModel.CreateNewViewModel(currentUserId, ticketAttachment, dbContext))
                                  .ToList() ?? new List <TicketAttachment.TicketAttachmentIndexViewModel>(),

                    TicketHistories = ticket.TicketHistories?
                                      .OrderByDescending(ticketHistory => ticketHistory.DateChanged)
                                      .Select(ticketHistory => TicketHistory.TicketHistoryIndexViewModel.CreateNewViewModel(dbContext, ticketHistory))
                                      .ToList() ?? new List <TicketHistory.TicketHistoryIndexViewModel>(),

                    DateCreated = ticket.DateCreated,
                    DateUpdated = ticket.DateUpdated,
                    Author = HelperUserViewModel.CreateNewViewModel(ticket.Author, dbContext),
                    AssignedUser = ticket.AssignedUser == null ? null : HelperUserViewModel.CreateNewViewModel(ticket.AssignedUser, dbContext),
                    Project = ticket.Project,
                    ProjectId = ticket.ProjectId,

                    IsWatching = new TicketNotificationRepository(dbContext).IsUserSubscribedToTicket(currentUserId, ticket.Id),
                });
            }
            catch (Exception e)
            {
                throw new Exception($"Something went wrong\n {e.Message}");
            }
        }