示例#1
0
        public Library.DataBase GetOrder(int id)
        {
            using var context = new StoreDBContext(_contextOptions);
            var dbOrderHitory = context.CustomerOrders.Include(c => c.ProductOrdereds)
                                .ThenInclude(c => c.Product)
                                .ThenInclude(c => c.Prices);
            var db = new Library.DataBase(new Library.Store(id));

            foreach (var orders in dbOrderHitory)
            {
                if (orders.TransactionNumber == id)
                {
                    var           x     = orders.TransactionTime.ToString();
                    Library.Order order = new Library.Order(id, orders.StoreId, orders.CustomerId, x);
                    foreach (var item in orders.ProductOrdereds)
                    {
                        var price  = item.Product.Prices.ToList();
                        var tPrice = price[0].Price1;
                        order.addItem(new Library.Product(item.ProductId, item.Product.Name, (int)item.Quantity, (double)tPrice));
                    }
                    db.AddOrder(order);
                }
            }
            return(db);
        }
        public Library.Order GetOrder(int orderId)
        {
            Order order = db.Order.Include(a => a.User).Include(b => b.Location).Include("OrderContent.Content").First(o => o.OrderId == orderId);

            Library.Location        l      = Mapper.Map(order.Location);
            Library.User            u      = Mapper.Map(order.User);
            Dictionary <Pizza, int> pizzas = new Dictionary <Pizza, int>();

            foreach (OrderContent oc in order.OrderContent)
            {
                Pizza p = new Pizza()
                {
                    Name = oc.Content.Name, Price = oc.Content.Price
                };
                pizzas[p] = oc.Amount;
            }

            Library.Order result = new Library.Order {
                OrderId   = order.OrderId,
                User      = u, Location = l,
                Contents  = pizzas,
                OrderTime = order.OrderTime
            };
            return(result);
        }
        private List <Library.Order> GetOrderHistory(List <Order> os)
        {
            List <Library.Order> result = new List <Library.Order>();

            foreach (var o in os)
            {
                Library.Location        l      = Mapper.Map(o.Location);
                Library.User            u      = Mapper.Map(o.User);
                Dictionary <Pizza, int> pizzas = new Dictionary <Pizza, int>();
                foreach (OrderContent oc in o.OrderContent)
                {
                    Pizza p = new Pizza()
                    {
                        Name = oc.Content.Name, Price = oc.Content.Price
                    };
                    pizzas[p] = oc.Amount;
                }

                Library.Order tempOrder = new Library.Order()
                {
                    OrderId = o.OrderId, User = u, Location = l, Contents = pizzas, OrderTime = o.OrderTime
                };
                result.Add(tempOrder);
            }

            return(result);
        }
        private Library.Order ConvertModel(int id, Order order)
        {
            var libOrder = new Library.Order
            {
                Id         = id,
                UserId     = order.UserId,
                LocationId = order.LocationId,
                DateTime   = order.DateTime,
                Price      = order.Price,
                PizzaId1   = order.PizzaId1,
                PizzaId2   = order.PizzaId2,
                PizzaId3   = order.PizzaId3,
                PizzaId4   = order.PizzaId4,
                PizzaId5   = order.PizzaId5,
                PizzaId6   = order.PizzaId6,
                PizzaId7   = order.PizzaId7,
                PizzaId8   = order.PizzaId8,
                PizzaId9   = order.PizzaId9,
                PizzaId10  = order.PizzaId10,
                PizzaId11  = order.PizzaId11,
                PizzaId12  = order.PizzaId12
            };

            return(libOrder);
        }
        private Order ConvertModel(Library.Order libOrder)
        {
            var webOrder = new Order
            {
                Id         = libOrder.Id,
                UserId     = libOrder.UserId,
                LocationId = libOrder.LocationId,
                DateTime   = libOrder.DateTime,
                Price      = libOrder.Price,
                PizzaId1   = libOrder.PizzaId1,
                PizzaId2   = libOrder.PizzaId2,
                PizzaId3   = libOrder.PizzaId3,
                PizzaId4   = libOrder.PizzaId4,
                PizzaId5   = libOrder.PizzaId5,
                PizzaId6   = libOrder.PizzaId6,
                PizzaId7   = libOrder.PizzaId7,
                PizzaId8   = libOrder.PizzaId8,
                PizzaId9   = libOrder.PizzaId9,
                PizzaId10  = libOrder.PizzaId10,
                PizzaId11  = libOrder.PizzaId11,
                PizzaId12  = libOrder.PizzaId12
            };

            return(webOrder);
        }
示例#6
0
 public static DataAccess.CupcakeOrder Map(Library.Order order) => new DataAccess.CupcakeOrder
 {
     OrderId    = order.Id,
     LocationId = order.OrderLocation,
     CustomerId = order.OrderCustomer,
     OrderTime  = order.OrderTime
 };
示例#7
0
 public static Orders Map(Library.Order order) => new Orders
 {
     Id         = order.Id,
     StoreId    = order.StoreId,
     CustomerId = order.CustomerId,
     TimePlaced = order.TimePlaced
 };
        /// <summary>
        /// Add order to db
        /// </summary>
        /// <param name="order"></param>
        public void AddOrder(Library.Order order)
        {
            var newEntity = Mapper.MapOrder(order);

            newEntity.OrderId = 0; // So there's no primary key conflicts
            dbcontext.Orders.Add(newEntity);
        }
示例#9
0
        // GET: Cart
        public ActionResult Index(int Id)
        {
            ViewBag.orderId = Id;
            Library.Order order = OrderRepo.GetOrderById(Id);
            IEnumerable <Lib.Inventory> libInv      = StoreRepo.GetInventory(order.StoreId);
            IEnumerable <Lib.Product>   libProducts = StoreRepo.GetInventoryProducts(libInv);

            IEnumerable <InventoryViewModel> ivm = libProducts.Select(x => new InventoryViewModel
            {
                Id           = x.Id,
                Name         = x.Name,
                Price        = (decimal)x.Price,
                Quantity     = libInv.First(i => i.ProductId == x.Id && i.StoreId == order.StoreId).Quantity,
                StoreName    = StoreRepo.GetStoreById(order.StoreId).Name,
                CustomerName = CustomerRepo.GetCustomerById(order.CustomerId).FirstName + ' ' +
                               CustomerRepo.GetCustomerById(order.CustomerId).LastName
            });

            IEnumerable <Lib.OrderItems> libOrderItems    = OrderRepo.GetOrderItems(order.Id);
            IEnumerable <Lib.Product>    libOrderProducts = OrderRepo.GetOrderProducts(libOrderItems);

            IEnumerable <CartViewModel> cvm = libOrderProducts.Select(x => new CartViewModel
            {
                Name     = x.Name,
                Price    = (decimal)x.Price,
                Quantity = libOrderItems.First(i => i.ProductId == x.Id && i.OrderId == order.Id).Quantity,
                Ivm      = ivm,
                Total    = OrderRepo.OrderTotal(order.Id)
            });

            return(View(cvm));
        }
        /// <summary>
        /// Enter a new order into db
        /// </summary>
        /// <param name="appOrder"></param>
        public void CreateOrder(Library.Order appOrder)
        {
            using var context = new P0Context(_dbContextOptions);
            //map library order to db
            var dbOrder = new Order()
            {
                Store    = context.Stores.First(s => s.Id == appOrder.TargetStore.Id),
                Customer = context.StoreCustomers.First(c => c.Id == appOrder.Orderer.Id),
                Time     = appOrder.Time
            };

            //map all items in the order to db
            foreach (Library.Product selection in appOrder.Selections)
            {
                //create a new item, Store = null unless item is part of an inventory
                var dbItem = new Item()
                {
                    Product  = context.Products.First(p => p.Name == selection.Name),
                    Quantity = selection.Quantity,
                    Store    = null,
                    //Store = context.Stores.First(s => s.Id == appOrder.TargetStore.Id),
                    Order = dbOrder
                };
                context.Add(dbItem);
            }
            context.Add(dbOrder);
            context.SaveChanges();
        }
        public ActionResult Edit(int id, Order order)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var libOrder = new Library.Order
                    {
                        Id         = order.Id,
                        LocationID = order.LocationID,
                        UserID     = order.UserID,
                        OrderTime  = order.OrderTime,
                        PizzaList  = order.PizzaList,
                        Price      = order.Price,
                        NumPizza   = order.NumPizza
                    };
                    Repo.UpdateOrder(libOrder);
                    Repo.Save();

                    return(RedirectToAction(nameof(Index)));
                }

                return(View(order));
            }
            catch
            {
                return(View(order));
            }
        }
示例#12
0
 public static CustomerOrder Map(Library.Order order) => new CustomerOrder
 {
     CustomerId = order.CustomerId,
     LocationId = order.LocationId,
     OrderTime  = order.OrderTime,
     OrderTotal = order.OrderTotal,
     OrderId    = order.OrderId
 };
示例#13
0
 public static Order Map(Library.Order otherOrder) => new Order
 {
     Id        = otherOrder.Id,
     Timestamp = otherOrder.Timestamp,
     Store     = otherOrder.Store,
     UserID    = otherOrder.UserID,
     Price     = otherOrder.Price,
     Pizzas    = Map(otherOrder.Pizzas).ToList()
 };
示例#14
0
 public ActionResult Create(Library.Order order)
 {
     if (ModelState.IsValid)
     {
         var newOrder = _storeRepo.AddOrder(order);
         return(RedirectToAction(nameof(Details), new { id = newOrder.OrderId }));
     }
     return(View("Index"));
 }
 // GET: Order/Details/5
 public ActionResult SingleOrderDetails(int orderId)
 {
     if (RH.OrderRepo.OrdersContainsID(orderId))
     {
         Library.Order o = RH.OrderRepo.GetOrderByID(orderId);
         return(View(Models.Mapper.Map(o)));
     }
     TempData["FeedbackMsg"] = $"Could not find order ID {orderId}";
     return(View(nameof(Index)));
 }
 /// <summary>
 /// Adds order items to the db
 /// </summary>
 /// <param name="orderItems">List of items in an order to be submitted to db</param>
 public void AddOrderItems(IEnumerable <Library.Item> orderItems, Library.Order order)
 {
     // populate list with mapped items
     foreach (Library.Item item in orderItems)
     {
         // find associated inventory item using item id
         var newEntity = Mapper.MapOrderItem(item, order);
         dbcontext.OrderItems.Add(newEntity);
     }
 }
示例#17
0
 public static DataAccess.OrderHeader Map(Library.Order order) => new DataAccess.OrderHeader
 {
     OrderId        = order.orderID,
     UserId         = order.userID,
     OrderAddressId = order.orderAddressID,
     TotalCost      = order.totalCost,
     OrderDate      = order.orderDate,
     StoreId        = order.storeId,
     OrderDetail    = Map(order.orderDetail).ToList()
 };
示例#18
0
 //Maps data object to entity
 //object data --> entity
 public static Entities.Orders MapOrderWithEF(Library.Order OOrder)
 {
     return(new Entities.Orders
     {
         Oid = OOrder.OID,
         Cid = OOrder.CID,
         Lid = OOrder.LID,
         OrderType = OOrder.OrderType,
         OrderTime = OOrder.OrderTime
     });
 }
示例#19
0
        /* --------------------------------------------------------- */

        /* Item to OrderItems Mapping */
        public static Entities.OrderItems MapOrderItem(Library.Item modelI, Library.Order modelO)
        {
            Entities.OrderItems result = new Entities.OrderItems
            {
                OrderId   = modelO.OrderID,
                ProductId = modelI.Product.ID,
                Quantity  = modelI.Quantity,
            };

            return(result);
        }
示例#20
0
 /// <summary>
 /// Display a single model order
 /// </summary>
 /// <param name="order"></param>
 public static void DisplayOrder(Library.Order order)
 {
     if (order != null)
     {
         Console.WriteLine("----------------------------------------");
         Console.WriteLine($"OrderID:\t{order.MyTime}\n");
         Console.WriteLine($"Customer:\t{order.MyCustomer.Name} | Location:\t{order.MyLocation.Name} | Time Placed:\t{order.MyTime}\n");
         Console.WriteLine(); //TODO display order's items
         DisplayItems(order.ProductList);
     }
 }
示例#21
0
 public static Entities.Orders Map(Library.Order order) => new Entities.Orders
 {
     OrderId    = order.ID,
     CreatedAt  = order.Ordertime,
     PriceTag   = Convert.ToDecimal(order.Price),
     CustomerId = order.CustomerID,
     LocationId = order.LocationID,
     //Customer = null ?? Map(order.Customer),
     Location  = Map(order.Location),
     SoldBears = Map(order.bears).ToList()
 };
示例#22
0
        public static Entities.Orders Map(Library.Order order)
        {
            var ord = new Entities.Orders
            {
                CustomerId   = order.CustomerId,
                OrderLine    = MapL(order),
                LocationId   = order.LocationId,
                PurchaseDate = order.PlacedTime,
            };

            return(ord);
        }
示例#23
0
        /*------------------------------------------------------*/


        /* Order mapping */

        public static Entities.Orders MapOrder(Library.Order model)
        {
            Entities.Orders result = new Entities.Orders
            {
                OrderId    = model.OrderID,
                CustomerId = model.MyCustomer.CustomerId,
                LocationId = model.MyLocation.Id,

                TimeConfirmed = model.MyTime,
                OrderItems    = model.ProductList.Select(i => MapOrderItem(i, model)).ToList()
            };

            return(result);
        }
示例#24
0
        public static Library.Order MapOrder(Entities.Orders dbmodel)
        {
            Library.Order result = new Library.Order
            {
                OrderID    = dbmodel.OrderId,
                MyCustomer = MapCustomer(dbmodel.Customer),
                MyLocation = MapLocation(dbmodel.Location),

                MyTime      = dbmodel.TimeConfirmed,
                ProductList = dbmodel.OrderItems.Select(MapOrderItem).ToList(),
            };

            return(result);
        }
示例#25
0
        public void UpdateOrderDb(Library.Order order)
        {
            using var context = new AquariumContext(_contextOptions);
            var dbOrders = context.Orders
                           .Where(o => o.OrderId == order.OrderId)
                           .FirstOrDefault();

            dbOrders.StoreId    = order.StoreId;
            dbOrders.CustomerId = order.Customer.CustomerId;
            dbOrders.Date       = order.Date;
            dbOrders.AnimalId   = order.Animal.AnimalId;
            dbOrders.Quantity   = order.Quantity;
            dbOrders.Total      = order.Total;
            context.SaveChanges();
        }
示例#26
0
        public void AddToOrderDb(Library.Order order)
        {
            using var context = new AquariumContext(_contextOptions);
            var newEntry = new DataModel.Order
            {
                StoreId    = order.StoreId,
                CustomerId = order.Customer.CustomerId,
                AnimalId   = order.Animal.AnimalId,
                Quantity   = order.Quantity,
                Total      = order.Total,
                Date       = order.Date
            };

            context.Orders.Add(newEntry);
            context.SaveChanges();
        }
示例#27
0
        public static ICollection <Entities.OrderLine> MapL(Library.Order order)
        {
            var returning = new List <Entities.OrderLine>();

            foreach (var item in order.Ordered)
            {
                var brandNew = new Entities.OrderLine
                {
                    ItemId    = item.Id,
                    ItemCount = (int)order.ItemCount[item.Id],
                    Price     = item.Price * order.ItemCount[item.Id]
                };
                returning.Add(brandNew);
            }
            return(returning);
        }
示例#28
0
        /// <summary>
        /// Adds order to a particular customer
        /// </summary>
        /// <param name="order">Order Added</param>
        public void AddOrderByCustomerId(int customerId, int locationId)
        {
            using var context = new project0Context(_dbContext);
            var appOrders = new Library.Order()
            {
                CustomerId = customerId,
                LocationId = locationId,
            };
            var dbOrders = new DataModel.Order()
            {
                CustomerId = appOrders.CustomerId,
                LocationId = appOrders.LocationId,
                // OrderDetails.Quantity = quantity,
            };

            context.Add(dbOrders);
            context.SaveChanges();
        }
示例#29
0
        // GET: Order/Details/5
        public ActionResult Details(int id)
        {
            Library.Order cart = Repo.GetOrderById((int)id);



            OrderViewModel model = new OrderViewModel
            {
                OrderId  = cart.OrdId,
                Customer = Repo.SearchCustomersById(cart.CustId),
                Location = Repo.SearchLocationsById(cart.StoreId),
                Prod     = Repo.SearchProductsById(cart.ProdId),
                OrdTime  = cart.OrdTIme,
                Quant    = cart.Quantity
            };

            return(View(model));
        }
        public ActionResult FinishOrder(PizzaStoreView psv)
        {
            var newWebOrder = new Library.Order
            {
                LocationID = psv.DefaultLocation,
                UserID     = psv.Id,
                OrderTime  = DateTime.Now,
                Price      = 0
            };
            var newWebPizza = new Library.Pizza
            {
                OrderID   = Repo.GetMostRecentOrderID() + 1,
                PizzaSize = psv.PizzaSize,
                Toppings  = new Dictionary <string, bool>()
                {
                    { "Pepperoni", psv.Pepperoni },
                    { "Chicken", psv.Chicken },
                    { "Ham", psv.Ham },
                    { "Sausage", psv.Sausage },
                    { "Mushroom", psv.Mushroom },
                    { "Onion", psv.Onion },
                    { "Pineapple", psv.Pineapple },
                    { "Jalapeno", psv.Jalapeno },
                    { "Olive", psv.Olive },
                    { "Tomato", psv.Tomato }
                }
            };

            foreach (var topping in newWebPizza.Toppings)
            {
                if (topping.Value == true)
                {
                    Repo.GetLocation(psv.DefaultLocation).Inventory[topping.Key]--;
                    Repo.Save();
                }
            }
            psv.Price         = Repo.AddPrice(newWebPizza) * psv.NumPizza;
            newWebOrder.Price = psv.Price;
            Repo.AddOrder(newWebOrder);
            Repo.AddPizza(newWebPizza);
            Repo.Save();
            return(View("FinishOrder", psv));
        }