public ActionResult UpdateTicketAttachment(TicketAttachmentViewModel model) { if (ModelState.IsValid) { ticketAttachmentLogic.updateTicketAttachment(model); return(RedirectToAction("Index", new { ticketId = model.TicketId })); } return(RedirectToAction("Error")); }
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); } }
public void updateTicketAttachment(TicketAttachmentViewModel ticketAttachmentViewModel) { TicketAttachment ticketAttachment = TicketAttachmentRepo.GetEntity(x => x.Id == ticketAttachmentViewModel.Id); Ticket ticket = TicketRepo.GetEntity(x => x.Id == ticketAttachment.TicketId); var stream = ticketAttachmentViewModel.FileData.InputStream; var fileName = ticketAttachmentViewModel.FileData.FileName; File.Delete(ticketAttachment.FilePath); string source = Path.GetDirectoryName(ticketAttachment.FilePath) + "\\" + fileName; int n = ticketAttachment.FileURL.LastIndexOf("/"); string fileURL = ticketAttachment.FileURL.Substring(0, n) + "/" + fileName; FileInfo fi = new FileInfo(source); var di = fi.Directory; di.Create(); ticketAttachment.FilePath = source; ticketAttachment.Description = ticketAttachmentViewModel.Description; ticketAttachment.Created = DateTime.Now; ticketAttachment.FileURL = fileURL; TicketAttachmentRepo.Update(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); } }
public ActionResult UpdateTicketAttachment(int ticketAttachmentId) { var ticketAttachment = ticketAttachmentLogic.GetTicketAttachment(ticketAttachmentId); if (ticketAttachment == null) { return(RedirectToAction("Error")); } //ViewBag.AttachmentId = ticketAttachment.Id; TicketAttachmentViewModel ticketAttachmentViewModel = new TicketAttachmentViewModel(); ticketAttachmentViewModel.Description = ticketAttachment.Description; ticketAttachmentViewModel.Id = ticketAttachment.Id; ticketAttachmentViewModel.FilePath = ticketAttachment.FilePath; ticketAttachmentViewModel.TicketId = ticketAttachment.TicketId; return(View(ticketAttachmentViewModel)); }
public ActionResult CreateTicketAttachment(TicketAttachmentViewModel ticketAttachmentViewModel) { ticketAttachmentLogic.createTicketAttachment(ticketAttachmentViewModel); return(RedirectToAction("Index", new { ticketId = ticketAttachmentViewModel.TicketId })); }