public ActionResult UpdateStatus(StatusJobModel statusRequest) { try { if (ModelState.IsValid) { var task = db.Tasks.Find(statusRequest.TaskId); if (task.AssigneeID == User.Identity.GetUserId() || User.IsInRole("Administrator")) { if (TryUpdateModel(task)) { task.Status = statusRequest.Status; db.SaveChanges(); TempData["message"] = "Status Updated"; } return(RedirectToAction("Show", new { id = statusRequest.TaskId })); } else { TempData["message"] = "Not authorized to update tasks for this project"; return(RedirectToAction("Index", new { id = task.Project.Id })); } } else { return(View(statusRequest)); } } catch (Exception e) { return(View(statusRequest)); } }
public ActionResult UpdateStatus(int id) { var task = db.Tasks.Find(id); var userId = User.Identity.GetUserId(); List <SelectListItem> listItems = new List <SelectListItem>(); listItems.Add(new SelectListItem { Text = "In Progress", Value = "In Progress" }); listItems.Add(new SelectListItem { Text = "In Review", Value = "In Review" }); listItems.Add(new SelectListItem { Text = "In Deployment", Value = "In Deployment" }); listItems.Add(new SelectListItem { Text = "Done", Value = "Done" }); var taskStatus = new StatusJobModel { TaskId = task.Id, Statuses = listItems }; if (User.IsInRole("Administrator") || task.AssigneeID == User.Identity.GetUserId()) { return(View(taskStatus)); } else { return(RedirectToAction("Index", "Project")); } }