public async Task <ActionResult> CreateTicketAttachments([Bind(Include = "Id,TicketId,UserId,FilePath,Description,Created,FileUrl")] TicketAttachments ticketAttachments, HttpPostedFileBase image) { if (ModelState.IsValid) { Tickets tickets = db.Tickets.FirstOrDefault(); ApplicationUser NotifyUser = db.Users.FirstOrDefault(u => u.Id.Equals(tickets.AssignedToUserId)); if (ImageUploadValidator.IsWebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/assets/Uploads/"), fileName)); ticketAttachments.FileUrl = "~/assets/Uploads/" + fileName; } ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.Created = DateTimeOffset.Now; db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); if (NotifyUser != null /*|| !(await UserManager.IsEmailConfirmedAsync(user.Id))*/) { var callBackUrl = Url.Action("Details", "Tickets", new { id = ticketAttachments.Ticket.Id }, protocol: Request.Url.Scheme); await UserManager.SendEmailAsync(NotifyUser.Id, "Ticket Update" + ticketAttachments.Ticket.Id, "Good day, this is a notification of changes to this <a href=\"" + callBackUrl + "\">ticket</a> you area assigned."); } return(RedirectToAction("Index")); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId); return(View(ticketAttachments)); }
public ActionResult Create(TicketFormViewModel viewModel) { Ticket ticket = new Ticket() { Created = DateTime.Now, OwnersUser = userHelper.GetUserFromId(User.Identity.GetUserId()), ProjectId = viewModel.ProjectId, TicketPrioritiesId = viewModel.TicketPriorityId, TicketTypeId = viewModel.TicketTypeId, Title = viewModel.Title, Description = viewModel.Description, }; int storedTicketId = ticketHelper.AddTicket(ticket); if (viewModel.File != null) { string attachmentPath = ticketHelper.saveFile(viewModel.File); TicketAttachments ticketAttachment = new TicketAttachments() { TicketId = storedTicketId, User = userHelper.GetUserFromId(User.Identity.GetUserId()), Created = DateTime.Now, FilePath = attachmentPath, Description = viewModel.Description, }; ticketHelper.AddTicketAttachment(ticketAttachment); } return(RedirectToAction("Index")); }
public TicketAttachments GetTicketAttachment(int id) { try { var files = new TicketAttachments(); var filesEntity = db.FileStorages.Where(f => f.Reference == id && f.Type == AttachmentType.Ticket).ToList(); if (filesEntity != null) { if (filesEntity.Count != 0) { var count = filesEntity.Count; files.Attachments = new string[count]; for (int i = 0; i < filesEntity.Count; i++) { files.Attachments[i] = filesEntity[i].Path; } ; } return(files); } else { return(null); } } catch (Exception ex) { GlobalVariable.log.Write(LogLevel.Error, ex); } return(null); }
public ActionResult CreateAttachment(int ticketId, [Bind(Include = "Id,Description,TicketTypeId")] TicketAttachments ticketAttachments, HttpPostedFileBase image) { if (ModelState.IsValid) { if (image == null) { return(HttpNotFound()); } if (!ImageUploadValidator.IsWebFriendlyImage(image)) { ViewBag.ErrorMessage = "upload image here"; } var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/ImgUploads/"), fileName)); ticketAttachments.FilePath = "/ImgUploads/" + fileName; ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.Created = DateTime.Now; ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.TicketId = ticketId; db.TicketAttachments.Add(ticketAttachments); var user = db.Users.FirstOrDefault(p => p.Id == ticketAttachments.UserId); var personalEmailService = new PersonalEmailService(); var mailMessage = new MailMessage( WebConfigurationManager.AppSettings["emailto"], user.Email ); mailMessage.Body = "New Attachment"; mailMessage.Subject = "Add Attachment"; mailMessage.IsBodyHtml = true; personalEmailService.Send(mailMessage); db.SaveChanges(); return(RedirectToAction("Details", new { id = ticketId })); } return(View(ticketAttachments)); }
public async Task <ActionResult> Create([Bind(Include = "Id, TicketId,FilePath,Description,UserId,FileUrl")] TicketAttachments ticketAttachments, HttpPostedFileBase attachment) { var ticketHistory = new TicketHistories(); var tickets = new Tickets(); var user = User.Identity.GetUserId(); var currentUser = db.Users.Find(user); //var ticketId = db.Tickets.FirstOrDefault(t => t.OwnerUserId == user).Id; var ticketOwnerId = db.Tickets.FirstOrDefault(t => t.OwnerUserId == user); ticketAttachments.UserId = currentUser.Id; if (FileUploadValidator.IsWebFriendlyFile(attachment)) { var absPath = Path.GetFileName(attachment.FileName); attachment.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), absPath)); ticketAttachments.FileUrl = "~/Uploads/" + absPath; if (ModelState.IsValid) { //Send Notification var developer = db.Users.Find(tickets.AssignedToUserId); if (developer != null && developer.Email != null) { var svc = new EmailService(); var msg = new IdentityMessage(); msg.Destination = developer.Email; msg.Subject = "Bug Tracker Update: " + tickets.Title; msg.Body = ("An attachment has been added to Ticket ID: " + tickets.Id + " - " + tickets.Title); await svc.SendAsync(msg); } //Ticket History ticketHistory.TicketId = ticketAttachments.TicketId; ticketHistory.Property = "Added Attachment"; ticketHistory.NewValue = "Added"; ticketHistory.UserId = ticketAttachments.UserId; ticketHistory.ChangeDate = DateTime.Now; ticketAttachments.Created = DateTime.Now; db.TicketHistories.Add(ticketHistory); db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Index", "Tickets", new { id = ticketAttachments.TicketId })); } } else { ModelState.AddModelError("attachment", "Invalid Format."); } // } //} ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.Id); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId); return(View(ticketAttachments)); }
public ActionResult Create(int id) { var ticketAttachment = new TicketAttachments(); ticketAttachment.TicketId = id; //ViewBag.TicketId = new SelectList(db.Ticket, "Id", "Title"); return(View(ticketAttachment)); }
/// <summary> /// Add ticket attachment in database. /// </summary> /// <param name="ticketAttachment">Ticket attachment to be added in database.</param> public void AddTicketAttachment(TicketAttachments ticketAttachment) { if (ticketAttachment != null) { db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { TicketAttachments ticketAttachments = db.ticketAttachments.Find(id); db.ticketAttachments.Remove(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachments.TicketId })); }
public ActionResult DeleteConfirmed(int id) { TicketAttachments ticketAttachments = db.TicketAttachments.Find(id); db.TicketAttachments.Remove(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,FilePath,Description,UploadDate,UserId")] TicketAttachments ticketAttachments) { if (ModelState.IsValid) { db.Entry(ticketAttachments).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ticketAttachments)); }
public ActionResult Edit([Bind(Include = "Id,TicketId,FilePath,Description,Created,UserId,FileUrl")] TicketAttachments ticketAttachments) { if (ModelState.IsValid) { db.Entry(ticketAttachments).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TicketId = new SelectList(db.Ticket, "Id", "Title", ticketAttachments.TicketId); return(View(ticketAttachments)); }
public ActionResult AddAttachmentConfirm(int?id, HttpPostedFileBase file, string Discription) { if (id == null) { return(RedirectToAction("Index")); } Ticket t = db.Tickets.Find(id); string userId = User.Identity.GetUserId(); bool confirmRole = false; if (User.IsInRole("Admin")) { confirmRole = true; } else if (User.IsInRole("ProjectManager") && TicketHandler.IsTicketBelongToProjectManager(userId, t.Id)) { confirmRole = true; } else if (User.IsInRole("Developer") && TicketHandler.IsTicketBelongToDeveloper(userId, t.Id)) { confirmRole = true; } else if (User.IsInRole("Submitter") && TicketHandler.IsTicketBelongToSubmitter(userId, t.Id)) { confirmRole = true; } else { return(RedirectToAction("Index")); } if (confirmRole == true) { TicketAttachments ticketAttachment = new TicketAttachments(); ticketAttachment.UserId = db.Users.Find(User.Identity.GetUserId()).Email; ticketAttachment.Created = DateTime.Now; ticketAttachment.Discription = Discription; ticketAttachment.TicketId = t.Id; string FileName = Path.GetFileName(file.FileName); //string fileExtention = Path.GetExtension(File.FileName); ticketAttachment.FilePath = "~/AttachedFile" + FileName; var path = Path.Combine(Server.MapPath("~/AttachedFile"), FileName); file.SaveAs(path); if (ModelState.IsValid) { db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); return(RedirectToAction("MyTickets")); } } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "Id,Description,FilePath,Created,UserId,TicketId")] TicketAttachments ticketAttachments) { if (ModelState.IsValid) { db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TicketId = new SelectList(db.Ticket, "Id", "Name", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId); return(View(ticketAttachments)); }
public ActionResult Details(int?id) { if (id == null) { return(View("404", "Account")); } TicketAttachments ticketAttachments = db.TicketAttachment.Find(id); if (ticketAttachments == null) { return(View("404", "Account")); } return(View(ticketAttachments)); }
// GET: TicketAttachments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketAttachments ticketAttachments = db.TicketAttachments.Find(id); if (ticketAttachments == null) { return(HttpNotFound()); } return(View(ticketAttachments)); }
public ActionResult AttachmentDetails(int?id) { if (id == null || !User.Identity.IsAuthenticated) { return(RedirectToAction("Index")); } if (!TicketHandler.TicketAttachmentConfirmation(User.Identity.GetUserId(), Convert.ToInt32(id))) { return(RedirectToAction("Index")); } TicketAttachments ticketAttachments = db.TicketAttachments.Find(id); ticketAttachments.UserId = db.Users.Find(ticketAttachments.UserId).Email; return(View(ticketAttachments)); }
public ActionResult Edit(int?id) { if (id == null) { return(View("404", "Account")); } TicketAttachments ticketAttachments = db.TicketAttachment.Find(id); if (ticketAttachments == null) { return(View("404", "Account")); } ViewBag.TicketId = new SelectList(db.Ticket, "Id", "Title", ticketAttachments.TicketId); return(View(ticketAttachments)); }
// GET: TicketAttachments/Create public ActionResult Create(Tickets tickets) { ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName"); ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title"); var ticketAttachment = new TicketAttachments(); var bp = db.Tickets.Find(ticketAttachment.TicketId); //var project = new Projects(); //Tickets tickets = db.Tickets.Find(id); //ticket.TicketId = id; //ticket.UserId = User.Identity.GetUserId(); var user = db.Users.Find(User.Identity.GetUserId()); if (User.IsInRole("Developer")) { if (!(tickets.AssignedToId == user.Id)) { return(RedirectToAction("Login", "Account")); } } if (User.IsInRole("ProjectManager")) { if (!(tickets.Project.PManagerID == user.Id)) { return(RedirectToAction("Login", "Account")); } } if (User.IsInRole("Submitter")) { if (!(tickets.OwnerUserId == user.Id)) { return(RedirectToAction("Login", "Account")); } } //ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title"); //ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName"); //return View(ticket); if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } return(View()); }
public ActionResult Create([Bind(Include = "Id,TicketId,filepath,description,created,UserId,fileurl")] TicketAttachments ticketAttachments, HttpPostedFileBase fileUpload) { if (ModelState.IsValid) { ticketAttachments.created = DateTimeOffset.Now; ticketAttachments.filepath = Path.Combine(Server.MapPath("~/Uploads/")); fileUpload.SaveAs(ticketAttachments.filepath); db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TicketId = new SelectList(db.Tickets, "id", "Title", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "DisplayName", ticketAttachments.UserId); return(View(ticketAttachments)); }
// GET: TicketAttachments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketAttachments ticketAttachments = db.TicketAttachments.Find(id); if (ticketAttachments == null) { return(HttpNotFound()); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId); return(View(ticketAttachments)); }
// GET: TicketAttachments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketAttachments ticketAttachments = db.TicketAttachments.Find(id); if (ticketAttachments == null) { ViewBag.ticketId = db.Tickets.Find(id); ViewBag.NoAtts = "No Attachments"; return(View()); } return(View(ticketAttachments)); }
public ActionResult Create([Bind(Include = "Id,TicketId,FilePath,Description,UploadDate,UserId")] TicketAttachments ticketAttachments, HttpPostedFileBase image) { if (ModelState.IsValid) { if (UploadValidator.IsWebFriendlyAttachment(image)) { var filename = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename)); ticketAttachments.FilePath = "/Uploads/" + filename; } ticketAttachments.UploadDate = DateTime.Now; db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachments.TicketId })); } return(View(ticketAttachments)); }
public ActionResult Create(AttachmentFormViewModel viewModel) { User loggedInUser = userHelper.GetUserFromId(User.Identity.GetUserId()); if (ticketHelper.isUserExistInTicket(loggedInUser.Id, viewModel.TicketId)) { TicketAttachments attachments = new TicketAttachments { TicketId = viewModel.TicketId, UserId = User.Identity.GetUserId(), FilePath = ticketHelper.saveFile(viewModel.File), Description = viewModel.Description, Created = DateTime.Now, }; db.TicketAttachments.Add(attachments); db.SaveChanges(); } return(RedirectToAction("List", new { id = viewModel.TicketId })); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TicketAttachments ticketAttachments = db.TicketAttachments.Find(id); if (ticketAttachments == null) { return(HttpNotFound()); } var viewModel = new AttachmentFormViewModel() { Id = ticketAttachments.Id, TicketId = ticketAttachments.TicketId, Description = ticketAttachments.Description, }; return(View(viewModel)); }
public ActionResult Create([Bind(Include = "TicketId,FilePath,Description,Created,UserId,FileUrl")] TicketAttachments ticketAttachments, HttpPostedFileBase attachment) { if (ModelState.IsValid) { if (AttachmentUpload.WebFriendlyImage(attachment)) { var fileName = Path.GetFileName(attachment.FileName); attachment.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachments.FilePath = "~/Uploads/" + fileName; } ticketAttachments.Created = DateTimeOffset.Now; ticketAttachments.UserId = User.Identity.GetUserId(); db.TicketAttachment.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachments.TicketId })); } ViewBag.TicketId = new SelectList(db.Ticket, "Id", "Title", ticketAttachments.TicketId); return(View(ticketAttachments)); }
public ActionResult EditAttachmentConfirm([Bind(Include = "Id,Discription")] TicketAttachments ticketAttachment) { TicketAttachments attachments = db.TicketAttachments.Find(ticketAttachment.Id); if (attachments == null) { return(RedirectToAction("MyAttachments")); } bool isAttachmentForRightUser = TicketHandler.TicketAttachmentConfirmation(User.Identity.GetUserId(), attachments.Id); if (isAttachmentForRightUser == true) { attachments.Discription = ticketAttachment.Discription; db.SaveChanges(); } else { return(RedirectToAction("MyAttachments")); } return(View()); }
public async Task <ActionResult> Edit([Bind(Include = "Id,TicketId,FilePath,Description,Created,UserId,FileUrl")] TicketAttachments ticketAttachments) { if (ModelState.IsValid) { db.Entry(ticketAttachments).State = EntityState.Modified; db.SaveChanges(); //Send Email var svc = new EmailService(); var msg = new IdentityMessage(); msg.Subject = "Edited Attachment"; msg.Body = "\r\n Your ticket titled," + ticketAttachments.Ticket.Title + "has a new edit on its attachment." + "\r\n"; msg.Destination = ticketAttachments.Ticket.AssignedTo.Email; await svc.SendAsync(msg); return(RedirectToAction("Index")); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId); return(View(ticketAttachments)); }
public ActionResult Create([Bind(Include = "Id,TicketId,FilePath,Description,Created,UserId,FileURL")] TicketAttachments ticketAttachments, HttpPostedFileBase image, int tId) { if (image != null && image.ContentLength > 0) { //check the file name to make sure its an image var ext = Path.GetExtension(image.FileName).ToLower(); if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" && ext != ".bmp" && ext != ".txt" && ext != ".pdf") { ModelState.AddModelError("image", "Invalid Format."); } } if (image != null) { //relative server path var FilePath = "/Uploads/"; // path on physical drive on server var absPath = Server.MapPath("~" + FilePath); // media url for relative path ticketAttachments.FileURL = FilePath + image.FileName; //save image image.SaveAs(Path.Combine(absPath, image.FileName)); } if (ModelState.IsValid) { ticketAttachments.TicketId = tId; ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.Created = DateTime.Now; db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = tId })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachments.UserId); return(View(ticketAttachments)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Description,Created,TicketId,UserId,FileUrl")] TicketAttachments ticketAttachments, HttpPostedFileBase image /*int id*/) { if (image != null && image.ContentLength > 0) { //check the file name to make sure its an image var ext = Path.GetExtension(image.FileName).ToLower(); if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".gif" && ext != ".bmp") { ModelState.AddModelError("image", "Invalid Format."); } } if (image != null) { //relative server path var filePath = "/Uploads/"; // path on physical drive on server var absPath = Server.MapPath("~" + filePath); // media url for relative path ticketAttachments.FileUrl = filePath + image.FileName; //save image image.SaveAs(Path.Combine(absPath, image.FileName)); } if (ModelState.IsValid) { ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.Created = DateTime.UtcNow; var T = db.Tickets.Find(ticketAttachments.TicketId); var user = db.Users.Find(User.Identity.GetUserId()); if (User.IsInRole("Developer")) { if (!(T.AssignedToId == user.Id)) { return(RedirectToAction("Login", "Account")); } } if (User.IsInRole("ProjectManager")) { if (!(T.Project.PManagerID == user.Id)) { return(RedirectToAction("Login", "Account")); } } if (User.IsInRole("Submitter")) { if (!(T.OwnerUserId == user.Id)) { return(RedirectToAction("Login", "Account")); } } db.TicketAttachments.Add(ticketAttachments); db.SaveChanges(); var svc = new EmailService(); var msg = new IdentityMessage(); msg.Subject = "New Attachment"; msg.Body = "\r\n You have a new Attachment on the ticket titled," + ticketAttachments.Ticket.Title + "with the following description:" + ticketAttachments.Ticket.Description + "\r\n"; msg.Destination = ticketAttachments.Ticket.AssignedToId; await svc.SendAsync(msg); return(RedirectToAction("Details", "Tickets", new { Id = T.Id })); } return(View(ticketAttachments)); }
private ActionResult SaveTicket(int?id, CreateTicketViewModel formData) { var userId = User.Identity.GetUserId(); var ticketPriority = DbContext.TicketsPriorityDatabase.ToList(); var tickets = DbContext.TicketsDatabase.FirstOrDefault(p => p.Id == id); if (!ModelState.IsValid) { //var userName = User.Identity.GetUserName(); //string userName = DbContext.Users.ToList()[0].UserName; var ticketType = DbContext.TicketsTypeDatabase.ToList(); var ticketAttachment = new CreateAttachmetsViewModel() { }; var model = new CreateTicketViewModel { TicketType = ticketType.Select(p => new SelectListItem() { Text = p.Name, Value = p.Id.ToString(), Selected = (tickets?.TicketTypeId ?? -1) == p.Id, }).ToList(), TicketPriority = ticketPriority.Select(p => new SelectListItem() { Text = p.Name, Value = p.Id.ToString(), Selected = (tickets?.TicketPriorityId ?? -1) == p.Id, }).ToList(), ProjectId = id.HasValue ? id.Value : formData.ProjectId, }; return(View(model)); } string fileExtension; //Validating file upload if (formData.Media != null) { fileExtension = Path.GetExtension(formData.Media.FileName); if (!Constants.AllowedFileExtensions.Contains(fileExtension.ToLower())) { ModelState.AddModelError("", "File extension is not allowed."); return(RedirectToAction(nameof(AllTickets))); } } Ticket ticket; //var userId = User.Identity.GetUserId(); if (!id.HasValue) { ticket = new Ticket(); var applicationUser = DbContext.Users.FirstOrDefault(user => user.Id == userId); if (applicationUser == null) { return(RedirectToAction(nameof(HomeController.Index))); } ticket.CreatedBy = applicationUser; ticket.ProjectId = formData.ProjectId; ticket.TicketStatusId = DbContext.TicketsStatusDatabase.First(p => p.Name == "Open").Id; var userMe = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); userMe.SendEmail(userId, "Notification", "There is a new Ticket Created for project You Belong To"); DbContext.TicketsDatabase.Add(ticket); } else { ticket = DbContext.TicketsDatabase.FirstOrDefault(p => p.Id == id); ticket.DateUpdated = DateTime.Now; var status = DbContext.TicketsStatusDatabase.FirstOrDefault(p => p.Id == formData.StatusId); ticket.TicketStatusId = status?.Id ?? DbContext.TicketsStatusDatabase.First(p => p.Name == "Open").Id; if (ticket == null) { return(RedirectToAction(nameof(HomeController.Index))); } } if (formData.Media != null) { if (!Directory.Exists(Constants.MappedUploadFolder)) { Directory.CreateDirectory(Constants.MappedUploadFolder); } var fileName = formData.Media.FileName; var fullPathWithName = Constants.MappedUploadFolder + fileName; formData.Media.SaveAs(fullPathWithName); TicketAttachments attachment; if (true) { attachment = new TicketAttachments() { MediaUrl = Constants.UploadFolder + fileName, TicketId = ticket.Id, UserId = ticket.CreatedById, }; var userMa = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); userMa.SendEmail(userId, "Notification", "There is a new Attachment for Ticket You Belong To"); ticket.Attachments.Add(attachment); DbContext.TicketsAttachmentsDatabase.Add(attachment); } } //var t = DbContext.TicketsPriorityDatabase.FirstOrDefault(p => p.Name.ToList(); == formData.TicketPriority); var tp = DbContext.TicketsPriorityDatabase.FirstOrDefault(p => p.Id == formData.PriorityId); var type = DbContext.TicketsTypeDatabase.FirstOrDefault(p => p.Id == formData.TypeId); ticket.Title = formData.Title; ticket.Description = formData.Description; ticket.TicketPriorityId = tp.Id; ticket.TicketPriorityId = formData.PriorityId; ticket.TicketTypeId = formData.TypeId; ticket.TicketTypeId = type.Id; var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); if (id.HasValue) { TicketHistory(ticket); } foreach (var user in ticket.SendNotification) { var usermanager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); userManager.SendEmail(userId, "Notification", "There Are some changes in a Ticket"); } var userM = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); userM.SendEmail(userId, "Notification", "There is achange in a Ticket You Belong To"); DbContext.SaveChanges(); return(RedirectToAction(nameof(TicketsController.Tickets))); }