public ActionResult Create(Goal goal) { if (ModelState.IsValid) { int checkYear = 1900; int inYear = goal.DueDate.Year; if (inYear < checkYear) { ViewBag.DateValidation = "Please enter a date between 1900 and now."; return View(); } UserManager manager = new UserManager(db); goal.User = manager.findByUserName(User.Identity.Name); db.Goals.Add(goal); db.SaveChanges(); return RedirectToAction("Edit", new { id = goal.ID }); } return View(goal); }
public GoalView(Goal g) { this.GoalObj = g; CategoriesList = new Dictionary<string, bool>(); // we have an existing goal. get the categories already assigned to it. List<Category> currCats = g.Categories.ToList(); foreach (Category cat in new CTContext().Categories.ToList()) { CategoriesList[cat.Name] = (currCats.Contains(cat)); } }
public ActionResult Edit(Goal goal) { //Goal oldGoal = db.Goals.Find(goal.ID); if (ModelState.IsValid) { int checkYear = 1900; int inYear = goal.DueDate.Year; if (inYear < checkYear) { ViewBag.DateValidation = "Please enter a date between 1900 and now."; return View(goal); } db.Entry(goal).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(goal); }