//IT was not possible to build a generic update for classes with relationships. //I use the new keyword because I didn't give up to do it generic yet, so is not intended to override the method. public new void Update(string data) { if (string.IsNullOrEmpty(data)) { return; } FoodStage foodStageData = JsonConvert.DeserializeObject <FoodStage>(data); FoodStage foodStage = _service.GetById(foodStageData.FoodStageId); foodStage.Initial = foodStageData.Initial; foodStage.Final = foodStageData.Final; foodStage.Complement = foodStageData.Complement; foodStage.RefuseDescription = foodStageData.RefuseDescription; foodStage.RefusePercentage = foodStageData.RefusePercentage; foodStage.ProteinCalorieFactor = foodStageData.ProteinCalorieFactor; foodStage.FatCalorieFactor = foodStageData.FatCalorieFactor; foodStage.CarbCalorieFactor = foodStageData.CarbCalorieFactor; _service.Update(foodStage); _service.Complete(); }
public void RemoveRelations(string data) { if (string.IsNullOrEmpty(data)) { return; } Food foodData = JsonConvert.DeserializeObject <Food>(data); Food food = _service.GetById(foodData.FoodId); if (foodData.Benefits.Any()) { Benefit benefit = _benefitService.GetById(foodData.Benefits.First().BenefitId); food.Benefits.Remove(benefit); _service.Update(food); _service.Complete(); } else if (foodData.FoodStages.Any()) { FoodStage foodStage = _foodStageService.GetById(foodData.FoodStages.First().FoodStageId); _foodStageService.Remove(foodStage); _foodStageService.Complete(); } }