Example #1
0
        public ActionResult CreateProject([Bind(Include = "ID,Code,Name,Description,Status,EndDate")] Project newProject)
        {
            int collectedThingID = 0;

            if (Request != null)
            {
                Int32.TryParse(Request.Params["collectedThingID"], out collectedThingID);
            }
            //set owner
            UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db));
            ApplicationUser appUser = manager.FindById(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {
                //set owner
                newProject.User = appUser;

                //set creation date
                newProject.CreationDate = DateTime.UtcNow;

                //create project
                db.Projects.Add(newProject);
                if (collectedThingID > 0)
                {
                    //delete associated collected thing
                    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("Index") + "'"));
                    }
                    return(JavaScript("window.location = '" + Url.Action("Details", "Project", new { id = newProject.ID }) + "'"));
                }
            }

            ViewBag.NewProject = newProject;
            return(PartialView(new Workspace(appUser)));
        }
Example #2
0
        public ActionResult Create([Bind(Include = "ID,Name,Description,EndDate,Estimate,TaskID,Deadline,Status")] Action newAction) //var name cannot be action
        {
            int collectedThingID = 0;

            if (Request != null)
            {
                Int32.TryParse(Request.Params["collectedThingID"], out collectedThingID);
            }

            newAction.Task = db.GetTaskById(User, newAction.TaskID);
            if (ModelState.IsValid)
            {
                //create action
                db.Actions.Add(newAction);
                //set creation date
                newAction.CreationDate = DateTime.UtcNow;
                if (collectedThingID > 0)
                {
                    //delete associated collected thing
                    CollectedThing collectedThing = db.GetCollectedThingById(User, collectedThingID);
                    db.CollectedThings.Remove(collectedThing);
                }

                db.SaveChanges();
                return(RedirectToAction("ActionList", "Task", new { id = newAction.TaskID }));
            }

            ViewBag.TaskID = new SelectList(db.GetMyTasks(User), "ID", "Code", newAction.TaskID);
            return(View(newAction));
        }
Example #3
0
        // GET: /CollectedThing/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CollectedThing collectedthing = db.GetCollectedThingById(User, id.Value);

            if (collectedthing == null)
            {
                return(HttpNotFound());
            }
            db.CollectedThings.Remove(collectedthing);
            db.SaveChanges();
            return(RedirectToAction("Review", "Layout"));
        }
Example #4
0
        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" });
        }
Example #5
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));
        }