Ejemplo n.º 1
0
        public ActionResult ShowOrder()
        {
            Dictionary<int, int> currentOrder = new Dictionary<int, int>();
            OrderModel orderModel = new OrderModel();
            List<string> matratNamn = new List<string>();
            List<int> matratCount = new List<int>();
            List<int> prices = new List<int>();

            if (Session["Order"] != null)
            {
                currentOrder = (Dictionary<int, int>)Session["Order"];
            }

            if (currentOrder.Count > 0)
            {
                foreach (KeyValuePair<int, int> entry in currentOrder)
                {
                    using (PizzaConnection db = new PizzaConnection())
                    {
                        string name = db.Matratts.SingleOrDefault(p => p.MatrattID == entry.Key).MatrattNamn;
                        int price = db.Matratts.SingleOrDefault(p => p.MatrattID == entry.Key).Pris;
                        matratNamn.Add(name);
                        prices.Add(price);
                    }
                    matratCount.Add(entry.Value);
                }
                orderModel.IdsOccurances = currentOrder;
                orderModel.Names = matratNamn;
                orderModel.Occurances = matratCount;
                orderModel.Prices = prices;
                orderModel.isEmpty = false;
            }
            else
            {
                orderModel.isEmpty = true;
            }

            return View(orderModel);
        }
Ejemplo n.º 2
0
        public ActionResult PlaceOrder(OrderModel model)
        {
            int orderId;
            int totalValue = model.TotalValue;
            int customerId = model.KundId;
            //Dictionary<int, int> itemsInOrder = model.IdsOccurances; CZEMU NIE DZIALA ODKRYC LUB SPYTAC
            Dictionary<int, int> itemsInOrder = (Dictionary<int, int>) Session["Order"];

            Bestallning bestallning = new Bestallning();
            bestallning.KundID = customerId;
            bestallning.BestallningDatum = DateTime.Now;
            bestallning.Totalbelopp = totalValue;
            bestallning.Levererad = false;
            using (PizzaConnection db = new PizzaConnection())
            {
                db.Bestallnings.Add(bestallning);
                db.SaveChanges();

                orderId = bestallning.BestallningID;

                foreach (var itemAmount in itemsInOrder)
                {
                    BestallningMatratt bm = new BestallningMatratt();
                    bm.MatrattID = itemAmount.Key;
                    bm.Antal = itemAmount.Value;
                    bm.BestallningID = orderId;
                    db.BestallningMatratts.Add(bm);
                }

                db.SaveChanges();
            }
            Session["Order"] = null;
            return View(); //TODO: Wreszcie, validering, css i done!!!
        }