public ActionResult Add(LogsAddViewModel model) { if (!ModelState.IsValid) { var newModel = new LogsAddViewModel { Goals = LogsUtility.GetGoalDropdown(), GoalLog = model.GoalLog }; return(View("Add", newModel)); } var log = new GoalLog { Date = model.GoalLog.Date, WasCompleted = model.GoalLog.WasCompleted, GoalId = model.GoalId }; _context.GoalLogs.Add(log); _context.SaveChanges(); return(RedirectToAction("Index", "Goal")); }
private IGoalLog GoalLogViewModelToInterface(LogAddGoalLogViewModel viewModel) { var goalLog = new GoalLog { DateTime = DateTime.Now, User = AuthController.GetAuthUser(User), Calories = viewModel.Calories }; return(goalLog); }
public ActionResult Edit(int id) { GoalLog log = _context.GoalLogs.SingleOrDefault(item => item.Id == id); if (log == null) { return(RedirectToAction("Index", "Logs")); } var model = new LogsEditViewModel { Goals = LogsUtility.GetGoalDropdown(), GoalLog = log }; return(View(model)); }