Ejemplo n.º 1
0
        public void AddPizzaToOrder(PizzaOrderViewModel pizzaOrderViewModel)
        {
            //get the order
            Order order = _orderRepository.GetById(pizzaOrderViewModel.OrderId);

            if (order == null)
            {
                //log
                throw new Exception($"Order with id {pizzaOrderViewModel.OrderId} was not found!");
            }
            //get the pizza
            Pizza pizza = _pizzaRepository.GetById(pizzaOrderViewModel.PizzaId);

            if (pizza == null)
            {
                //log
                throw new Exception($"Pizza with id {pizzaOrderViewModel.PizzaId} was not found!");
            }
            order.PizzaOrders.Add(new PizzaOrder
            {
                Pizza     = pizza,
                PizzaSize = pizzaOrderViewModel.PizzaSize,
                Price     = pizzaOrderViewModel.Price
            });
            _orderRepository.Update(order);
        }
Ejemplo n.º 2
0
        public void AddPizzaToOrder(PizzaOrderViewModel pizzaOrderViewModel)
        {
            Pizza pizzaDb = _pizzaRepository.GetById(pizzaOrderViewModel.PizzaId);

            if (pizzaDb == null)
            {
                //log
                throw new Exception($"Pizza with id {pizzaOrderViewModel.PizzaId} was not found");
            }
            Order orderDb = _orderRepository.GetById(pizzaOrderViewModel.OrderId);

            if (orderDb == null)
            {
                //log
                throw new Exception($"Order with id {pizzaOrderViewModel.OrderId} was not found");
            }

            orderDb.PizzaOrders.Add(new PizzaOrder
            {
                Pizza     = pizzaDb,
                PizzaId   = pizzaDb.Id,
                PizzaSize = pizzaOrderViewModel.PizzaSize
            });
            _orderRepository.Update(orderDb);
        }
Ejemplo n.º 3
0
        private Pizza loadPizza(IResolveFieldContext <object> context, IPizzaRepository pizzaRepository)
        {
            int id           = (int)context.Arguments["id"];
            var loadToppings = context.SubFields.FirstOrDefault(kv => kv.Key == "toppings").Key != null;

            return(pizzaRepository.GetById(id, loadToppings));
        }
        public PizzaViewModel GetPizzaById(int id)
        {
            Pizza pizza = _pizzaRepository.GetById(id);

            if (pizza == null)
            {
                throw new Exception($"Pizza with Id: {id} does not exist");
            }
            return(pizza.ToPizzaViewModel());
        }
Ejemplo n.º 5
0
        public PizzaDTO GetByLanguage(ObjectId id, string language)
        {
            language = language ?? CultureInfo.CurrentCulture.Name;
            var translator = _builder
                             .AddLanguage(language)
                             .AddLanguage("en")
                             .AddLanguage("pl")
                             .Build();
            var langPizza = translator.GetTranslation(_pizzaRepository.GetById(id));

            return(new PizzaDTO
            {
                Name = langPizza?.Contents.FirstOrDefault()?.Name,
                Description = langPizza?.Contents.FirstOrDefault()?.Description,
                ImageUrl = langPizza?.ImageUrl,
                Price = langPizza?.Price ?? 0
            });
        }
Ejemplo n.º 6
0
        public ResultEntity <Pizza> Delete(int id)
        {
            var pizza = new Pizza();

            try
            {
                pizza = _repository.GetById(id);

                if (pizza == null)
                {
                    return(ResultEntity <Pizza> .Fail(pizza, $"Pizza não existe"));
                }

                _repository.Delete(pizza);

                return(ResultEntity <Pizza> .Success(pizza));
            }
            catch (Exception e)
            {
                return(ResultEntity <Pizza> .Fail(pizza, $"Ocorreu algum erro na exclusão da pizza - {e.Message}"));
            }
        }
        public IActionResult Details(int id)
        {
            var pizza = pizzaRepository.GetById(id);

            return(View(pizza));
        }
Ejemplo n.º 8
0
        public PizzaModel GetById(int id)
        {
            var response = _repository.GetById(id);

            return(response.ProjectedAs <PizzaModel>());
        }