public async Task <IActionResult> AddEdit(GoalViewModel vm) { if (ModelState.IsValid) { var user = _userManager.GetUserId(HttpContext.User); if (vm.GoalId > 0) { var goal = _goalRepository.GetById(vm.GoalId); if (goal == null) { return(RedirectToAction("Index")); } vm.ModifiedBy = user; vm.CreatedBy = goal.CreatedBy; vm.DateCreated = goal.DateCreated; goal = Mapper.Map <GoalViewModel, Goal>(vm); await _goalRepository.UpdateAsync(goal); } else { vm.CreatedBy = user; vm.ModifiedBy = user; var goal = Mapper.Map <GoalViewModel, Goal>(vm); await _goalRepository.CreateAsync(goal); } return(RedirectToAction("Index")); } return(View("~/Views/Shared/_AddEditGoal.cshtml", vm)); }