Esempio n. 1
0
        public Pizza Add(DtoPizza command)
        {
            var entity = Pizza.CreatePizza(command);

            if (!entity.IsValid())
            {
                throw new Exception("Error: Campos no validos.");
            }

            var pizza = _context.Pizzas.Add(entity);

            _context.SaveChanges();

            return(pizza);
        }
Esempio n. 2
0
        public Pizza Add(DtoPizza data)
        {
            var ingredientes = GetIngredients(data.Ingredients);

            var pizza = Pizza.Create(data, ingredientes);

            if (!pizza.IsValid())
            {
                throw new CustomException(pizza.Errors);
            }
            var response = _pizzaContext.Pizzas.Add(pizza);

            _pizzaContext.SaveChanges();
            _pizzaContext.Dispose();
            return(response);
        }