public IActionResult UpdateUserTargets(int id, [FromBody] UserTargets targets) { targets.UserId = id; UpdateUserTargetsResponse response = _userService.UpdateUserTargets(targets); if (!response.ResponseStatus.HasError()) { return(Ok()); } return(StatusCode(response.ResponseStatus.Status, response.ResponseStatus.Message)); }
public void UpdateUserTargets(UserTargets targets) { try { int userId = targets.UserId; double goalWeight = targets.GoalWeight; string weightGoalTimeline = targets.WeightGoalTimeline; string sql = $"call update_user_targets({userId},{goalWeight},'{weightGoalTimeline}')"; using (var connection = _dbConnectionFactory.CreateConnection(ConfigurationsHelper.ConnectionString)) { connection.Open(); connection.Execute(sql); } } catch (Exception e) { throw e; } }
public UpdateUserTargetsResponse UpdateUserTargets(UserTargets targets) { UpdateUserTargetsResponse response = new UpdateUserTargetsResponse(); //TODO: Handle with non existent user id try { _userRepository.UpdateUserTargets(targets); response.ResponseStatus.SetOk(); } catch (Exception e) { _logger.LogError(e.ToString()); response.ResponseStatus.SetError(ResponseStatusCode.INTERNAL_SERVER_ERROR, e.ToString()); } return(response); }