public FoodsResponse Update(FoodsModel editedFood, string userIdOfEditor) { FoodsModel uneditedFood = _unitOfWork.Foods.GetById(editedFood.Id); ValidateFoodForUpdate(uneditedFood); Update(editedFood, uneditedFood); SaveUserEditedFood(userIdOfEditor, false, true); return(response); }
private void CreateFood(FoodsModel food, string userIdOfEditor) { if (response.IsValid) { food.Id = GetId(); response.Foods.Add(_unitOfWork.Foods.Add(food)); SaveChanges(); SaveUserEditedFood(userIdOfEditor, true, false); } }
private void Update(FoodsModel editedFood, FoodsModel uneditedFood) { if (response.IsValid) { SetUpFood(editedFood, uneditedFood); _unitOfWork.Foods.update(response.Foods[0]); SaveChanges(); response.StatusCode = 201; } }
private void SetUpFood(FoodsModel editedFood, FoodsModel uneditedFood) { uneditedFood.Name = editedFood.Name; uneditedFood.ReferenceMassInGrams = editedFood.ReferenceMassInGrams; uneditedFood.ReferenceVolumeInMililiters = editedFood.ReferenceVolumeInMililiters; uneditedFood.Macronutrients = editedFood.Macronutrients; uneditedFood.Minerals = editedFood.Minerals; uneditedFood.FattyAcidsAndCholesterol = editedFood.FattyAcidsAndCholesterol; uneditedFood.Vitamins = editedFood.Vitamins; response.Foods.Add(uneditedFood); }
private void ValidateFoodForUpdate(FoodsModel uneditedFood) { if (uneditedFood == null) { response.IsValid = false; response.StatusCode = 400; } else { response.IsValid = true; } }
private void ValidateFoodForCreate(FoodsModel food) { if (AreAllReferenceUnitsNull(food) || DoesUserExist(food.Name)) { response.IsValid = false; response.StatusCode = 400; } else { response.IsValid = true; } // return ProcessValidationForCreate(validation); }
private void DeleteResult(FoodsModel food) { if (food != null) { Delete(food); response.IsValid = true; response.StatusCode = 200; } else { response.IsValid = false; response.StatusCode = 400; } }
private bool AreAllReferenceUnitsNull(FoodsModel food) { return(MeasuresValidator.CheckIfTheyAreNull(food.ReferenceMassInGrams, food.ReferenceVolumeInMililiters, food.ReferenceUnits)); }
public FoodsResponse Create(FoodsModel food, string userIdOfCreator) { ValidateFoodForCreate(food); CreateFood(food, userIdOfCreator); return(response); }
private void SetResponse(FoodsModel food) { response.Foods.Add(food); }
private void Delete(FoodsModel food) { _unitOfWork.Foods.Delete(food); SaveChanges(); }