//[Authorize(Roles = "Admin")] public ActionResult ManageRoles(List <string> userIds, string role) { if (!userRolesHelper.IsDemoUser(User.Identity.GetUserId())) { // Unenroll selected users from any roles foreach (var userId in userIds) { var userRole = userRolesHelper.ListUserRoles(userId).FirstOrDefault(); if (userRole != null) { userRolesHelper.RemoveUserFromRole(userId, userRole); } } // Add user back to role if (!string.IsNullOrEmpty(role)) { foreach (var userId in userIds) { userRolesHelper.AddUserToRole(userId, role); } } } return(RedirectToAction("ManageRoles", "Admin")); }
public ActionResult Create([Bind(Include = "TicketId,Comment")] TicketComment ticketComment) { if (ticketComment.Comment != null) { if (ModelState.IsValid) { ticketComment.Created = DateTime.Now; ticketComment.UserId = User.Identity.GetUserId(); db.TicketComments.Add(ticketComment); var userr = User.Identity.GetUserId(); if (!rolesHelper.IsDemoUser(userr)) { db.SaveChanges(); } return(RedirectToAction("Details", "Tickets", new { id = ticketComment.TicketId })); } } else { return(RedirectToAction("Index", "Tickets")); } ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketComment.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketComment.UserId); return(View(ticketComment)); }
public ActionResult EditProfile() { var sourceUser = db.Users.Find(User.Identity.GetUserId()); if (sourceUser.AvatarPath == null) { sourceUser.AvatarPath = "/Avatars/default_user.png"; var userr = User.Identity.GetUserId(); if (!roleHelper.IsDemoUser(userr)) { db.SaveChanges(); } } var userVm = new UserProfileViewModel(); userVm.Id = sourceUser.Id; userVm.AvatarPath = sourceUser.AvatarPath; userVm.FName = sourceUser.FirstName; userVm.LName = sourceUser.LastName; userVm.NickName = sourceUser.DisplayName; userVm.Email = sourceUser.Email; userVm.UName = sourceUser.UserName; //different approach //var userVm = new UserProfileViewModel //{ // FName = sourceUser.FirstName, // LName = sourceUser.LastName, // NickName = sourceUser.DisplayName, // Email = sourceUser.Email //}; return(View(userVm)); }
public ActionResult Dismiss(int id) { var notification = db.TicketNotifications.Find(id); notification.IsRead = true; var userr = User.Identity.GetUserId(); if (!rolesHelper.IsDemoUser(userr)) { db.SaveChanges(); } return(RedirectToAction("Dashboard", "Home")); }
public ActionResult Create([Bind(Include = "Id,PriorityName,Description")] TicketPriority ticketPriority) { if (ModelState.IsValid) { db.TicketPriorities.Add(ticketPriority); var userr = User.Identity.GetUserId(); if (!rolesHelper.IsDemoUser(userr)) { db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(ticketPriority)); }
public ActionResult Create([Bind(Include = "Id,Name,Description")] Project project) { if (ModelState.IsValid) { project.Created = DateTime.Now; db.Projects.Add(project); var userr = User.Identity.GetUserId(); if (!roleHelper.IsDemoUser(userr)) { db.SaveChanges(); } return(RedirectToAction("Index")); } return(View(project)); }
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,UserId,ProjectId,Property,OldValue,NewValue,Changed")] TicketHistory ticketHistory) { if (ModelState.IsValid) { db.TicketHistories.Add(ticketHistory); var userr = User.Identity.GetUserId(); if (!rolesHelper.IsDemoUser(userr)) { db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.ProjectId = new SelectList(db.Projects, "Id", "ProjectId", ticketHistory.ProjectId); ViewBag.TicketId = new SelectList(db.Tickets, "Id", "SubmitterId", ticketHistory.TicketId); ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", ticketHistory.UserId); return(View(ticketHistory)); }
// this will lock out demo roles from making changes // comment out when updating database for now til addressed public override int SaveChanges() { var userId = HttpContext.Current.User.Identity.GetUserId(); UserRolesHelper role = new UserRolesHelper(); if (role.IsDemoUser(userId)) { HttpContext.Current.Session.Add("Message", "For security purposes demo roles cannot save changes to the database."); // fire sweetalert2 with tempdata return(0); } return(base.SaveChanges()); }
public ActionResult Create([Bind(Include = "Id,ProjectId,TicketTypeId,TicketPriorityId,TicketStatusId,SubmitterId,DeveloperId,Title,Description,Created")] Ticket ticket) { if (ModelState.IsValid) { ticket.SubmitterId = User.Identity.GetUserId(); ticket.Created = DateTime.Now; db.Tickets.Add(ticket); var userr = User.Identity.GetUserId(); if (!rolesHelper.IsDemoUser(userr)) { db.SaveChanges(); } return(RedirectToAction("Index")); } ViewBag.DeveloperId = new SelectList(db.Users, "Id", "FirstName", ticket.DeveloperId); ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name", ticket.ProjectId); ViewBag.SubmitterId = new SelectList(db.Users, "Id", "FirstName", ticket.SubmitterId); ViewBag.TicketPriorityId = new SelectList(db.TicketPriorities, "Id", "PriorityName", ticket.TicketPriorityId); ViewBag.TicketStatusId = new SelectList(db.TicketStatuses, "Id", "StatusName", ticket.TicketStatusId); ViewBag.TicketTypeId = new SelectList(db.TicketTypes, "Id", "TypeName", ticket.TicketTypeId); return(View(ticket)); }