Beispiel #1
0
        public async Task <bool> CreateToppingAsync(Topping topping)
        {
            try
            {
                var search = await _pizzaReservationContext.tblToppings.FirstOrDefaultAsync(t => t.Name == topping.Name);

                if (search == null)
                {
                    topping.ToppingId = Guid.NewGuid();
                    await _pizzaReservationContext.tblToppings.AddAsync(topping);

                    await _pizzaReservationContext.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw ex;
            }
        }
Beispiel #2
0
        public async Task <bool> CreateSizeAsync(Size size)
        {
            try
            {
                var search = await _pizzaReservationContext.tblSizes.FirstOrDefaultAsync(s => s.Name == size.Name);

                if (search == null)
                {
                    size.SizeId = Guid.NewGuid();
                    await _pizzaReservationContext.tblSizes.AddAsync(size);

                    await _pizzaReservationContext.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                throw ex;
            }
        }
Beispiel #3
0
        public async Task <bool> CreatePizzaAsync(Pizza pizza, string[] toppings, string[] sizes)
        {
            try
            {
                var piz = await _pizzaReservation.tblPizzas.Include(p => p.PizzaSizes).Include(p => p.PizzaToppings).FirstOrDefaultAsync(p => p.Name == pizza.Name);

                if (piz == null)
                {
                    if (pizza.PizzaId == Guid.Empty)
                    {
                        pizza.PizzaId = Guid.NewGuid();
                    }

                    if (sizes != null & toppings != null)
                    {
                        foreach (var s in sizes)
                        {
                            _pizzaReservation.tblPizzaSizes.Add(new PizzaSize {
                                PizzaId = pizza.PizzaId, SizeId = Guid.Parse(s)
                            });
                        }
                        foreach (var t in toppings)
                        {
                            _pizzaReservation.tblPizzaToppings.Add(new PizzaTopping {
                                PizzaId = pizza.PizzaId, ToppingId = Guid.Parse(t)
                            });
                        }
                    }

                    await _pizzaReservation.tblPizzas.AddAsync(pizza);

                    await _pizzaReservation.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(false);
            }
        }
Beispiel #4
0
        } //Grootte per pizza uit een order

        #endregion

        #region Create (POST)
        public async Task <bool> CreateOrderAsync(Order order, string[] pizzas)
        {
            try
            {
                var search = await _pizzaReservation.tblOrders.FirstOrDefaultAsync(o => o.Name == order.Name);

                if (search == null)
                {
                    if (order.OrderId == Guid.Empty)
                    {
                        order.OrderId = Guid.NewGuid();
                        //foreach (var po in order.PizzaOrders) po.OrderId = order.OrderId;
                    }

                    if (pizzas != null)
                    {
                        foreach (var p in pizzas)
                        {
                            _pizzaReservation.tblPizzaOrders.Add(new PizzaOrder {
                                OrderId = order.OrderId, PizzaId = Guid.Parse(p)
                            });
                        }
                    }
                    await _pizzaReservation.tblOrders.AddAsync(order);

                    await _pizzaReservation.SaveChangesAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(false);

                throw ex;
            }
        }