コード例 #1
0
        public int CreateGoal(CreateGoalsCommand cmd, ApplicationUser appUser)
        {
            var goals = cmd.ToGoals(appUser);

            _context.Add(goals);
            _context.SaveChanges();
            return(goals.GoalId);
        }
コード例 #2
0
        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));
        }