public async Task <IActionResult> Add(AddPlanViewModel planModel) { var user = await _userManager.GetUserAsync(User); ViewBag.userName = user.Name; if (ModelState.IsValid) { try { var plan = new Plan { Created = DateTime.Now, User = user, Name = planModel.PlanName, Description = planModel.Description, }; _planService.Create(plan); return(RedirectToAction("List")); } catch { return(View(planModel)); } } else { return(View(planModel)); } }
public async Task <IActionResult> Add(AddPlanViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.GetUserAsync(User); if (user == null) { ModelState.AddModelError("", "Błąd dodawania planu"); return(View(model)); } var plan = new Plan() { Name = model.Name, Description = model.Description, Created = DateTime.Now, User = user }; var result = await _planService.CreateAsync(plan); if (result == false) { ModelState.AddModelError("", "Błąd dodawania planu"); return(View(model)); } return(RedirectToAction("List", "Plan")); }
public ActionResult AddPlan(int patientID) { AddPlanViewModel apvm = new AddPlanViewModel(patientID) { }; return(View(apvm)); }
public ActionResult AddPlan([Bind(Include = "PatientID, PhysicistID, RadOncID, NeuroID, PlanTypeID, PlanName, IsInPlanning, HasPreApproval")] AddPlanViewModel apvm) { //send to database DAL dal = new DAL(); bool success = dal.AddNewPlan(apvm.PatientID, apvm.IsInPlanning, apvm.HasPreApproval, apvm.PhysicistID, apvm.RadOncID, apvm.NeuroID, apvm.PlanName, apvm.PlanTypeID); ViewBag.Success = success ? "Plan has been saved to the database." : "There was an error saving to the database."; return(View(new AddPlanViewModel(apvm.PatientID))); }
public ActionResult AddPlan(string name, int?id) //list of meal IDs, foreach { AddPlanViewModel addPlan = new AddPlanViewModel(); List <Meal> mealsOnDay = new List <Meal>(); if (id > 0) { addPlan.Plan = _dal.GetPlanByPlanId((int)id); addPlan.Meals = _dal.GetMealsByPlanId((int)id); for (int i = 0; i <= 6; i++) { mealsOnDay = _dal.GetMealsOnDay((int)id, i); addPlan.MealsOnDay.Add(mealsOnDay); } } if (Session[UserKey] != null) { addPlan.AllMeals = _dal.GetAllMealsByUserId((int)Session[UserKey]); } bool doesExist = _dal.PlanExists(name); if (IsAuthenticated) { if (!doesExist) { Plan plan = new Plan(); plan.PlanName = name; plan.UserId = (int)Session[UserKey]; plan.Id = _dal.AddPlan(plan); addPlan.Plan = plan; } _nextView = "AddMealPlan"; } return(GetAuthenticatedView(_nextView, addPlan)); }