public JsonResult Create(CarePlanViewModel model) { if (model.Completed == true) { Validate(model); } var carePlan = new API.Models.CarePlan { CarePlanId = model.CarePlanId, Title = model.Title, PatientName = model.PatientName, UserName = model.UserName, ActualStartDate = model.ActualStartDate, TargetDate = model.TargetDate, Reason = model.Reason, Action = model.Action, Completed = model.Completed, EndDate = model.EndDate, OutCome = model.OutCome }; if (ModelState.IsValid) { Db.CarePlan.Add(carePlan); Db.SaveChanges(); } return(Json(new { Success = true })); }
private void Validate(CarePlanViewModel model) { if (model.EndDate <= model.ActualStartDate) { ModelState.AddModelError("EndDate", $@"End Date error: Cannot before start date"); } }
public ActionResult GetCarePlan(int id) { CarePlanViewModel model; var carePlan = Db.CarePlan.FirstOrDefault(x => x.CarePlanId == id); model = new CarePlanViewModel(carePlan); return(View("CreateCarePlan", model)); }