public async Task <ActionResult> DeleteConfirmed(int id) { // Now add the TicketHistory for the TicketComment Deletion TicketComment ticketComment = db.TicketComments.Find(id); HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId()); ticketHistory.AddHistoryEvent(ticketComment.TicketId, "Comment Deleted", null, null); int ticketId = ticketComment.TicketId; var project = db.Projects.First(p => p.Tickets.Any(t => t.Id == ticketComment.TicketId)); if (User.IsInRole("Admin") || (User.IsInRole("ProjectManager") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) || (User.IsInRole("Developer") && ticketComment.AuthorId == User.Identity.GetUserId()) || (User.IsInRole("Submitter") && ticketComment.AuthorId == User.Identity.GetUserId())) { db.TicketComments.Remove(ticketComment); db.SaveChanges(); // Now send Notification, if ticket.AssignedUserId != Current User Ticket ticket = db.Tickets.Find(ticketId); if (ticket.AssignedUserId != null && ticket.AssignedUserId != User.Identity.GetUserId()) { string assignedUserEmailAddress = db.Users.Find(ticket.AssignedUserId).Email; bool commentAdded = false; NotificationHelper notification = new NotificationHelper(User.Identity.GetUserId()); await notification.AddCommentNotification(ticket.Id, ticketComment.Body, commentAdded, assignedUserEmailAddress); } return(RedirectToAction("Details", "Tickets", new { id = ticketId })); } return(RedirectToAction("Details", "Tickets", new { id = ticketId })); }
public async Task <ActionResult> DeleteConfirmed(int id) { TicketAttachment ticketAttachment = db.TicketAttachments.Find(id); Ticket ticket = db.Tickets.First(t => t.Id == ticketAttachment.TicketId); Project project = db.Projects.Find(ticket.ProjectId); if ((User.IsInRole("Admin") || (User.IsInRole("ProjectManager") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) || (User.IsInRole("Developer") && ticket.AssignedUserId == User.Identity.GetUserId()) || (User.IsInRole("Submitter") && ticket.OwnerUserId == User.Identity.GetUserId())) && (ticket.IsArchived == false)) { // Now delete from database db.TicketAttachments.Remove(ticketAttachment); db.SaveChanges(); // Now delete the file from the repository var absPath = Server.MapPath(ticketAttachment.FileUrl); //att.SaveAs(Path.Combine(absPath, att.FileName)); try { System.IO.File.Delete(@absPath); } catch (System.IO.IOException e) { Console.WriteLine(e.Message); Console.ReadLine(); return(RedirectToAction("Details", "Tickets", new { id = ticket.Id })); } // Now add the TicketHistory for the TicketAttachment Deletion HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId()); ticketHistory.AddHistoryEvent(ticketAttachment.TicketId, "Attachment Deleted", ticketAttachment.FileUrl, null); // Now send notification, if assignedUser != Current User if (ticket.AssignedUserId != null && ticket.AssignedUserId != User.Identity.GetUserId()) { List <string> attachments = new List <string>(); attachments.Add(ticketAttachment.FileName); string assignedUserEmailAddress = db.Users.Find(ticket.AssignedUserId).Email; bool attAdded = false; NotificationHelper notification = new NotificationHelper(User.Identity.GetUserId()); await notification.AddAttachmentNotification(ticket.Id, attachments, attAdded, assignedUserEmailAddress); } return(RedirectToAction("Details", "Tickets", new { id = ticket.Id })); } return(RedirectToAction("Details", "Tickets", new { id = ticket.Id })); }
public async Task <ActionResult> Create([Bind(Include = "Id,Body")] TicketComment ticketComment, int ticketId) { TicketComment comment = db.TicketComments.Find(ticketComment.Id); Ticket ticket = db.Tickets.Find(ticketId); Project project = db.Projects.Find(ticket.ProjectId); if ((User.IsInRole("Admin") || (User.IsInRole("ProjectManager") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) || (User.IsInRole("Developer") && ticket.AssignedUserId == User.Identity.GetUserId()) || (User.IsInRole("Submitter") && ticket.OwnerUserId == User.Identity.GetUserId())) && (ticket.IsArchived == false)) { if (ModelState.IsValid) { // Now add the TicketHistory for the TicketComment Creation HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId()); ticketHistory.AddHistoryEvent(ticket.Id, "Comment Created", null, ticketComment.Body); ticketComment.Created = DateTimeOffset.UtcNow; ticketComment.TicketId = ticketId; ticketComment.AuthorId = User.Identity.GetUserId(); db.TicketComments.Add(ticketComment); db.SaveChanges(); // Now send Notification, if ticket.AssignedUserId != Current User if (ticket.AssignedUserId != null && ticket.AssignedUserId != User.Identity.GetUserId()) { string assignedUserEmailAddress = db.Users.Find(ticket.AssignedUserId).Email; bool commentAdded = true; NotificationHelper notification = new NotificationHelper(User.Identity.GetUserId()); await notification.AddCommentNotification(ticket.Id, ticketComment.Body, commentAdded, assignedUserEmailAddress); } return(RedirectToAction("Details", "Tickets", new { id = ticketId })); } ViewBag.ticketId = ticketId; return(View(ticketComment)); //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketComment.TicketId); } return(RedirectToAction("Details", "Tickets", new { id = ticketId })); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Body,Created,TicketId,AuthorId")] TicketComment ticketComment) { Ticket ticket = db.Tickets.Find(ticketComment.TicketId); Project project = db.Projects.First(p => p.Id == ticket.ProjectId); if ((User.IsInRole("Admin") || (User.IsInRole("ProjectManager") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) || (User.IsInRole("Developer") && ticketComment.AuthorId == User.Identity.GetUserId()) || (User.IsInRole("Submitter") && ticketComment.AuthorId == User.Identity.GetUserId())) && (ticket.IsArchived == false)) { if (ModelState.IsValid) { // Now add the TicketHistory for the TicketComment Edit TicketComment oldComment = db.TicketComments.AsNoTracking().First(t => t.Id == ticketComment.Id); HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId()); ticketHistory.AddHistoryEvent(ticketComment.TicketId, "Comment Edited", oldComment.Body, ticketComment.Body); // Now send Notification, if ticket.AssignedUserId != Current User if (ticket.AssignedUserId != null && ticket.AssignedUserId != User.Identity.GetUserId()) { string assignedUserEmailAddress = db.Users.Find(ticket.AssignedUserId).Email; NotificationHelper notification = new NotificationHelper(User.Identity.GetUserId()); await notification.AddCommentEditedNotification(ticket.Id, oldComment.Body, ticketComment.Body, assignedUserEmailAddress); } db.Entry(ticketComment).State = EntityState.Modified; ticketComment.Updated = DateTime.Now; db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticket.Id })); } //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketComment.TicketId); return(View(ticketComment)); } return(RedirectToAction("Details", "Tickets", new { id = ticket.Id })); }
public async Task <ActionResult> Create([Bind(Include = "Id,Description,FileUrl,Created,TicketId,AuthorId")] TicketAttachment ticketAttachment, int ticketId, ICollection <HttpPostedFileBase> files) { if (!db.Tickets.Any(t => t.Id == ticketId)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Ticket ticket = db.Tickets.First(t => t.Id == ticketId); Project project = db.Projects.First(p => p.Tickets.Any(x => x.Id == ticketId)); if ((User.IsInRole("Admin") || (User.IsInRole("ProjectManager") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) || (User.IsInRole("Developer") && ticket.AssignedUserId == User.Identity.GetUserId()) || (User.IsInRole("Submitter") && ticket.OwnerUserId == User.Identity.GetUserId())) && (ticket.IsArchived == false)) { if (ModelState.IsValid) { TicketAttachment attachment = new TicketAttachment(); List <string> attachments = new List <string>(); foreach (var att in files) { if (att != null && att.ContentLength > 0) { // Process File Info and Save File var ext = Path.GetExtension(att.FileName).ToLower(); // Gets image's extension and then sets it to lower case var filePath = "Content/Media/Ticket Attachments/" + ticketId; var absPath = Server.MapPath("~/" + filePath); string newFileName = att.FileName; var num = 0; while (System.IO.File.Exists(Path.Combine(absPath, newFileName))) { //Sets "filename" back to the default value newFileName = Path.GetFileNameWithoutExtension(att.FileName); //Add's parentheses after the name with a number ex. filename(4) newFileName = string.Format(newFileName + "(" + ++num + ")" + ext); //Makes sure pPic gets updated with the new filename so it could check //attach = fileName + Path.GetExtension(doc.FileName); } attachments.Add(newFileName); att.SaveAs(Path.Combine(absPath, newFileName)); // Update attachment info and add to database attachment.FileUrl = "/" + filePath + "/" + newFileName; attachment.FileName = newFileName; attachment.AuthorId = User.Identity.GetUserId(); attachment.Created = DateTime.UtcNow; attachment.TicketId = ticketId; attachment.IconUrl = ""; switch (ext) { case ".png": attachment.IconUrl = "~/Content/Images/Icons/512px/png.png"; break; case ".jpg": attachment.IconUrl = "~/Content/Images/Icons/512px/jpg.png"; break; case ".jpeg": attachment.IconUrl = "~/Content/Images/Icons/512px/jpeg.png"; break; case ".gif": attachment.IconUrl = "~/Content/Images/Icons/512px/gif.png"; break; case ".bmp": attachment.IconUrl = "~/Content/Images/Icons/512px/bmp.png"; break; case ".jfif": attachment.IconUrl = "~/Content/Images/Icons/512px/jfif.png"; break; case ".tiff": attachment.IconUrl = "~/Content/Images/Icons/512px/tiff.png"; break; case ".doc": attachment.IconUrl = "~/Content/Images/Icons/512px/doc.png"; break; case ".docx": attachment.IconUrl = "~/Content/Images/Icons/512px/doc.png"; break; case ".xls": attachment.IconUrl = "~/Content/Images/Icons/512px/xls.png"; break; case ".xlsx": attachment.IconUrl = "~/Content/Images/Icons/512px/xls.png"; break; case ".pdf": attachment.IconUrl = "~/Content/Images/Icons/512px/pdf.png"; break; case ".txt": attachment.IconUrl = "~/Content/Images/Icons/512px/txt.png"; break; case ".htm": attachment.IconUrl = "~/Content/Images/Icons/512px/html.png"; break; case ".html": attachment.IconUrl = "~/Content/Images/Icons/512px/html.png"; break; case ".ppt": attachment.IconUrl = "~/Content/Images/Icons/512px/ppt.png"; break; case ".pptx": attachment.IconUrl = "~/Content/Images/Icons/512px/ppt.png"; break; case ".zip": attachment.IconUrl = "~/Content/Images/Icons/512px/zip.png"; break; case ".rar": attachment.IconUrl = "~/Content/Images/Icons/512px/rar.png"; break; case ".csv": attachment.IconUrl = "~/Content/Images/Icons/512px/csv.png"; break; case ".rtf": attachment.IconUrl = "~/Content/Images/Icons/512px/rtf.png"; break; case ".xml": attachment.IconUrl = "~/Content/Images/Icons/512px/xml.png"; break; case ".mp3": attachment.IconUrl = "~/Content/Images/Icons/512px/mp3.png"; break; case ".mp4": attachment.IconUrl = "~/Content/Images/Icons/512px/mp4.png"; break; case ".wav": attachment.IconUrl = "~/Content/Images/Icons/512px/wav.png"; break; case ".avi": attachment.IconUrl = "~/Content/Images/Icons/512px/avi.png"; break; case ".wmv": attachment.IconUrl = "~/Content/Images/Icons/512px/_blank.png"; break; case ".mpg": attachment.IconUrl = "~/Content/Images/Icons/512px/mpg.png"; break; case ".flv": attachment.IconUrl = "~/Content/Images/Icons/512px/flv.png"; break; case ".mov": attachment.IconUrl = "~/Content/Images/Icons/512px/mov.png"; break; case ".css": attachment.IconUrl = "~/Content/Images/Icons/512px/css.png"; break; case ".less": attachment.IconUrl = "~/Content/Images/Icons/512px/less.png"; break; case ".sass": attachment.IconUrl = "~/Content/Images/Icons/512px/sass.png"; break; case ".dat": attachment.IconUrl = "~/Content/Images/Icons/512px/dat.png"; break; case ".cpp": attachment.IconUrl = "~/Content/Images/Icons/512px/cpp.png"; break; case ".js": attachment.IconUrl = "~/Content/Images/Icons/512px/js.png"; break; case ".py": attachment.IconUrl = "~/Content/Images/Icons/512px/py.png"; break; case ".rb": attachment.IconUrl = "~/Content/Images/Icons/512px/rb.png"; break; case ".php": attachment.IconUrl = "~/Content/Images/Icons/512px/php.png"; break; case ".dwg": attachment.IconUrl = "~/Content/Images/Icons/512px/dwg.png"; break; default: attachment.IconUrl = "~/Content/Images/Icons/512px/_blank.png"; break; } db.TicketAttachments.Add(attachment); db.SaveChanges(); // Now add the TicketHistory for the TicketAttachment Creation HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId()); ticketHistory.AddHistoryEvent(ticketAttachment.TicketId, "Attachment Added", null, attachment.FileUrl); } } // Now, send notification, if Ticket.AssignedUserId == Current User if (ticket.AssignedUserId != null && User.Identity.GetUserId() != ticket.AssignedUserId) { ApplicationUser assignedUser = db.Users.Find(ticket.AssignedUserId); string assignedUserEmailAddress = assignedUser.Email; bool attAdded = true; NotificationHelper notification = new NotificationHelper(User.Identity.GetUserId()); await notification.AddAttachmentNotification(ticket.Id, attachments, attAdded, assignedUserEmailAddress); } return(RedirectToAction("Details", "Tickets", new { id = ticketId })); } //ViewBag.AuthorId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.AuthorId); //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId); return(View(ticketAttachment)); } return(RedirectToAction("Details", "Tickets", new { id = ticketId })); }
public async Task <ActionResult> Edit([Bind(Include = "Id,Created,Updated,Title,Description,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedUserId,IsArchived")] Ticket ticket) { var project = db.Projects.First(p => p.Id == ticket.ProjectId); if ((User.IsInRole("Admin") || (User.IsInRole("ProjectManager") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) || (User.IsInRole("Developer") && project.Users.Any(u => u.Id == User.Identity.GetUserId())) || (User.IsInRole("Submitter") && ticket.OwnerUserId == User.Identity.GetUserId())) && (ticket.IsArchived == false)) { var userId = User.Identity.GetUserId(); if (ModelState.IsValid) { bool hasAssignedUserIdChanged = false; // Declaration of a two-dimensional String Array and a Counter // The array is set to the max possible size, which will likely not be used. // The arrayCounter is passed, along with the array, to the NotificationHelper to indicate the # of rows in the array string[,] arrChangedProperties = new string[7, 3]; int arrayCounter = 0; // Ticket History entries need to be created for each event // Determine which Property(s) were changed HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId()); Ticket oldTicket = db.Tickets.AsNoTracking().First(t => t.Id == ticket.Id); if (oldTicket.Title != ticket.Title) { ticketHistory.AddHistoryEvent(ticket.Id, "Title", oldTicket.Title, ticket.Title); arrChangedProperties[arrayCounter, 0] = "Title"; arrChangedProperties[arrayCounter, 1] = oldTicket.Title; arrChangedProperties[arrayCounter, 2] = ticket.Title; arrayCounter++; } if (oldTicket.Description != ticket.Description) { ticketHistory.AddHistoryEvent(ticket.Id, "Description", oldTicket.Description, ticket.Description); arrChangedProperties[arrayCounter, 0] = "Description"; arrChangedProperties[arrayCounter, 1] = oldTicket.Description; arrChangedProperties[arrayCounter, 2] = ticket.Description; arrayCounter++; } if (oldTicket.TicketPriorityId != ticket.TicketPriorityId) { TicketPriority oldPriority = db.TicketPriorities.Find(oldTicket.TicketPriorityId); TicketPriority newPriority = db.TicketPriorities.Find(ticket.TicketPriorityId); ticketHistory.AddHistoryEvent(ticket.Id, "TicketPriorityId", oldPriority.Name, newPriority.Name); arrChangedProperties[arrayCounter, 0] = "Priority"; arrChangedProperties[arrayCounter, 1] = oldPriority.Name; arrChangedProperties[arrayCounter, 2] = newPriority.Name; arrayCounter++; } if (oldTicket.TicketStatusId != ticket.TicketStatusId) { TicketStatus oldStatus = db.TicketStatuses.Find(oldTicket.TicketStatusId); TicketStatus newStatus = db.TicketStatuses.Find(ticket.TicketStatusId); ticketHistory.AddHistoryEvent(ticket.Id, "TicketStatus", oldStatus.Name, newStatus.Name); arrChangedProperties[arrayCounter, 0] = "Status"; arrChangedProperties[arrayCounter, 1] = oldStatus.Name; arrChangedProperties[arrayCounter, 2] = newStatus.Name; arrayCounter++; } if (oldTicket.AssignedUserId != ticket.AssignedUserId) { ApplicationUser newUser = db.Users.Find(ticket.AssignedUserId); arrChangedProperties[arrayCounter, 0] = "Developer"; if (oldTicket.AssignedUserId == null) { ticketHistory.AddHistoryEvent(ticket.Id, "AssignedUserId", "null", newUser.FullName); arrChangedProperties[arrayCounter, 1] = "null"; } else { ApplicationUser oldUser = db.Users.Find(oldTicket.AssignedUserId); ticketHistory.AddHistoryEvent(ticket.Id, "AssignedUserId", oldUser.FullName, newUser.FullName); arrChangedProperties[arrayCounter, 1] = oldUser.FullName; } arrChangedProperties[arrayCounter, 2] = newUser.FullName; arrayCounter++; hasAssignedUserIdChanged = true; } if (oldTicket.TicketTypeId != ticket.TicketTypeId) { TicketType oldType = db.TicketTypes.Find(oldTicket.TicketTypeId); TicketType newType = db.TicketTypes.Find(ticket.TicketTypeId); ticketHistory.AddHistoryEvent(ticket.Id, "Ticket Type", oldType.Name, newType.Name); arrChangedProperties[arrayCounter, 0] = "Type"; arrChangedProperties[arrayCounter, 1] = oldType.Name; arrChangedProperties[arrayCounter, 2] = newType.Name; arrayCounter++; } if (oldTicket.IsArchived != ticket.IsArchived) { ticketHistory.AddHistoryEvent(ticket.Id, "Ticket Archived", oldTicket.IsArchived, ticket.IsArchived); //hasIsArchivedChanged = true; arrChangedProperties[arrayCounter, 0] = "Archived"; arrChangedProperties[arrayCounter, 1] = oldTicket.IsArchived.ToString(); arrChangedProperties[arrayCounter, 2] = ticket.IsArchived.ToString(); arrayCounter++; } //The ticket must be saved before calling the Notification ticket.Updated = DateTimeOffset.UtcNow; db.Entry(ticket).State = EntityState.Modified; db.SaveChanges(); //Call NotificationHelper NotificationHelper notification = new NotificationHelper(User.Identity.GetUserId()); string newAssignedUserEmailAddress = "temporary value"; if (ticket.AssignedUserId != null) { newAssignedUserEmailAddress = db.Users.Find(ticket.AssignedUserId).Email; } string oldAssignedUserEmailAddress = "temporary value"; if (oldTicket.AssignedUserId != null) { oldAssignedUserEmailAddress = db.Users.Find(oldTicket.AssignedUserId).Email; } if (User.Identity.GetUserId() == oldTicket.AssignedUserId) //If the Current User was the Assignee and... { if (hasAssignedUserIdChanged) //If the CurrentUser/oldAssignedUser has reassigned the ticket - Notification to newAssignedUser only { await notification.AddNotification(ticket.Id, arrChangedProperties, arrayCounter, newAssignedUserEmailAddress); } //If the Current User did not reassign the Ticket - no Notifications } else //If the Current User was NOT oldAssignedUser { if (User.Identity.GetUserId() == ticket.AssignedUserId) { //If the Current User is newAssignedUser - Notification to oldAssignedUser only //Assumes that the Assignee has changed since they are NOT the oldAssigneeId and ARE the newAssigneeId if (oldTicket.AssignedUserId != null) { await notification.AddNotification(ticket.Id, arrChangedProperties, arrayCounter, oldAssignedUserEmailAddress); } } else //Current User is neither the oldAssignedUser or the newAssignedUser { if (hasAssignedUserIdChanged) { if (oldTicket.AssignedUserId != null) { await notification.AddNotification(ticket.Id, arrChangedProperties, arrayCounter, oldAssignedUserEmailAddress); } await notification.AddNotification(ticket.Id, arrChangedProperties, arrayCounter, newAssignedUserEmailAddress); } else //Current User is neither assignee and the assignee has not changed. Ticket changes were made, however and the assigned Developer needs to be notified. { await notification.AddNotification(ticket.Id, arrChangedProperties, arrayCounter, newAssignedUserEmailAddress); } } } //My God, it is finally over!! return(RedirectToAction("Details", "Tickets", new { id = ticket.Id })); } ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Title", ticket.ProjectId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId); return(View(ticket)); } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Title,Description,ProjectId,TicketTypeId,TicketPriorityId")] Ticket ticket, ICollection <HttpPostedFileBase> files) { if (ModelState.IsValid) { ticket.Created = DateTimeOffset.UtcNow; ticket.OwnerUserId = User.Identity.GetUserId(); ticket.TicketStatusId = 1; ticket.IsArchived = false; db.Tickets.Add(ticket); db.SaveChanges(); //Now create a folder for any attachments to be added var attPath = "~/Content/Media/Ticket Attachments/" + ticket.Id; var newPath = Server.MapPath(attPath); Directory.CreateDirectory(newPath); // Now save the attachments TicketAttachment attachment = new TicketAttachment(); foreach (var att in files) { if (att != null && att.ContentLength > 0) { // Process File Info and Save File var ext = Path.GetExtension(att.FileName).ToLower(); // Gets image's extension and then sets it to lower case var filePath = "Content/Media/Ticket Attachments/" + ticket.Id; var absPath = Server.MapPath("~/" + filePath); string newFileName = att.FileName; var num = 0; while (System.IO.File.Exists(Path.Combine(absPath, newFileName))) { //Sets "filename" back to the default value newFileName = Path.GetFileNameWithoutExtension(att.FileName); //Add's parentheses after the name with a number ex. filename(4) newFileName = string.Format(newFileName + "(" + ++num + ")" + ext); //Makes sure pPic gets updated with the new filename so it could check //attach = fileName + Path.GetExtension(doc.FileName); } att.SaveAs(Path.Combine(absPath, newFileName)); // Update attachment info and add to database attachment.FileUrl = "/" + filePath + "/" + newFileName; attachment.FileName = newFileName; attachment.AuthorId = User.Identity.GetUserId(); attachment.Created = DateTime.UtcNow; attachment.TicketId = ticket.Id; attachment.IconUrl = ""; switch (ext) { case ".png": attachment.IconUrl = "~/Content/Images/Icons/512px/png.png"; break; case ".jpg": attachment.IconUrl = "~/Content/Images/Icons/512px/jpg.png"; break; case ".jpeg": attachment.IconUrl = "~/Content/Images/Icons/512px/jpeg.png"; break; case ".gif": attachment.IconUrl = "~/Content/Images/Icons/512px/gif.png"; break; case ".bmp": attachment.IconUrl = "~/Content/Images/Icons/512px/bmp.png"; break; case ".jfif": attachment.IconUrl = "~/Content/Images/Icons/512px/jfif.png"; break; case ".tiff": attachment.IconUrl = "~/Content/Images/Icons/512px/tiff.png"; break; case ".doc": attachment.IconUrl = "~/Content/Images/Icons/512px/doc.png"; break; case ".docx": attachment.IconUrl = "~/Content/Images/Icons/512px/doc.png"; break; case ".xls": attachment.IconUrl = "~/Content/Images/Icons/512px/xls.png"; break; case ".xlsx": attachment.IconUrl = "~/Content/Images/Icons/512px/xls.png"; break; case ".pdf": attachment.IconUrl = "~/Content/Images/Icons/512px/pdf.png"; break; case ".txt": attachment.IconUrl = "~/Content/Images/Icons/512px/txt.png"; break; case ".htm": attachment.IconUrl = "~/Content/Images/Icons/512px/html.png"; break; case ".html": attachment.IconUrl = "~/Content/Images/Icons/512px/html.png"; break; case ".ppt": attachment.IconUrl = "~/Content/Images/Icons/512px/ppt.png"; break; case ".pptx": attachment.IconUrl = "~/Content/Images/Icons/512px/ppt.png"; break; case ".zip": attachment.IconUrl = "~/Content/Images/Icons/512px/zip.png"; break; case ".rar": attachment.IconUrl = "~/Content/Images/Icons/512px/rar.png"; break; case ".csv": attachment.IconUrl = "~/Content/Images/Icons/512px/csv.png"; break; case ".rtf": attachment.IconUrl = "~/Content/Images/Icons/512px/rtf.png"; break; case ".xml": attachment.IconUrl = "~/Content/Images/Icons/512px/xml.png"; break; case ".mp3": attachment.IconUrl = "~/Content/Images/Icons/512px/mp3.png"; break; case ".mp4": attachment.IconUrl = "~/Content/Images/Icons/512px/mp4.png"; break; case ".wav": attachment.IconUrl = "~/Content/Images/Icons/512px/wav.png"; break; case ".avi": attachment.IconUrl = "~/Content/Images/Icons/512px/avi.png"; break; case ".wmv": attachment.IconUrl = "~/Content/Images/Icons/512px/_blank.png"; break; case ".mpg": attachment.IconUrl = "~/Content/Images/Icons/512px/mpg.png"; break; case ".flv": attachment.IconUrl = "~/Content/Images/Icons/512px/flv.png"; break; case ".mov": attachment.IconUrl = "~/Content/Images/Icons/512px/mov.png"; break; case ".css": attachment.IconUrl = "~/Content/Images/Icons/512px/css.png"; break; case ".less": attachment.IconUrl = "~/Content/Images/Icons/512px/less.png"; break; case ".sass": attachment.IconUrl = "~/Content/Images/Icons/512px/sass.png"; break; case ".dat": attachment.IconUrl = "~/Content/Images/Icons/512px/dat.png"; break; case ".cpp": attachment.IconUrl = "~/Content/Images/Icons/512px/cpp.png"; break; case ".js": attachment.IconUrl = "~/Content/Images/Icons/512px/js.png"; break; case ".py": attachment.IconUrl = "~/Content/Images/Icons/512px/py.png"; break; case ".rb": attachment.IconUrl = "~/Content/Images/Icons/512px/rb.png"; break; case ".php": attachment.IconUrl = "~/Content/Images/Icons/512px/php.png"; break; case ".dwg": attachment.IconUrl = "~/Content/Images/Icons/512px/dwg.png"; break; default: attachment.IconUrl = "~/Content/Images/Icons/512px/_blank.png"; break; } db.TicketAttachments.Add(attachment); db.SaveChanges(); } } // Now add the TicketHistory for the Ticket Creation HistoryHelper ticketHistory = new HistoryHelper(User.Identity.GetUserId()); ticketHistory.AddHistoryEvent(ticket.Id, "CreationDate", null, ticket.Created.ToString()); return(RedirectToAction("Index")); } List <Project> projects = db.Projects.ToList(); ViewBag.ProjectId = new SelectList(projects.Where(p => p.Users.Any(u => u.Id == User.Identity.GetUserId())).ToList(), "Id", "Title"); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "Name", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "Name", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "Name", ticket.TicketTypeId); return(View(ticket)); }