Пример #1
0
        public static List <dom.Pizza> GetPizzasByOrderID(int orderID)
        {
            var _db          = new dat.PizzaStoreDbContext();
            var datapizzas   = _db.Pizza.Where(p => p.OrderId == orderID).ToList();
            var domPizzaList = new List <dom.Pizza>();

            foreach (var item in datapizzas)
            {
                if ((bool)item.Active)
                {
                    var dompizza = new dom.Pizza()
                    {
                        CrustId = (int)item.CrustId
                        ,
                        crustSize = (int)item.Size
                        ,
                        OrderId = (int)item.OrderId
                        ,
                        ModifiedDate = item.ModifiedDate
                        ,
                        Id = (int)item.PizzaId
                    };

                    dompizza.Toppings    = PizzaHelper.GetIngredientsByPizza(item);
                    dompizza.CrustFactor = PizzaHelper.GetFactorByCrustID(item.CrustId);
                    dompizza.price       = dompizza.CalculateCost();

                    domPizzaList.Add(dompizza);
                }
            }
            return(domPizzaList);
        }
Пример #2
0
        public static int PizzaSetter(dom.Pizza p)
        {
            var _db     = new PizzaStoreDbContext();
            var myOrder = _db.Order.Where(o => o.OrderId == p.OrderId).FirstOrDefault();
            var myCrust = _db.Crust.Where(c => c.CrustId == p.CrustId).FirstOrDefault();

            if (myCrust == null)
            {
                var DefaultCrust = _db.Crust.Where(c => c.Name == "Regular").FirstOrDefault();
                p.CrustId     = DefaultCrust.CrustId;
                p.CrustFactor = (double)DefaultCrust.CrustFactor;
            }

            if (myOrder == null)
            {
                return(0);
            }
            else
            {
                var dataPizza = new Pizza()
                {
                    OrderId      = p.OrderId,
                    ModifiedDate = DateTime.Now,
                    Price        = (decimal)p.CalculateCost(),
                    Size         = (byte)p.crustSize,
                    CrustId      = (byte)p.CrustId,
                };

                _db.Pizza.Add(dataPizza);

                var pizzaAdditions = _db.SaveChanges();

                var fullPizzaList = GetPizzas();
                var lastPizza     = fullPizzaList[fullPizzaList.Count - 1];
                var lastPizzaID   = lastPizza.Id;
                SetPizzaIngredientByIds(p, lastPizzaID);

                return(pizzaAdditions);
            }
        }