Exemple #1
0
        public static TicketAttachmentIndexViewModel CreateNewViewModel(string currentUserId, Domain.TicketAttachment ticketAttachment, ApplicationDbContext dbContext)
        {
            if (ticketAttachment == null)
            {
                throw new ArgumentNullException(nameof(ticketAttachment));
            }

            TicketIndexViewModel ticket = TicketIndexViewModel.CreateNewViewModel(currentUserId, ticketAttachment.Ticket) ?? throw new ArgumentException();
            HelperUserViewModel  user   = HelperUserViewModel.CreateNewViewModel(ticketAttachment.User, dbContext) ?? throw new ArgumentException();

            return(new TicketAttachmentIndexViewModel()
            {
                Id = ticketAttachment.Id,
                Description = ticketAttachment.Description,
                FilePath = ticketAttachment.FilePath,
                FileUrl = ticketAttachment.FileUrl,
                DateCreated = ticketAttachment.DateCreated,
                FileName = Path.GetFileName(ticketAttachment.FilePath),
                User = user,
                UserId = user.Id,

                Ticket = ticket,
                TicketId = ticket.Id,
            });
        }
        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}");
            }
        }
Exemple #3
0
        //public override string ToString() => $"(Changed) {Property}: Old - {OldValue}, New - {NewValue}, ChangeMadeBy - {UserWhoMadeTheChange.Email}";

        public static TicketHistoryIndexViewModel CreateNewViewModel(ApplicationDbContext dbContext, Domain.TicketHistory ticketHistory)
        {
            if (ticketHistory == null)
            {
                throw new ArgumentNullException(nameof(ticketHistory));
            }

            return(new TicketHistoryIndexViewModel()
            {
                Id = ticketHistory.Id,
                DateChanged = ticketHistory.DateChanged,
                Property = ticketHistory.Property,
                NewValue = ticketHistory.NewValue,
                OldValue = ticketHistory.OldValue,
                UserWhoMadeTheChange = HelperUserViewModel.CreateNewViewModel(ticketHistory.User, dbContext),
            });
        }
        public static ProjectDetailsViewModel CreateNewViewModel(string currentUserId, Domain.Project project, ApplicationDbContext dbContext)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            try
            {
                return(new ProjectDetailsViewModel()
                {
                    Id = project.Id == null ? throw new ArgumentNullException() : project.Id,
                    Name = string.IsNullOrWhiteSpace(project.Name) ? throw new ArgumentNullException() : project.Name,
                    Users = project.Users?.Select(user => HelperUserViewModel.CreateNewViewModel(user, dbContext)).ToList() ?? throw new ArgumentNullException(),
                    TicketCount = project.Tickets?.Count ?? 0,
                    Tickets = project.Tickets?.Select(ticket => TicketIndexViewModel.CreateNewViewModel(currentUserId, ticket)).ToList() ?? new List <TicketIndexViewModel>(),
                    DateCreated = project.DateCreated == null ? throw new ArgumentNullException() : project.DateCreated,
                    DateUpdated = project.DateUpdated,
                    CurrentUserId = currentUserId,
                });
            }
        // GET: UserRole
        public ActionResult Index(string error)
        {
            List <HelperUserViewModel> model = UserRepository
                                               .GetAllUsers()
                                               .Where(user => !user.Email.ToLower().Contains("demo-"))
                                               .ToList()
                                               .Select(user => HelperUserViewModel.CreateNewViewModel(user, DbContext))
                                               .ToList();

            if (model == null)
            {
                return(RedirectToAction(nameof(Index), "Home"));
            }

            if (!string.IsNullOrWhiteSpace(error))
            {
                ModelState.AddModelError("", error);
            }

            return(View(model));
        }