Exemplo n.º 1
0
        public PizzaRepository UpdatePizza(int pizzaId, PizzaRepository pizzaBody)
        {
            PizzaRepository pizza = new PizzaRepository();

            try
            {
                var pizzaProps = typeof(PizzaRepository).GetProperties();

                using (var db = new PizzaDbContext())
                {
                    foreach (var pizzaProp in pizzaProps)
                    {
                        pizza = db.Pizza.Where(e => e.pizzaId == pizzaId).FirstOrDefault();
                        string pizzaPropToString = pizzaProp.Name;
                        bool   isPrimaryId       = Regex.IsMatch(pizzaPropToString, @"\w+Id$");
                        var    pizzaProperty     = pizzaBody.GetType().GetProperty(pizzaPropToString);
                        if (!isPrimaryId)
                        {
                            if (pizzaProperty.GetValue(pizzaBody) != null)
                            {
                                var getPizzaBodyPropValue = pizzaProp.GetValue(pizzaBody);
                                pizza.GetType().GetProperty(pizzaPropToString).SetValue(pizza, pizzaProperty.GetValue(pizzaBody));
                                pizzaProperty.SetValue(pizza, pizzaProp.GetValue(pizzaBody));
                            }
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(pizza);
        }
Exemplo n.º 2
0
        // TODO : Methods for the order and orderItem table
        public OrderRepository GetNewOrderToInsert()
        {
            PizzaRepository            pizzaList           = new PizzaRepository();
            int                        pizzaIdToOrderFirst = pizzaList.GetAllPizzas().Select(pizz => pizz.pizzaId).FirstOrDefault();
            int                        pizzaIdToOrderLast  = pizzaList.GetAllPizzas().Select(pizz => pizz.pizzaId).LastOrDefault();
            List <OrderItemRepository> newOrderItems       = new List <OrderItemRepository>()
            {
                new OrderItemRepository()
                {
                    pizzaItem = pizzaIdToOrderFirst
                },
                new OrderItemRepository()
                {
                    pizzaItem = pizzaIdToOrderLast
                }
            };

            OrderRepository newOrder = new OrderRepository()
            {
                customerName  = "Kinder",
                customerPhone = "0000000000",
                orderItems    = newOrderItems
            };

            return(newOrder);
        }
Exemplo n.º 3
0
 // TODO : Implement all proper exection handling and response message
 public int CreateOrder(PizzaRepository pizzaBody)
 {
     try
     {
         using (var db = new PizzaDbContext())
         {
             db.Pizza.Add(pizzaBody);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         return(0);
     }
     return(pizzaBody.pizzaId);
 }
Exemplo n.º 4
0
        public PizzaRepository GetPizza(int pizzaId)
        {
            PizzaRepository getPizza = new PizzaRepository();

            try
            {
                using (var db = new PizzaDbContext())
                {
                    getPizza = db.Pizza.Where(pizz => pizz.pizzaId == pizzaId).First();
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(getPizza);
        }
Exemplo n.º 5
0
        public PizzaRepository UpdatePizzaToppingList(int pizzaid)
        {
            PizzaRepository pizza = new PizzaRepository();

            try
            {
                using (var db = new PizzaDbContext())
                {
                    pizza = db.Pizza.Where(element => element.pizzaId == pizzaid).FirstOrDefault();
                    var pizzaToppings = new List <PizzaToppingsRepository>();
                    pizzaToppings      = db.PizzaToppings.Where(e => e.pizzaId == pizzaid).ToList();
                    pizza.toppingsList = pizzaToppings;
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(pizza);
        }