public ActionResult Finish(int Id) { int userId = int.Parse(User.Identity.GetProjectUserId()); var project = new ProjectUserManager().GetProject(Id); var manager = new TaskManager(); var tasks = new TaskManager().GetTasksForProject(Id); if (tasks.Count == 0 || tasks.All(t => t.State == manager.GetDeletedStateId() || t.State == manager.GetDoneStateId())) { new ProjectUserManager().FinishProject(Id); } else { TempData["errorMessage"] = "Can't finish project, there are still tasks in progress!"; } return Redirect(Request.UrlReferrer.ToString()); }