public void createTicketAttachment(TicketAttachmentViewModel ticketAttachmentViewModel) { Ticket ticket = TicketRepo.GetEntity(x => x.Id == ticketAttachmentViewModel.TicketId); string userId = HttpContext.Current.User.Identity.GetUserId(); string userName = db.Users.Find(userId).UserName; string projectName = ticket.Project.Name; string ticketTitle = ticket.Title; var stream = ticketAttachmentViewModel.FileData.InputStream; var fileName = ticketAttachmentViewModel.FileData.FileName; string baseDir = AppDomain.CurrentDomain.BaseDirectory; string source = baseDir + "Content\\Attachements\\" + userName + "\\" + projectName + "\\" + ticketTitle + "\\" + fileName; string fileURL = "/Content/Attachements/" + userName + "/" + projectName + "/" + ticketTitle + "/" + fileName; FileInfo fi = new FileInfo(source); var di = fi.Directory; if (!di.Exists) { di.Create(); } TicketAttachment ticketAttachment = new TicketAttachment(); ticketAttachment.FilePath = source; ticketAttachment.Description = ticketAttachmentViewModel.Description; ticketAttachment.TicketId = ticketAttachmentViewModel.TicketId; ticketAttachment.UserId = userId; ticketAttachment.Created = DateTime.Now; ticketAttachment.FileURL = fileURL; TicketAttachmentRepo.Add(ticketAttachment); using (stream) { using (FileStream fsWrite = new FileStream(source, FileMode.OpenOrCreate, FileAccess.Write)) { byte[] buffer = new byte[1024 * 1024 * 5]; while (true) { int r = stream.Read(buffer, 0, buffer.Length); if (r == 0) { break; } fsWrite.Write(buffer, 0, r); } } } if (ticket.AssignedToUserId != null) { TicketNotification notification = new TicketNotification(ticket.AssignedToUserId, ticket.Id, true); TicketNotificationRepo.Add(notification); } }
//CREATE TICKET public void createTicket(CreateTicketViewModel model, string userId) { TicketType ticketType = new TicketType(model.TicketTypeName); TicketPriority ticketPriority = new TicketPriority(model.Priority); TicketTypeRepo.Add(ticketType); TicketPriorityRepo.Add(ticketPriority); Ticket ticket = new Ticket(model.Title, model.Description, DateTime.Now, model.ProjectId, ticketType.Id, ticketPriority.Id, userId); TicketRepo.Add(ticket); var copyTicket = TicketRepo.GetEntity(x => x.Id == ticket.Id); TicketHistory history = new TicketHistory(copyTicket.Id, "property", model.Description, model.Description, true, userId); TicketHistoryRepo.Add(history); }
//CREATE TICKET public void createTicketComment(TicketComment model, string userId) { var ticket = TicketRepo.GetEntity(x => x.Id == model.TicketId); var ticketComment = TicketCommentRepo.GetEntity(x => x.Comment == model.Comment && x.TicketId == ticket.Id); if (ticketComment == null) { TicketComment newticketComment = new TicketComment(model.Comment, model.Created, userId, model.TicketId); TicketCommentRepo.Add(newticketComment); } if (ticket.AssignedToUserId != null) { TicketNotification notification = new TicketNotification(ticket.AssignedToUserId, ticket.Id, true); TicketNotificationRepo.Add(notification); } }