public async Task <ActionResult> Index(ApplicationUser model, HttpPostedFileBase image) { FileUploadValidator fileHelper = new FileUploadValidator(); var userId = User.Identity.GetUserId(); model = db.Users.AsNoTracking().FirstOrDefault(u => u.Id == userId); if (fileHelper.IsWebpageFrendlyFile(image)) { TempData["avatarCheck"] = "Success"; var fileName = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Avatar/"), fileName)); model.avatar = "/Avatar/" + fileName; } else { TempData["avatarCheck"] = "Failure"; } db.Users.Attach(model); db.Entry(model).State = EntityState.Modified; db.SaveChanges(); var viewModel = new IndexViewModel { HasPassword = HasPassword(), currentUser = UserManager.FindById(userId), PhoneNumber = await UserManager.GetPhoneNumberAsync(userId), TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId), Logins = await UserManager.GetLoginsAsync(userId), BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId) }; return(View(viewModel)); }
public ActionResult Create([Bind(Include = "Id,TicketId,description")] TicketAttachments ticketAttachments, HttpPostedFileBase file) { if (ModelState.IsValid) { FileUploadValidator helper = new FileUploadValidator(); if (helper.IsWebpageFrendlyFile(file)) { var extention = Path.GetExtension(file.FileName); var fileName = Path.GetFileName(file.FileName); file.SaveAs(Path.Combine(Server.MapPath("~/UploadedFiles/"), fileName)); ticketAttachments.fileURL = "/UploadedFiles/" + fileName; ticketAttachments.filePath = Path.GetFileNameWithoutExtension(file.FileName); if (extention == ".doc" || extention == ".docx") { ticketAttachments.icon = "/Attachments/word.png"; } else if (extention == ".xls" || extention == ".xlsx") { ticketAttachments.icon = "/Attachments/excel.png"; } else if (extention == ".pdf") { ticketAttachments.icon = "/Attachments/pdf.png"; } else if (extention == ".png" || extention == ".jpg" || extention == ".jpeg") { ticketAttachments.icon = "/Attachments/image.png"; } else { ticketAttachments.icon = "/Attachments/default.png"; } } else { TempData["attachCheck"] = "Failure"; return(RedirectToAction("Details", "Tickets", new { id = ticketAttachments.TicketId })); } if (User.IsInRole("ProjectManager") || User.IsInRole("Submitter")) { TicketNotifications notify = new TicketNotifications(); notify.TicketId = ticketAttachments.TicketId; notify.UserId = (string)TempData["assignedId"]; notify.seen = false; notify.notification = (string)TempData["Title"] + " has a new attachment"; db.ticketNotifications.Add(notify); } ticketAttachments.UserId = User.Identity.GetUserId(); ticketAttachments.created = DateTimeOffset.Now; db.ticketAttachments.Add(ticketAttachments); db.SaveChanges(); TempData["attachCheck"] = "Success"; return(RedirectToAction("Details", "Tickets", new { id = ticketAttachments.TicketId })); } TempData["attachCheck"] = "Failure"; ViewBag.TicketId = new SelectList(db.tickets, "Id", "title", ticketAttachments.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "firstName", ticketAttachments.UserId); return(View(ticketAttachments)); }