public async Task UpdateAsync(UpdateDietaryProfile model, IValidator <UpdateDietaryProfile> validator) { ValidateAndThrow(model, validator); var dietaryProfile = _mapper.Map <DietaryProfile>(model); // Derive height if (model.HeightFeet.HasValue && !model.HeightCm.HasValue) { short heightInchesValue = model.HeightInches ?? 0; dietaryProfile.Height = _conversion.FeetAndInchesToCentimeters(model.HeightFeet.Value, heightInchesValue); } else { dietaryProfile.Height = (float)Math.Floor((double)model.HeightCm.Value); } // Derive weight if (model.WeightLbs.HasValue && !model.WeightKg.HasValue) { dietaryProfile.Weight = _conversion.PoundsToKilos(model.WeightLbs.Value); } else { dietaryProfile.Weight = (float)Math.Round(model.WeightKg.Value, 1); } await _dietaryProfilesRepository.UpdateAsync(dietaryProfile); }
public async Task <IActionResult> Update([FromBody] UpdateDietaryProfile dto) { if (dto == null) { return(BadRequest()); } try { dto.UserId = IdentityHelper.GetUserId(User); } catch (UnauthorizedAccessException) { return(Unauthorized()); } await _dietaryProfileService.UpdateAsync(dto, _updateDietaryProfileValidator); return(NoContent()); }