public DTO.Ingredient Execute(Ingredient ingredient) { var ingredientDto = TypeAdapter.Adapt <DTO.Ingredient>(ingredient); var ingredientGroup = _ingredientGroupRepository.FindBy(ingredient.IngredientGroupId); ingredientDto.IngredientGroup = TypeAdapter.Adapt <DTO.IngredientGroup>(ingredientGroup); return(ingredientDto); }
public SuccessResponse Update(IngredientGroupRequest request) { try { var currentIngredientGroup = _ingredientGroupRepository.FindBy(request.Id); currentIngredientGroup.ThrowExceptionIfRecordIsNull(); var ingredientGroupToCopy = TypeAdapter.Adapt <IngredientGroup>(request); TypeAdapter.Adapt(ingredientGroupToCopy, currentIngredientGroup); _ingredientGroupValidator.ValidateAndThrowException(currentIngredientGroup, "Base"); _ingredientGroupRepository.Update(currentIngredientGroup); return(new SuccessResponse { IsSuccess = true }); } catch (DataAccessException) { throw new ApplicationException(); } }
public ValidationFailure ReferencesValidate(Ingredient ingredient, ValidationContext <Ingredient> context) { var ingredientGroup = _ingredientGroupRepository.FindBy(ingredient.IngredientGroupId); if (ingredientGroup.IsNull() || ingredientGroup.Status.Equals(GlobalConstants.StatusDeactivated)) { return(new ValidationFailure("Ingredient", "El grupo esta desactivado o no existe")); } var unitType = new UnitType().ConvertToCollection().FirstOrDefault(unitTp => unitTp.Value == ingredient.Unit); if (unitType.IsNull()) { return(new ValidationFailure("Menu", "El tipo de unidad no existe")); } return(null); }