Пример #1
0
        /// <summary>
        /// Creates an ingredient
        /// </summary>
        /// <param name="id"></param>
        /// <param name="createdOn"></param>
        /// <param name="ingredientName"></param>
        /// <param name="ingredientQuantity"></param>
        /// <returns></returns>
        public static Result <Ingredient> Create(int id,
                                                 DateTime createdOn,
                                                 string ingredientName,
                                                 int ingredientQuantity)
        {
            if (createdOn == default(DateTime))
            {
                return(Result.Invalid <Ingredient>(ResultErrorCodes.INGREDIENT_INVALID_CREATED_ON));
            }

            Result <IngredientNameValue>     ingredientNameOrError     = IngredientNameValue.Create(ingredientName);
            Result <IngredientQuantityValue> ingredientQuantityOrError = IngredientQuantityValue.Create(ingredientQuantity);

            Result okOrError = Result.FirstFailureOrOk(ingredientNameOrError, ingredientQuantityOrError);

            if (okOrError.IsFailure)
            {
                return(Result.FromError <Ingredient>(okOrError));
            }

            return(Result.Ok(new Ingredient
            {
                CreatedOn = createdOn,
                Id = id,
                Name = ingredientNameOrError.Value,
                Quantity = ingredientQuantityOrError.Value,
            }));
        }
Пример #2
0
        // Storage to domain

        public static Result <Ingredient> ToIngredientDomain(this Entities.Ingredient dbIngredient)
        {
            Result <IngredientNameValue>     ingredientNameOrError     = IngredientNameValue.Create(dbIngredient.Name);
            Result <IngredientQuantityValue> ingredientQuantityOrError = IngredientQuantityValue.Create(dbIngredient.Quantity);

            Result okOrError = Result.FirstFailureOrOk(ingredientNameOrError, ingredientQuantityOrError);

            if (okOrError.IsFailure)
            {
                return(Result.FromError <Ingredient>(okOrError));
            }

            return(Ingredient.Create(dbIngredient.Id,
                                     dbIngredient.CreatedOn,
                                     dbIngredient.DeletedOn,
                                     ingredientNameOrError.Value,
                                     ingredientQuantityOrError.Value,
                                     dbIngredient.PizzaFk));
        }