public ActionResult CreateLight([Bind(Include = "ID,Name")] CollectedThing collectedthing, string submitButton, string UrlReferrer) { if (ModelState.IsValid) { //set owner UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); collectedthing.User = manager.FindById(User.Identity.GetUserId()); //set creation date collectedthing.CreationDate = DateTime.UtcNow; db.CollectedThings.Add(collectedthing); db.SaveChanges(); } UrlReferrer = UrlReferrer .Replace("?collecting=1", string.Empty) .Replace("&collecting=1", string.Empty); if (submitButton == "Save") { return(Redirect(UrlReferrer)); } //"Create more" return(Redirect(UrlReferrer + (UrlReferrer.Contains("?") ? "&" : "?") + "collecting=1")); }
public void TestCreateCollectedThing() { // Arrange //dashboard (active) counts LayoutController lc = new LayoutController(); lc.TestUser = user; ReviewViewModel review = (ReviewViewModel)lc.Review().ViewData.Model; int lCollectedThingsCount = review.CollectedThings.Items.Count(); ////////////////////////////////////////// // Act collectedThing = CreateCollectedThing(); ////////////////////////////////////////// // Assert review = (ReviewViewModel)lc.Review().ViewData.Model; Assert.AreEqual <int>(review.CollectedThings.Items.Count(), lCollectedThingsCount + 1); }
public ActionResult Index(int?ct, string text) { UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); ApplicationUser user = manager.FindById(User.Identity.GetUserId()); Project newProject = new Project(); newProject.User = user; if (ct.HasValue) { CollectedThing collectedthing = db.GetCollectedThingById(User, ct.Value); if (collectedthing != null) { newProject.SetCode(collectedthing.Name); newProject.SetName(collectedthing.Name); ViewBag.collectedThingID = ct.Value; } } else if (string.IsNullOrWhiteSpace(text) == false) { newProject.SetCode(text); newProject.SetName(text); } ViewBag.NewProject = newProject; return(View("Workspace", new Workspace(user))); }
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)); }
// GET: /Task/CreateAction/5 public ActionResult CreateAction(string op, int?id, int?ct, string text) { ActionResult result = loadView(id, Operation.CreateAction); if ((result is HttpStatusCodeResult || result is HttpNotFoundResult) == false) { Action newAction = (Action)ViewBag.NewAction; newAction.TaskID = id.Value; if (ct.HasValue) { CollectedThing collectedthing = db.GetCollectedThingById(User, ct.Value); if (collectedthing != null) { newAction.SetName(collectedthing.Name); ViewBag.collectedThingID = ct.Value; } } else if (string.IsNullOrWhiteSpace(text) == false) { newAction.SetName(text); } } return(result); }
public ActionResult CreateTaskOld(int?id, int?ct, string text) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Project project = db.GetProjectById(User, id.Value); if (project == null) { return(HttpNotFound()); } Task newTask = new Task(); newTask.ProjectID = id.Value; if (ct.HasValue) { CollectedThing collectedthing = db.GetCollectedThingById(User, ct.Value); if (collectedthing != null) { newTask.SetCode(collectedthing.Name); newTask.Name = collectedthing.Name; ViewBag.collectedThingID = ct.Value; } } else if (string.IsNullOrWhiteSpace(text) == false) { newTask.SetCode(text); newTask.Name = text; } ViewBag.NewTask = newTask; return(View(project)); }
public ActionResult CreateActionOld(int?id, int?ct, string text) { if (id == null) { //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); return(Redirect(Request.GetReferrerUrlOrCurrent())); } Task task = db.GetTaskById(User, id.Value); if (task == null) { return(HttpNotFound()); } Action newAction = new Action(); newAction.TaskID = id.Value; if (ct.HasValue) { CollectedThing collectedthing = db.GetCollectedThingById(User, ct.Value); if (collectedthing != null) { newAction.SetName(collectedthing.Name); ViewBag.collectedThingID = ct.Value; } } else if (string.IsNullOrWhiteSpace(text) == false) { newAction.SetName(text); } ViewBag.NewAction = newAction; return(View(task)); }
public ActionResult Create([Bind(Include = "ID,Code,Name,Description,EndDate,ProjectID,Status,Priority")] Task task) { int collectedThingID = 0; Int32.TryParse(Request.Params["collectedThingID"], out collectedThingID); if (ModelState.IsValid) { //set creation date task.CreationDate = DateTime.UtcNow; //create task db.Tasks.Add(task); if (collectedThingID > 0) { //delete associated collected thing CollectedThing collectedThing = db.GetCollectedThingById(User, collectedThingID); db.CollectedThings.Remove(collectedThing); } db.SaveChanges(); return(RedirectToAction("TaskList", "Project", new { id = task.ProjectID })); } ViewBag.ProjectID = new SelectList(db.GetMyProjects(User), "ID", "Code", task.ProjectID); return(View(task)); }
public ActionResult DeleteConfirmed(int id, String UrlReferrer) { CollectedThing collectedthing = db.GetCollectedThingById(User, id); db.CollectedThings.Remove(collectedthing); db.SaveChanges(); return(Redirect(UrlReferrer)); }
public ActionResult Edit([Bind(Include = "ID,Name,CreationDate")] CollectedThing collectedthing) { if (ModelState.IsValid) { db.Entry(collectedthing).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = collectedthing.ID })); } return(View(collectedthing)); }
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))); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CollectedThing collectedthing = db.GetCollectedThingById(User, id.Value); if (collectedthing == null) { return(HttpNotFound()); } return(View(collectedthing)); }
// 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")); }
public ActionResult Create([Bind(Include = "ID,Name")] CollectedThing collectedthing) { if (ModelState.IsValid) { //set owner UserManager <ApplicationUser> manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(db)); collectedthing.User = manager.FindById(User.Identity.GetUserId()); //set creation date collectedthing.CreationDate = DateTime.UtcNow; db.CollectedThings.Add(collectedthing); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(collectedthing)); }
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" }); }
public CollectedThing CreateCollectedThing() { // Arrange ////////////////////////////////////////// // Act CollectedThing collectedThing = new CollectedThing() { Name = "Test Collected Thing" }; ActionResult actionResult = collectedThingController.CreateLight(collectedThing, string.Empty, string.Empty); ////////////////////////////////////////// // Assert Assert.IsNotNull(actionResult); return(collectedThing); }
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)); }