public async Task AddProductToOrderTempAsync(int productId) { var product = await _context.Products.FindAsync(productId); if (product == null) { return; } var orderDetailTemp = await _context.OrderDetailsTemp .Where(odt => odt.Product == product) .FirstOrDefaultAsync(); if (orderDetailTemp == null) { orderDetailTemp = new OrderDetailsTemp { Price = product.Price, Product = product, Quantity = 1, //User = user }; _context.OrderDetailsTemp.Add(orderDetailTemp); } else { orderDetailTemp.Quantity += 1; _context.OrderDetailsTemp.Update(orderDetailTemp); } await _context.SaveChangesAsync(); }
protected void RepeaterOrder_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { OrderDetailsTemp dr = (OrderDetailsTemp)e.Item.DataItem; ((Button)e.Item.FindControl("btn_decrease")).CommandArgument = dr.ProductId.ToString(); ((Button)e.Item.FindControl("btn_increase")).CommandArgument = dr.ProductId.ToString(); } }
public async Task AddItemToOrderAsync(AddItemViewModel model, string userName) { var user = await _userHelper.GetUserByEmailAsync(userName); if (user == null) { return; } var product = await _context.Products.FindAsync(model.ProductId); if (product == null) { return; } var orderDetailsTemp = await _context.OrderDetailsTemp .Where(odt => odt.User == user && odt.Product == product) .FirstOrDefaultAsync(); if (orderDetailsTemp == null) { orderDetailsTemp = new OrderDetailsTemp { Price = product.Price, Product = product, Quantity = model.Quantity, User = user, }; _context.OrderDetailsTemp.Add(orderDetailsTemp); } else { orderDetailsTemp.Quantity += model.Quantity; _context.OrderDetailsTemp.Update(orderDetailsTemp); } await _context.SaveChangesAsync(); }
//ToDo: Need to update the contain in Warehouse database when new order occur private void lvCategory_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (App.Current.Properties["CurrentEmpWorking"] == null) { return; } orderingTable = ((MainWindow)Window.GetWindow(this)).currentTable; orderingChair = ((MainWindow)Window.GetWindow(this)).currentChair; ListBox lbSelected = sender as ListBox; if (orderingTable == null || orderingChair == null) { MessageBox.Show("Chair must be choice!"); return; } orderTempCurrentTable = _unitofwork.OrderTempRepository.Get(x => x.TableOwned.Equals(orderingTable.TableId)).First(); if (orderTempCurrentTable == null) { return; } var item = lbSelected.SelectedItem; if (item != null) { if (orderingTable.IsOrdered == 0) { orderTempCurrentTable.Ordertime = DateTime.Now; orderingTable.IsOrdered = 1; _unitofwork.TableRepository.Update(orderingTable); } OrderDetailsTemp o = new OrderDetailsTemp(); Product it = (Product)lbSelected.SelectedItem; //order for each chair if (orderingChair != null) { var chairorderdetailstemp = _unitofwork.OrderDetailsTempRepository.Get(x => x.ChairId.Equals(orderingChair.ChairId)).ToList(); var foundinchairorderdetailstemp = chairorderdetailstemp.Where(x => x.ProductId.Equals(it.ProductId)).ToList(); // go to warehouse, check and get the ingredient to make product if (!TakeFromWareHouseData(o, it)) { return; } // add a product to order if (foundinchairorderdetailstemp.Count == 0) { o.ChairId = orderingChair.ChairId; o.OrdertempId = orderTempCurrentTable.OrdertempId; o.ProductId = it.ProductId; o.SelectedStats = it.StandardStats; o.Note = ""; o.Quan = 1; o.IsPrinted = 0; o.Discount = it.Discount; _unitofwork.OrderDetailsTempRepository.Insert(o); _unitofwork.Save(); } else { foreach (var order in foundinchairorderdetailstemp) { if (!order.SelectedStats.Equals(it.StandardStats) || !order.Note.Equals("") || order.IsPrinted != 0) { o.ChairId = orderingChair.ChairId; o.OrdertempId = orderTempCurrentTable.OrdertempId; o.ProductId = it.ProductId; o.SelectedStats = it.StandardStats; o.Note = ""; o.Quan = 1; o.IsPrinted = 0; o.Discount = it.Discount; _unitofwork.OrderDetailsTempRepository.Insert(o); _unitofwork.Save(); break; } if (order.SelectedStats.Equals(it.StandardStats) && order.Note.Equals("") && order.IsPrinted == 0) { order.ProductId = it.ProductId; order.Quan++; _unitofwork.OrderDetailsTempRepository.Update(order); _unitofwork.Save(); break; } } } } lbSelected.UnselectAll(); checkWorkingAction(App.Current.Properties["CurrentEmpWorking"] as EmpLoginList, orderTempCurrentTable); ((MainWindow)Window.GetWindow(this)).initProgressTableChair(); ((MainWindow)Window.GetWindow(this)).en.ucOrder.RefreshControl(_unitofwork, orderingTable); ((MainWindow)Window.GetWindow(this)).en.ucOrder.txtDay.Text = orderTempCurrentTable.Ordertime.ToString("dd/MM/yyyy H:mm:ss"); } }
private bool TakeFromWareHouseData(OrderDetailsTemp orderDetails, Product orderingProduct) { var prodOfOrderDetails = _cloudPosUnitofwork.ProductRepository.Get(x => x.ProductId.Equals(orderingProduct.ProductId), includeProperties: "ProductDetails").FirstOrDefault(); if (prodOfOrderDetails != null) { // if product have no product details if (prodOfOrderDetails.ProductDetails.Count == 0) { // still allow to order but no ingredient relate to this product for tracking return(true); } var wareHouseDict = new Dictionary <WareHouse, double?>(); // going to warehouse and take the contain of each ingredient foreach (var prodDetails in prodOfOrderDetails.ProductDetails) { var quan = prodDetails.Quan; var ingd = _cloudPosUnitofwork.IngredientRepository.Get(x => x.IgdId.Equals(prodDetails.IgdId)) .FirstOrDefault(); if (ingd == null) { MessageBox.Show("Something went wrong cause of the Ingredient's information"); return(false); } var wareHouse = _cloudPosUnitofwork.WareHouseRepository.Get(x => x.WarehouseId.Equals(ingd.WarehouseId)) .FirstOrDefault(); if (wareHouse == null) { MessageBox.Show("Something went wrong cause of the WareHouse's information"); return(false); } var temple_Contain = wareHouse.Contain; if (temple_Contain < quan) { MessageBox.Show("This Product can not order now. Please check to WareHouse for Ingredient's stock!"); return(false); } else { temple_Contain -= quan; } wareHouseDict.Add(wareHouse, temple_Contain); } // when all ingredient are enough to make product foreach (var item in wareHouseDict) { item.Key.Contain = item.Value; } _cloudPosUnitofwork.Save(); } else { MessageBox.Show("This Product is not existed in database! Please check the Product's information"); return(false); } return(true); }
protected void RepeaterProducts_ItemCommand(object source, RepeaterCommandEventArgs e) { List <OrderDetailsTemp> OrderDetailsTemps = new List <OrderDetailsTemp>(); if (Session["anonimo"] != null) { OrderDetailsTemps = (List <OrderDetailsTemp>)Session["anonimo"]; } if (e.CommandName.Equals("btn_cart")) { if (Session["userlogin"] == null) { var temp = new OrderDetailsTemp(); foreach (var item in Products) { if (item.ProductId.ToString() == ((Button)e.Item.FindControl("btn_cart")).CommandArgument) { temp.Category = item.Category; temp.Description = item.Description; temp.ImagePath = item.ImagePath; temp.ProductId = item.ProductId; temp.Price = item.Price; temp.Quantity = 1; temp.ProductName = item.ProductName; } } if (temp != null) { if (OrderDetailsTemps.Find(o => o.ProductId == temp.ProductId) == null) { OrderDetailsTemps.Add(temp); } else { OrderDetailsTemps.Find(o => o.ProductId == temp.ProductId).Quantity += 1; } } numItemInCart.Text = OrderDetailsTemps.Count().ToString(); Session["anonimo"] = OrderDetailsTemps; //Response.Redirect("../Home/Login.aspx"); } else { foreach (var item in Products) { if (item.ProductId.ToString() == ((Button)e.Item.FindControl("btn_cart")).CommandArgument) { SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["OnShopCenterConnectionString"].ConnectionString); SqlCommand mycommand = new SqlCommand { CommandType = CommandType.StoredProcedure, CommandText = "AddProduct", Connection = myConn }; //mycommand.Parameters.AddWithValue("@userId", 2); mycommand.Parameters.AddWithValue("@userId", Convert.ToInt32(Session["userId"].ToString())); mycommand.Parameters.AddWithValue("@productId", item.ProductId); mycommand.Parameters.AddWithValue("@price", item.Price); mycommand.Parameters.AddWithValue("@quantity", 1); SqlParameter valor = new SqlParameter { ParameterName = "@retorno", Direction = ParameterDirection.Output, SqlDbType = SqlDbType.Int, Size = 6 }; //add parameter output mycommand.Parameters.Add(valor); try { myConn.Open(); mycommand.ExecuteNonQuery(); numItemInCart.Text = mycommand.Parameters["@retorno"].Value.ToString(); } catch (Exception) { } finally { myConn.Close(); } } } } } }