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 PartialViewResult Create() { var createGoal = new GoalFormModel(); var metrics = metricService.GetMetrics(); var goalstatus = goalStatusService.GetGoalStatus(); createGoal.Metrics = metrics.ToSelectListItems(-1); return PartialView(createGoal); }
public void Create_Goal() { GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService); // Act Mapper.CreateMap<GoalFormModel, Goal>(); GoalFormModel goal = new GoalFormModel() { GoalName = "t", StartDate = DateTime.Now, EndDate = DateTime.Now.AddDays(1), Desc = "t", UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", }; var result = (RedirectToRouteResult)controller.Create(goal); Assert.AreEqual("Index", result.RouteValues["action"]); }
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 void Create_Goal_Get_ReturnsView() { IEnumerable<Focus> fakeFocus = new List<Focus> { new Focus { FocusId = 1, FocusName="Test1",GroupId = 1}, new Focus { FocusId = 2, FocusName="Test2",GroupId = 1}, new Focus { FocusId = 3, FocusName="Test3",GroupId = 1} }.AsEnumerable(); focusRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<Focus, bool>>>())).Returns(fakeFocus); IEnumerable<Metric> fakeMatrices = new List<Metric> { new Metric{MetricId=1, Type="Test1"}, new Metric{MetricId=2,Type="Test2"}, new Metric{MetricId=3,Type="Test3"} }.AsEnumerable(); metricRepository.Setup(x => x.GetAll()).Returns(fakeMatrices); GoalFormModel goal = new GoalFormModel(); GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService); PartialViewResult result = controller.Create() as PartialViewResult; Assert.IsNotNull(result, "View Result is null"); Assert.IsInstanceOf(typeof(GoalFormModel), result.ViewData.Model, "Wrong View Model"); }