public ActionResult EditProfile(UserProfileViewModel model, HttpPostedFileBase avatar) { var user = db.Users.Find(User.Identity.GetUserId()); user.Id = model.Id; user.FirstName = model.FName; user.LastName = model.LName; user.DisplayName = model.NickName; user.Email = model.Email; user.UserName = model.Email; if (user.AvatarPath != model.AvatarPath) { if (UploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName)); user.AvatarPath = "/Avatars/" + fileName; } } var userr = User.Identity.GetUserId(); if (!roleHelper.IsDemoUser(userr)) { db.SaveChanges(); } return(RedirectToAction("Profile", "Account")); }
public ActionResult Create([Bind(Include = "TicketId,Descriptionn")] TicketAttachment ticketAttachment, HttpPostedFileBase file, string Descriptionn) { if (ModelState.IsValid) { if (file != null) { if (UploadValidator.IsWebFriendlyFile(file) || UploadValidator.IsWebFriendlyImage(file)) { var fileName = Path.GetFileName(file.FileName); var onlyFilename = Path.GetFileNameWithoutExtension(fileName); onlyFilename = StringUtilities.URLFriendly(onlyFilename); fileName = $"{onlyFilename}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; file.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.MediaUrl = "/Uploads/" + fileName; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); ticketAttachment.Description = Descriptionn; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } } return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); //return View("Index"); } return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "TicketId,Description")] TicketAttachment ticketAttachment, HttpPostedFileBase attachments) { if (ModelState.IsValid) { if (attachments != null) { if (UploadValidator.IsWebFriendlyImage(attachments) || UploadValidator.IsWebFriendlyFile(attachments)) { var fileName = Path.GetFileName(attachments.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; attachments.SaveAs(Path.Combine(Server.MapPath("~/Attachments/"), fileName)); ticketAttachment.FilePath = "/Attachments/" + fileName; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); } } var tkAttach = db.Tickets.Find(ticketAttachment.TicketId).Id; return(RedirectToAction("Details", "Tickets", new { id = tkAttach })); } return(View(ticketAttachment)); }
public ActionResult Create([Bind(Include = "Id,TicketsId,Body,MediaUrl,")] Attachments attachment, HttpPostedFileBase image) { if (ModelState.IsValid) { if (UploadValidator.IsWebFriendlyImage(image)) { var fileName = Path.GetFileName(image.FileName); var uniqueId = DateTime.Now.Ticks; fileName = Regex.Replace(fileName, @"[!@#$%_\s]", ""); image.SaveAs(Path.Combine(Server.MapPath("~/fileUpload/"), uniqueId + fileName)); attachment.MediaUrl = "/fileUpload/" + uniqueId + fileName; } else { return(View()); } attachment.Created = DateTimeOffset.Now; attachment.UserId = User.Identity.GetUserId(); db.Attachments.Add(attachment); db.SaveChanges(); TicketHistory history = new TicketHistory(); history.Date = DateTimeOffset.Now; var historyBody = "A new attachment was added to this ticket."; history.Body = historyBody; history.TicketId = attachment.ticketsId; db.TicketHistory.Add(history); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = attachment.ticketsId })); } return(View()); }
public ActionResult EditProfile([Bind(Include = "Id, FirstName, LastName, DisplayName, Email, AvatarPath")] ProfileViewModel user, HttpPostedFileBase avatar) { var myuser = db.Users.Find(user.Id); myuser.FirstName = user.FirstName; myuser.LastName = user.LastName; myuser.DisplayName = user.DisplayName; myuser.Email = user.Email; myuser.UserName = user.Email; if (ModelState.IsValid) { if (myuser.AvatarPath != user.AvatarPath) { if (UploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName); fileName = StringUtilities.URLFriendly(Path.GetFileNameWithoutExtension(fileName)); fileName += "_" + DateTime.Now.Ticks + Path.GetExtension(avatar.FileName); avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName)); myuser.AvatarPath = "/Avatars/" + fileName; } } } db.SaveChanges(); return(RedirectToAction("EditProfile", "Home")); }
public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase avatar) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, AvatarPath = "/Avatars/default.png" }; if (avatar != null) { if (UploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName)); user.AvatarPath = "/Avatars/" + fileName; } } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); await EmailHelper.ComposeEmailAsync(model, callbackUrl); roleHelper.AddUserToRole(user.Id, "Unregistered"); return(RedirectToAction("NewRegister", "Account")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); //return RedirectToAction("Index", "Home"); }
public ActionResult Create([Bind(Include = "TicketId,Description")] TicketAttachment ticketAttachment, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { if (UploadValidator.IsWebFriendlyImage(file) || UploadValidator.IsWebFriendlyFile(file)) { var fileName = Path.GetFileName(file.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); var ticketId = ticketAttachment.TicketId; var oldTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticketId); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; file.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), fileName)); ticketAttachment.FilePath = "/Uploads/" + fileName; ticketAttachment.Created = DateTime.Now; ticketAttachment.UserId = User.Identity.GetUserId(); //=========================== Ticket History ======================================= oldTicket.Updated = DateTime.Now; //ticketAttachment.Ticket.Updated = DateTime.Now; var newTicket = db.Tickets.AsNoTracking().FirstOrDefault(t => t.Id == ticketId); db.Entry(oldTicket).State = EntityState.Modified; db.TicketAttachments.Add(ticketAttachment); auditHelper.RecordAttachments(oldTicket, newTicket, fileName); // create notification notificationHelper.AttachmentNotification(newTicket); //=================================================================================== var userr = User.Identity.GetUserId(); if (!rolesHelper.IsDemoUser(userr)) { db.SaveChanges(); } } } //Response.Redirect(Request.RawUrl); return(RedirectToAction("Index", "Tickets", new { id = ticketAttachment.TicketId })); } return(View(ticketAttachment)); }
public async Task <ActionResult> Register(RegisterViewModel model, HttpPostedFileBase avatar) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, AvatarPath = "/Avatars/default_user.png" }; if (avatar != null) { if (UploadValidator.IsWebFriendlyImage(avatar)) { var fileName = Path.GetFileName(avatar.FileName); var justFileName = Path.GetFileNameWithoutExtension(fileName); justFileName = StringUtilities.URLFriendly(justFileName); fileName = $"{justFileName}_{DateTime.Now.Ticks}{Path.GetExtension(fileName)}"; avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), fileName)); user.AvatarPath = "/Avatars/" + fileName; } } var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); //new users are set to submitter by default roleHelper.AddUserToRole(user.Id, "Submitter"); return(RedirectToAction("Dashboard", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }