Пример #1
0
        public void CreateOrder(Cart cart)
        {
            
            int statusID = chocoPlanetDbEntities.Status.SingleOrDefault(s => s.Name == "Новий").ID;
            int orderItemsID = (chocoPlanetDbEntities.OrderItems.Count() != 0) ? (chocoPlanetDbEntities.OrderItems.Max(id => id.ID) + 1) : 1;
            Country country = new Country()
            {
                ID = (chocoPlanetDbEntities.Country.Count() != 0) ? chocoPlanetDbEntities.Country.Max(id => id.ID) + 1 : 1,
                Name = cart.ShippingDetails.Country
            };
            Address address = new Address()
            {
                ID = (chocoPlanetDbEntities.Address.Count() != 0) ? chocoPlanetDbEntities.Address.Max(id => id.ID) + 1 : 1,
                CountryId = country.ID,
                Town = cart.ShippingDetails.Town,
                Stret = cart.ShippingDetails.Stret

            };
            Customer customer = new Customer()
            {
                ID = (chocoPlanetDbEntities.Customer.Count() != 0) ? chocoPlanetDbEntities.Customer.Max(id => id.ID) + 1 : 1,
                Name = cart.ShippingDetails.Name,
                Telefon = cart.ShippingDetails.Telefon,
                AddressId = address.ID



            };
            Order order = new Order()
            {
                ID = (chocoPlanetDbEntities.Order.Count() != 0) ? chocoPlanetDbEntities.Order.Max(id => id.ID) + 1 : 1,
                StatusId = statusID,
                CreateDate = DateTime.Now,
                ModifayDate = DateTime.Now,
                CustomerId = customer.ID


            };


            foreach (CartLine line in cart.Lines)
            {
                OrderItems orderItems = new OrderItems();
                orderItems.ID = orderItemsID;
                orderItems.OrderId = order.ID;
                orderItems.ProductId = chocoPlanetDbEntities.Product.SingleOrDefault(name => name.Name == line.Product.Name).ID;
                orderItems.Quantity = line.Quantity;
                chocoPlanetDbEntities.OrderItems.AddObject(orderItems);
                orderItemsID++;
            }
            chocoPlanetDbEntities.Order.AddObject(order);
            chocoPlanetDbEntities.Country.AddObject(country);
            chocoPlanetDbEntities.Customer.AddObject(customer);
            chocoPlanetDbEntities.Address.AddObject(address);
            chocoPlanetDbEntities.SaveChanges();
            
           

        }
Пример #2
0
 public void OrderItemsComparer()
 {
     foreach (var item in OrderItems)
     {
         if (OrderItems.Where(x => x.Product == item.Product).Count() > 1)
         {
             MessageBox.Show("Dublicate product in order items list.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
             NotifyPropertyChanged();
         }
     }
 }
Пример #3
0
        public void DeleteItem(ItemOptionsClass itemToDelete)
        {
            OrderItems.Remove(itemToDelete);
            OrderItem oi = context.OrderItems.FirstOrDefault(it => it.Sku.Equals(itemToDelete.Sku));

            if (context.OrderItems.Contains(oi))
            {
                context.OrderItems.DeleteOnSubmit(context.OrderItems.FirstOrDefault(it => it.Sku.Equals(itemToDelete.Sku)));
                _hasChanges = true;
            }
        }
Пример #4
0
        public decimal CalculateTotal()
        {
            decimal total = 0;

            if (!OrderItems.IsLoaded)
            {
                OrderItems.Load();
            }
            OrderItems.ForEach(x => total += x.TotalPrice);
            return(total);
        }
Пример #5
0
        public async Task ShipAsync()
        {
            if (CanShip)
            {
                var shipTasks = OrderItems.Select(i => i.SubmitAsync()).ToArray();
                await Task.WhenAll(shipTasks);

                _eventAggregator.SendMessage <OrderUpdatedEvent>(new OrderUpdatedEvent(this));
                OnPropertyChanged("CanShip", "CanChangeCustomer");
            }
        }
Пример #6
0
        public void RemoveItem(Guid orderItemId)
        {
            var orderItem = OrderItems.FirstOrDefault(x => x.Id == orderItemId);

            if (orderItem == null)
            {
                AddNotification("Order", "This item doesn't exist in your list.");
            }

            _orderItems.Remove(orderItem);
        }
Пример #7
0
        //Checks if Item is in basket
        public bool IsProductInBasket(string productName)
        {
            bool      inBasket = false;
            OrderItem item     = OrderItems.Find(x => x.ProductName == productName);

            if (item != null)
            {
                inBasket = true;
            }
            return(inBasket);
        }
Пример #8
0
 public int GetIdempotentKey()
 {
     unchecked
     {
         int hashCode = CaptureNumber?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (CreditNoteNumber?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ OrderItems.GetIdempotentListKey();
         hashCode = (hashCode * 397) ^ (OrderNumber?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
        public async Task <IActionResult> Create([Bind("OrderId,ProductId,Quantity")] OrderItems orderItems)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderItems);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderItems));
        }
        public bool UpdateDataSource(OrderItems aItem)
        {
            bool success = true;

            Create_INSERT_Command(aItem);
            Create_UPDATE_Command(aItem);
            Create_DELETE_Command(aItem);
            success = UpdateDataSource(sqlLocal1, table1);

            return(success);
        }
Пример #11
0
        private async void AddProduct(Product product)
        {
            this.decimalTextBox.Text    = "1";
            this.quantityDialog.Content = this.decimalTextBox;
            this.quantityDialog.Title   = "Enter quantity";
            ContentDialogResult result = await this.ShowQuantityDialog();

            if (result == ContentDialogResult.Primary)
            {
                TextBox input = (TextBox)quantityDialog.Content;
                decimal.TryParse(input.Text, out decimal quantity);
                if (quantity == 0)
                {
                    quantity = 1;
                }
                if (quantity <= product.Quantity)
                {
                    if (OrderItems.Any(p => p.OrderItem.ProductId == product.ProductId))
                    {
                        OrderItemListView existingItem = OrderItems.FirstOrDefault(p => p.OrderItem.ProductId == product.ProductId);
                        int index = OrderItems.IndexOf(existingItem);
                        existingItem.OrderItem.Quantity += quantity;
                        OrderItemListView orderItemListView = this.GetDuplicatedItem(existingItem);
                        OrderItems.RemoveAt(index);
                        OrderItems.Insert(index, orderItemListView);
                    }
                    else
                    {
                        OrderItemListView orderItem = new OrderItemListView
                        {
                            OrderItem = new OrderItem
                            {
                                Product      = product,
                                ProductId    = product.ProductId,
                                Quantity     = quantity,
                                LineDiscount = 0,
                                SubTotal     = this.GetSubTotal(product.SellingPrice, quantity, 0)
                            }
                        };
                        orderItem.ItemDeleteClicked += this.HandleItemDeleted;
                        OrderItems.Add(orderItem);
                    }
                    RaisePropertyChanged("OrderItems");
                    RaisePropertyChanged("IsProceedEnabled");
                }
                else
                {
                    this.messageDialog.Content = "Insufficient quantity !";
                    await this.messageDialog.ShowAsync();
                }
                this.SearchText = product.Name;
            }
            this.SearchText = string.Empty;
        }
Пример #12
0
 public void AddOrUpdateItem(OrderItem orderItem, Product product)
 {
     if (orderItem == null)
     {
         OrderItems.Add(new OrderItem(product));
     }
     else
     {
         OrderItems.Where(x => x.Product.Id == orderItem.Product.Id).Select(x => x.Qtd++).ToList();
     }
 }
Пример #13
0
        /// <summary>
        /// Create a new receipt object using all data collected from the order so far, and then store this in a list
        /// for use later.
        /// </summary>
        private void CreateReceipt()
        {
            CheckCustomerFields();

            CustomerInfo   customer = ReceiptLogic.CreateCustomer(txtCustomerName.Text, txtCustomerAddress.Text, txtCustomerPostcode.Text);
            OrderItems     items    = ReceiptLogic.PopulateOrderItems(pizzas, sides, drinks);
            MonetaryValues money    = ReceiptLogic.PopulateMonetaryValues(deals, CalculateBasePrice());
            ReceiptModel   receipt  = ReceiptLogic.CreateReceipt(customer, items, money);

            receipts.Add(receipt);
        }
Пример #14
0
 public void AddExistingCustomerOrderTest()
 {
     try
     {
         OrderItems expected = orderManage.AddCustomerOrder(orderItems.First());
     }
     catch (Exception ex)
     {
         Assert.AreEqual("CustomerOrder already exists", ex.Message);
     }
 }
        public KitchenReceiptForm(string order_id)
        {
            InitializeComponent();

            this.orders    = new Orders();
            this.orders.Id = order_id;

            DataTable orderData = this.orders.getOrderDetail();

            Employee emp         = new Employee();
            string   server_name = emp.getServerNameById(orderData.Rows[0]["server_id"].ToString());

            this.param = new Dictionary <string, string>();
            param.Add("table_id", orderData.Rows[0]["table_id"].ToString());
            param.Add("table_name", orderData.Rows[0]["table_name"].ToString());
            param.Add("floor", orderData.Rows[0]["floor"].ToString());
            param.Add("zone", orderData.Rows[0]["zone"].ToString());
            param.Add("server_id", orderData.Rows[0]["server_id"].ToString());
            param.Add("server_name", server_name);
            param.Add("user_name", orderData.Rows[0]["user_name"].ToString());
            param.Add("order_type", orderData.Rows[0]["order_type"].ToString().ToUpper());


            this.kitchenOrder = new KitchenOrder(this.orders);
            DataTable kitchenOrdersData = this.kitchenOrder.getKitchenOrder();

            this.kitchen              = new Kitchen();
            cbn_kitchen.DataSource    = this.kitchen.getKitchensByPrimaryKeys(kitchenOrdersData);
            cbn_kitchen.ValueMember   = "id";
            cbn_kitchen.DisplayMember = "name";
            cbn_kitchen.SelectedIndex = 0;

            this.orderItems            = new OrderItems(this.orders);
            this.orderItems.Kitchen_id = cbn_kitchen.SelectedValue.ToString();

            DataTable data = this.orderItems.kitchenReceipt();

            this.list = new List <KitchenReceipt>();

            foreach (DataRow row in data.Rows)
            {
                this.list.Add(
                    new KitchenReceipt()
                {
                    item_id          = row["id1"].ToString(),
                    item_name        = row["item_name"].ToString(),
                    item_qty         = row["item_qty"].ToString(),
                    additional_notes = row["additional_note"].ToString()
                }
                    );
            }

            dgv_items.DataSource = list;
        }
 public void AddOrderItemsExistTest()
 {
     try
     {
         OrderItems expected = orderManage.AddOrderItems(11, "Iphone8", 2);
     }
     catch (Exception ex)
     {
         Assert.AreEqual("Item already exists", ex.Message);
     }
 }
Пример #17
0
 public static List <DataEntryInfo> GetRevenueChartData()
 {
     if (!useCache || rChartData == null)
     {
         rChartData = OrderItems.GroupBy(i => i.Product.Category).Select(g => new DataEntryInfo()
         {
             Name = g.Key.ToString(), Value = g.Sum(i => i.Total)
         }).ToList();
     }
     return(rChartData);
 }
        private void FillRow(DataRow aRow, OrderItems aItem, DB.DBOperation operation)
        {
            if (operation == DB.DBOperation.Add)
            {
                aRow["OrderItemID"] = aItem.OrderItemID;  //NOTE square brackets to indicate index of collections of fields in row.
            }

            aRow["OrderID"]   = aItem.OrderID;
            aRow["ProductID"] = aItem.ProductID;
            aRow["Quantity"]  = aItem.Quantity;
        }
Пример #19
0
        public ICollection <OrderItems> GetAllSelectedCartProducts(IDictionary <int, int> cartProductItems)
        {
            IDictionary <int, int>   productQuantity = cartProductItems;
            ICollection <OrderItems> items           = new Collection <OrderItems>();


            foreach (KeyValuePair <int, int> productQ in productQuantity)
            {
                using (SqlConnection Connection = new SqlConnection(connectionString))
                {
                    ICollection <Product> products = new Collection <Product>();

                    SqlCommand Command = new SqlCommand();
                    Command.Connection = Connection;


                    Command.CommandText = "sp_Get_Product_By_Id";
                    Command.CommandType = CommandType.StoredProcedure;

                    SqlParameter parameterId = new SqlParameter("@ProductId", productQ.Key);


                    Command.Parameters.Add(parameterId);
                    Connection.Open();
                    SqlDataReader reader  = Command.ExecuteReader();
                    Product       product = new Product();

                    while (reader.Read())
                    {
                        product.ProductId          = Convert.ToInt32(reader["Id"]);
                        product.ProductName        = reader["ProductName"].ToString();
                        product.ProductDescription = reader["Description"].ToString();
                        product.ProductPrice       = Convert.ToInt64(reader["Price"]);
                        product.ProductImage       = (byte[])reader["ProductImage"];


                        OrderItems orderItem = new OrderItems()
                        {
                            Product    = product,
                            Quantity   = productQ.Value,
                            TotalPrice = (product.ProductPrice * productQ.Value)
                        };
                        items.Add(orderItem);
                    }


                    reader.Close();
                    Connection.Close();
                }
            }


            return(items);
        }
Пример #20
0
        public void AddOrderItem(OrderItem orderItem)
        {
            OrderItemCount = 0;
            Subtotal       = 0.0;

            OrderItems.Add(orderItem);
            foreach (var item in OrderItems)
            {
                OrderItemCount += item.Quantity;
                Subtotal       += item.LineTotal;
            }
        }
Пример #21
0
        public async Task <IActionResult> PostOrderItems([FromBody] OrderItems orderItems)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.OrderItems.Add(orderItems);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetOrderItems", new { id = orderItems.ID }, orderItems));
        }
Пример #22
0
        public async Task <ActionResult> Put(string id, [FromBody] OrderItems catIn)
        {
            var obj = _context.Get(id);

            if (obj == null)
            {
                return(NotFound());
            }
            await _context.Update(id, catIn);

            return(NoContent());
        }
Пример #23
0
 public ActionResult Edit([Bind(Include = "OrderItemsID,OrderID,ProductID,Quantity")] OrderItems orderItems)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderItems).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "OrderID", orderItems.OrderID);
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Name", orderItems.ProductID);
     return(View(orderItems));
 }
 private void OnRemoveItem()
 {
     if (SelectedOrderItem != null)
     {
         MessageBoxResult result = MessageBox.Show("You are about to delete an item. Do you want to continue?", "Delete Item", MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (result == MessageBoxResult.Yes)
         {
             OrderItems.Remove(SelectedOrderItem);
         }
         ;
     }
 }
Пример #25
0
        public void InValidOrderItem()
        {
            //Arrange
            OrderItems orderItem = new OrderItems();
            bool       expected  = false;

            //Act
            bool actual = orderItem.IsValid;

            //Assert
            Assert.AreEqual(expected, actual);
        }
Пример #26
0
 public void AddProduct(string prodName, decimal latestPrice, int qty)
 {
     foreach (OrderItem item in OrderItems)
     {
         if (item.ProductName == prodName)
         {
             item.AddItems(latestPrice, qty);
             return;
         }
     }
     OrderItems.Add(new OrderItem(prodName, latestPrice, qty));
 }
Пример #27
0
        public void GetOrderTotals()
        {
            foreach (var orderItem in OrderItems)
            {
                orderItem.GetOrderItemTotals();
            }

            Subtotal      = OrderItems.Sum(o => o.Subtotal);
            ShippingTotal = OrderItems.Sum(o => o.ShippingCost);
            TaxTotal      = OrderItems.Sum(o => o.TaxCost);
            Total         = OrderItems.Sum(o => o.OrderItemTotal);
        }
Пример #28
0
 public void Remove(Product product, int count = 1)
 {
     if (OrderItems.Any(x => x.Product == product))
     {
         OrderItem item = OrderItems.Where(x => x.Product == product).First();
         item.Remove(count);
         if (0 == item.Quontity)
         {
             OrderItems.Remove(item);
         }
     }
 }
Пример #29
0
 public void InsertOrderItems(List <int> Items, Guid OrdersID)
 {
     foreach (var item in Items)
     {
         OrderItems _orderItems = new OrderItems()
         {
             ProductID = item, Amount = 1, OrdersID = OrdersID
         };
         _context.OrderItems.Add(_orderItems);
     }
     _context.SaveChanges();
 }
 private void OnCancelOrder()
 {
     if (OrderItems.Count > 0)
     {
         MessageBoxResult result = MessageBox.Show("You are about to delete current order. Do you want to continue?", "Delete Order", MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (result == MessageBoxResult.Yes)
         {
             OrderItems.Clear();
         }
         ;
     }
 }
Пример #31
0
 static Dictionary <long, List <DataEntryInfo> > CreateProductSalesChartData()
 {
     return(OrderItems.GroupBy(q => q.ProductId)
            .Select(g => new {
         K = g.Key.Value,
         V = g.GroupBy(q => q.Order.OrderDate.Year)
             .Select(yg => new { Year = yg.Key, Total = yg.Sum(i => i.Total) }).OrderBy(i => i.Year).ToList()
     }).ToDictionary(i => i.K, i => i.V.Select(e => new DataEntryInfo()
     {
         Name = e.Year.ToString(), Value = e.Total
     }).ToList()));
 }