Beispiel #1
0
        /// <summary>
        /// The purpose of this class is to insert new a new order into the database.
        /// </summary>
        /// <param name="Order">Type Library.Models.Order. It will contain all data about customer, location, and a list of orderlines.</param>
        public void PlaceAnOrderForACustomer(Library.Models.Order m_order)
        {
            // Create the Entity item to be put into the database
            OrderEntity order;

            order = Mapper_Order.MapOrderWithOrderLines(m_order);

            // We need to grab the entity objects from the database for the inventory rows for the given location.
            // This is so we can update them accordingly.
            IEnumerable <InventoryEntity> dbStocks = _context.Inventories.Where(i => i.LocationId == m_order.LocationPlaced.ID);

            // Since we are returned all the rows of inventory we need to iterate through each one to update it
            // This is done no matter if there was 1 purchase or many changing the inventory just to be sure
            // everything is updated correctly.
            foreach (InventoryEntity i in dbStocks)
            {
                // We also need to iterate through all the Library.Models.Stock list for the location
                foreach (Library.Models.Stock stock in m_order.LocationPlaced.Inventory)
                {
                    // An extra measure is taken here just to be sure that only books that exists in the database are being changed.
                    if (stock.Book.ISBN == i.BookIsbn)
                    {
                        // Set the new quantity
                        i.Quantity = stock.Quantity;
                    }
                }
            }

            // Add the new order and orderlines to the database
            _context.Add(order);

            // Save those changes
            Save();
        }
        /// <summary>
        /// Add a new order, along with its product dictionary, to the database
        /// </summary>
        /// <param name="order">Business-Model order object</param>
        public void AddOrder(Library.Models.Order order)
        {
            if (order.Id != 0)   // IDs are assigned by database, so it already exists if not 0
            {
                throw new ArgumentException("Order already exists.");
            }

            var customer = _dbContext.Customers.First(c => c.Id == order.Customer.Id);
            var location = _dbContext.Locations.First(l => l.Id == order.Location.Id);
            var dbOrder  = new Order()
            {
                Customer = customer,
                Location = location,
                Date     = order.Time
            };

            _dbContext.Orders.Add(dbOrder);

            foreach (var item in order.Products)
            {
                var product = _dbContext.Products.First(p => p.Id == item.Key.Id);

                var dbOrderContent = new OrderContent()
                {
                    Order    = dbOrder,
                    Product  = product,
                    Quantity = item.Value,
                    Price    = order.Location.Prices[item.Key]
                };

                _dbContext.OrderContents.Add(dbOrderContent);
            }
        }
Beispiel #3
0
 public static Entities.Order Map(Library.Models.Order order) => new Entities.Order
 {
     OrderId    = order.Id,
     CustomerId = order.CustomerId,
     LocationId = order.LocationId,
     Time       = order.Time,
     Quantity   = order.Quantity,
     Total      = order.Total,
 };
Beispiel #4
0
        public async void initData(Library.Models.Order value)
        {
            order = value;

            this.orderIDText.Text += order.OrderId.Substring(0, 20);

            if (order.isArrived == 1)
            {
                this.deliveryText.Text += "Delivered";
            }
            else
            {
                this.deliveryText.Text += "Is Delivering";
            }

            if (order.expectedShippingTime == "")
            {
                this.expectedShipTime.Text += "Processing";
            }
            else
            {
                this.expectedShipTime.Text += string.Format("{0:dd/MM/yyyy HH:mm:ss}", order.expectedShippingTime);
            }

            this.totalText.Text += string.Format("{0:N0} VNĐ", order.Total);

            if (order.isPaid == 1 && order.isArrived == 1 && order.customerRecived == 1)
            {
                receive.Content   = "OK";
                receive.IsEnabled = false;
            }
            else
            {
                if (order.isArrived == 1)
                {
                    receive.IsEnabled = true;
                }
                else
                {
                    receive.IsEnabled = false;
                }
            }
        }
 public void UpdateOrder(Library.Models.Order order)
 {
     throw new NotImplementedException();
 }