// GET: /Task/ChangeProject/5?parent=1 public ActionResult ChangeProject(int?id, int?parent) { if (id == null || parent.HasValue == false) { //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); return(Redirect(Request.GetReferrerUrlOrCurrent())); } Task task = db.GetTaskById(User, id.Value); if (task == null) { return(HttpNotFound()); } Project project = db.GetProjectById(User, parent.Value); if (project == null) { return(HttpNotFound()); } if (project.Status != Status.Active) { //check if contains the selected action if (task.ContainsSelectedAction) { //not working nor pending confirmation if (task.Owner.WorkingPanelAvailable) { //clear selected action task.Owner.ActionID = null; db.Entry(task.Owner).State = EntityState.Modified; } else { //cannot perform change TempData["UpdateError"] = Settings.MSG_UNSUCCESSFUL_BECAUSE_WORKING; return(Redirect(Request.GetReferrerUrlOrCurrent())); } } } task.ProjectID = parent.Value; db.Entry(task).State = EntityState.Modified; db.SaveChanges(); TempData["UpdateInfo"] = Settings.MSG_SUCCESSFUL_UPDATE; return(RedirectToAction("Details", new { id = id.Value })); }
public ActionResult CreateTask([Bind(Include = "ID,Code,Name,Description,EndDate,ProjectID,Status,Priority")] Task newTask) { if (ModelState.IsValid) { //set creation date newTask.CreationDate = DateTime.UtcNow; db.Tasks.Add(newTask); //delete associated collected thing int collectedThingID = 0; if (Request != null) { Int32.TryParse(Request.Params["collectedThingID"], out collectedThingID); if (collectedThingID > 0) { CollectedThing collectedThing = db.GetCollectedThingById(User, collectedThingID); if (collectedThing != null) { db.CollectedThings.Remove(collectedThing); } } } db.SaveChanges(); TempData["UpdateInfo"] = Settings.MSG_SUCCESSFUL_CREATE; if (Request != null && Url != null) //avoid null reference exceptions when testing { string button = Request.Form["submitButton"]; if (button == "1") { return(JavaScript("window.location = '" + Url.Action("CreateTask", new { id = newTask.ProjectID }) + "'")); } return(JavaScript("window.location = '" + Url.Action("Details", "Task", new { id = newTask.ID }) + "'")); } } //load project for the view newTask.Project = db.GetProjectById(User, newTask.ProjectID); ViewBag.NewTask = newTask; return(PartialView(newTask.Project)); //return RedirectToAction("Details", new { id = newTask.ProjectID, op = "create" }); }