//ProjectId = Model.Id, UserId public ActionResult _projectTickets(string ProjectId, string UserId) { Guid projGuid = new Guid(ProjectId); Project proj = db.Project.Find(projGuid); bool allowEdit = true, allowDetails = true, allowDelete = true, usrIsDev = true; if (!string.IsNullOrEmpty(UserId)) { Guid userGuid = new Guid(UserId); usrIsDev = helper.IsUserInRole(UserId, "Developer, Submitter"); /*srIsSub = helper.IsUserInRole(UserId, "Submitter");*/ if (!helper.IsUserInAnyRole(UserId, "Admin", "PM")) { if (usrIsDev) { allowDelete = false; } else { allowEdit = false; allowDetails = false; allowDelete = false; } } } ViewData["ProjTickets"] = proj.Tickets.ToList(); ViewData["allowEdit"] = allowEdit; ViewData["allowDetails"] = allowDetails; ViewData["allowDelete"] = allowDelete; ViewData["usrIsDev"] = usrIsDev; return(PartialView(proj)); }
public ActionResult DeleteRoleForUser(string UserName, string RoleName) { var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); if (urhelper.IsUserInRole(user.Id, RoleName)) { UserManager.RemoveFromRole(user.Id, RoleName); ViewBag.ResultMessage = "Role removed from this user successfully!"; } else { ViewBag.ResultMessage = "This user doesn't belong to selected role!"; } // roles for the view dropdown var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList(); ViewBag.Roles = list; return(View("ManageUserRoles")); }
public ActionResult Index() { // var ticket = db.Ticket.Include(t => t.Project); //join user in db.Users // on userRoles.UserId equals user.Id // select user; var allusers = db.Users.ToList(); var ticket = from e in db.Ticket join a in db.TicketStatuses on e.TicketStatusId equals a.Id join c in db.TicketTypes on e.TicketTypeId equals c.Id select new TicketViewModel() { Id = e.Id, Title = e.Title, ProjectName = e.Project.Title, Description = e.Description, Created = e.Created, Updated = e.Updated, TicketPriority = e.TicketPriorities.Name, TicketStatus = a.Name, TicketType = c.Name, CreatedBy = e.CreatedBy, AssigneeId = e.AssigneeId }; string UserId = User.Identity.GetUserId(); Guid user = new Guid(UserId); ApplicationUser ap = db.Users.Find(UserId); bool usrIsAdmiNOrPM = urhelper.IsUserInAnyRole(UserId, "Admin", "PM"); bool usrIsDev = urhelper.IsUserInRole(UserId, "Developer"); if (usrIsAdmiNOrPM) { //tickets of projects whose project id exits in tickets tbl //var usrprojtik = (from tik in ticket // join proj in ap.Projects on new { tik.Project.Id } equals new { proj.Id } // select tik).ToList(); //return View(usrprojtik); return(View(ticket.OrderBy(x => x.Id).ToList())); } else { if (usrIsDev) { var devassgnedtik = (from tik in ticket where tik.AssigneeId == ap.Email select tik).OrderBy(x => x.Id).ToList(); return(View(devassgnedtik)); } else { var submittertik = (from tik in ticket where tik.CreatedBy == ap.Email select tik).OrderBy(x => x.Id).ToList(); return(View(submittertik)); } } }