public ActionResult Edit(GoalFormModel editGoal) { Goal goalToEdit = Mapper.Map <GoalFormModel, Goal>(editGoal); var errors = goalService.CanAddGoal(goalToEdit, updateService); ModelState.AddModelErrors(errors); if (ModelState.IsValid) { goalService.EditGoal(goalToEdit); return(RedirectToAction("Index", new { id = editGoal.GoalId })); } else { var metrics = metricService.GetMetrics(); var goalstatus = goalStatusService.GetGoalStatus(); var goal = goalService.GetGoal(editGoal.GoalId); if (goal.Metric != null) { editGoal.Metrics = metrics.ToSelectListItems(goal.Metric.MetricId); } else { editGoal.Metrics = metrics.ToSelectListItems(-1); } return(View(editGoal)); } }
public PartialViewResult Create() { var createGoal = new GoalFormModel(); var metrics = metricService.GetMetrics(); var goalstatus = goalStatusService.GetGoalStatus(); createGoal.Metrics = metrics.ToSelectListItems(-1); return(PartialView(createGoal)); }
public ActionResult Create(GoalFormModel createGoal) { Goal goal = Mapper.Map <GoalFormModel, Goal>(createGoal); var errors = goalService.CanAddGoal(goal, updateService).ToList(); ModelState.AddModelErrors(errors); if (ModelState.IsValid) { goalService.CreateGoal(goal); return(RedirectToAction("Index", new { id = goal.GoalId })); } var metrics = metricService.GetMetrics(); var goalstatuss = goalStatusService.GetGoalStatus(); createGoal.Metrics = metrics.ToSelectListItems(-1); return(View("Create", createGoal)); }
public ActionResult Edit(int id) { var goal = goalService.GetGoal(id); GoalFormModel editGoal = Mapper.Map <Goal, GoalFormModel>(goal); if (goal == null) { return(HttpNotFound()); } var metrics = metricService.GetMetrics(); if (goal.Metric != null) { editGoal.Metrics = metrics.ToSelectListItems(goal.Metric.MetricId); } else { editGoal.Metrics = metrics.ToSelectListItems(-1); } return(View(editGoal)); }