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 = "Id,Title,Description,FilePath,FileUrl,Created,TicketId,UserId")] TicketAttachment ticketAttachment, HttpPostedFileBase attachment, string TicketDescription) { if (ModelState.IsValid && UploadValidator.IsAcceptableUploadType(attachment)) { ticketAttachment.Description = TicketDescription; var fileName = Path.GetFileName(attachment.FileName); Directory.CreateDirectory(Server.MapPath($"~/Uploads/{ticketAttachment.TicketId}")); attachment.SaveAs(Path.Combine(Server.MapPath($"~/Uploads/{ticketAttachment.TicketId}"), fileName)); //ticketAttachment.FilePath = Server.MapPath($"~/Uploads/{ticketAttachment.TicketId}"); ticketAttachment.FilePath = $"/Uploads/{ticketAttachment.TicketId}/{fileName}"; ticketAttachment.Created = DateTimeOffset.Now; ticketAttachment.Title = fileName; db.TicketAttachments.Add(ticketAttachment); db.SaveChanges(); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "Title", ticketAttachment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketAttachment.UserId); //return RedirectToAction("Index", "Tickets"); return(RedirectToAction("Details", "Tickets", new { id = ticketAttachment.TicketId })); }
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,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,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,OwnerUserId,AssignedToUserId,Title,Description,Created,Updated")] Tickets tickets, HttpPostedFileBase image, TicketAttachments ticketAttachment) { if (ModelState.IsValid) { if (UploadValidator.IsWebFriendlyAttachment(image)) { var filename = Path.GetFileName(image.FileName); image.SaveAs(Path.Combine(Server.MapPath("~/Uploads/"), filename)); ticketAttachment.FilePath = "/Uploads/" + filename; } var project = db.Projects.FirstOrDefault(p => p.Id == tickets.ProjectId); tickets.Project = project; tickets.OwnerUserId = User.Identity.GetUserId(); tickets.Created = DateTime.Now; db.Tickets.Add(tickets); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AssignedToUserId = new SelectList(db.Users, "Id", "FirstName", tickets.AssignedToUserId); ViewBag.OwnerUserId = new SelectList(db.Users, "Id", "FirstName", tickets.OwnerUserId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", tickets.ProjectId); ViewBag.TicketStatusId = new SelectList(db.TicketStatus, "Id", "StatusName", tickets.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "TypeName", tickets.TicketTypeId); return(View(tickets)); }
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 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 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)); }
public ActionResult EditProfile(AdminUser model, HttpPostedFileBase avatar) { var userId = User.Identity.GetUserId(); var user = db.Users.Find(userId); user.DisplayName = model.DisplayName; user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; if (avatar != null) { if (UploadValidator.IsWebFriendlyAttachment(avatar)) { var filename = Path.GetFileName(avatar.FileName); avatar.SaveAs(Path.Combine(Server.MapPath("~/Avatars/"), filename)); user.AvatarPath = "/Avatars/" + filename; } } db.SaveChanges(); return(View()); }