public int CreateGoal(CreateGoalsCommand cmd, ApplicationUser appUser) { var goals = cmd.ToGoals(appUser); _context.Add(goals); _context.SaveChanges(); return(goals.GoalId); }
public async Task <IActionResult> Create(CreateGoalsCommand command) { try { if (ModelState.IsValid) { var appUser = await _userService.GetUserAsync(User); var id = _service.CreateGoal(command, appUser); return(RedirectToAction(nameof(Index))); } } catch (Exception) { ModelState.AddModelError( string.Empty, "An error occured saving the goal" ); } return(View(command)); }