public static TicketAttachmentDeleteViewModel CreateNewViewModel(Domain.TicketAttachment ticketAttachment) { if (ticketAttachment == null) { throw new ArgumentNullException(nameof(ticketAttachment)); } return(new TicketAttachmentDeleteViewModel() { Id = ticketAttachment.Id, FileName = Path.GetFileName(ticketAttachment.FilePath), Description = ticketAttachment.Description, TicketId = ticketAttachment?.Ticket.Id ?? throw new ArgumentException("TicketAttachment wasn't attached to ticket"), TicketName = ticketAttachment?.Ticket.Title ?? throw new ArgumentException("TicketAttachment wasn't attached to ticket"), });
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, }); }