예제 #1
0
        // GET: /Action/ChangeTask/5?parent=1
        public ActionResult ChangeTask(int?id, int?parent)
        {
            if (id == null || parent.HasValue == false)
            {
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                return(Redirect(Request.GetReferrerUrlOrCurrent()));
            }
            ;
            Action action = db.GetActionById(User, id.Value);

            if (action == null)
            {
                return(HttpNotFound());
            }
            Task task = db.GetTaskById(User, parent.Value);

            if (task == null)
            {
                return(HttpNotFound());
            }
            if (task.Status != Status.Active)
            {
                //check if contains the selected action
                if (action.ContainsSelectedAction)
                {
                    //not working nor pending confirmation
                    if (action.Owner.WorkingPanelAvailable)
                    {
                        //clear selected action
                        action.Owner.ActionID        = null;
                        db.Entry(action.Owner).State = EntityState.Modified;
                    }
                    else
                    {
                        //cannot perform change
                        TempData["UpdateError"] = Settings.MSG_UNSUCCESSFUL_BECAUSE_WORKING;
                        return(Redirect(Request.GetReferrerUrlOrCurrent()));
                    }
                }
            }
            action.TaskID          = parent.Value;
            db.Entry(action).State = EntityState.Modified;
            db.SaveChanges();

            TempData["UpdateInfo"] = Settings.MSG_SUCCESSFUL_UPDATE;
            return(RedirectToAction("Details", new { id = id.Value }));
        }
예제 #2
0
        public ActionResult CreateAction([Bind(Include = "ID,Name,Description,EndDate,Estimate,TaskID,Deadline,Status,IsPersistent,Priority")] Action newAction) //var name cannot be action
        {
            if (ModelState.IsValid)
            {
                db.Actions.Add(newAction);
                //set creation date
                newAction.CreationDate = DateTime.UtcNow;

                //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("CreateAction", new { id = newAction.TaskID }) + "'"));
                    }
                    return(JavaScript("window.location = '" + Url.Action("Details", "Action", new { id = newAction.ID }) + "'"));
                }
            }
            //load task for the view
            newAction.Task    = db.GetTaskById(User, newAction.TaskID);
            ViewBag.NewAction = newAction;
            return(PartialView(newAction.Task));
        }