protected void btnPlaceOrder_Click(object sender, EventArgs e) { DataTable userDt = (DataTable)Session["UserWholeRecord"]; int customerID = Convert.ToInt32(userDt.Rows[0]["user_id"]); CustomerOrderDetails cod = new CustomerOrderDetails { CustomerID = customerID, GUID = Request.QueryString["id"].ToString(), Address = txtAddress.InnerText, PhoneNumber = txtPhoneNumber.Text, Quantity = ddlProductQuantity.SelectedValue.Equals("-1") ? 1 : ddlProductQuantity.SelectedIndex, TotalPrice = Convert.ToDouble(lblTotalPrice.Text) }; ECommerceBusiness ecb = new ECommerceBusiness { CODObj = cod }; ecb.AddNewCustomerOrderDetails(); Panel panel = OrderBody; panel.Style.Add("display", "none"); panel = pCPOD; panel.Style.Add("display", "none"); lblMessage.Text = "Your order will be placed within 24 hours!"; lblMessage.Style.Add("display", "block"); }
public void CreateOrder(int userId, OrdersDto orderDetails) { try { StringBuilder orderid = new StringBuilder(); orderid.Append(CreateRandomNumber(3)); orderid.Append('-'); orderid.Append(CreateRandomNumber(6)); CustomerOrders customerOrder = new CustomerOrders { OrderId = orderid.ToString(), UserId = userId, DateCreated = DateTime.Now.Date, CartTotal = orderDetails.CartTotal }; _dbContext.CustomerOrders.Add(customerOrder); _dbContext.SaveChanges(); foreach (CartItemDto order in orderDetails.OrderDetails) { CustomerOrderDetails productDetails = new CustomerOrderDetails { OrderId = orderid.ToString(), ProductId = order.Product.ProductId, Quantity = order.Quantity, Price = order.Product.Price }; _dbContext.CustomerOrderDetails.Add(productDetails); _dbContext.SaveChanges(); } } catch { throw; } }
public async Task <IActionResult> Order() { var Discount = HttpContext.Session.GetString("Discount"); var CustomerDetails = new Customers(); var user = await userManager.GetUserAsync(User); var user1 = await userManager.FindByEmailAsync(User.Identity.Name); if (await userManager.IsInRoleAsync(user, "Customer") == true) { CustomerDetails = _context.Customers. Where(s => s.MobileNumber == user.PhoneNumber) .FirstOrDefault(); } var ReservedTable = HttpContext.Session.Get <TableResevationCart>("Table"); if (ReservedTable != null) { CustomerOrderedTable abc = new CustomerOrderedTable() { CustomerOrderedTableId = 0, CustomersId = CustomerDetails.CustomersId }; abc.BookTimeFrom = ReservedTable.BookTimeFrom; abc.BookTimeTo = ReservedTable.BookTimeTo; abc.Date = ReservedTable.Date; abc.TableId = ReservedTable.TableId; await _context.CustomerOrderedTable.AddAsync(abc); await _context.SaveChangesAsync(); var update = _context.Table.Where(a => a.TableId == ReservedTable.TableId).FirstOrDefault(); update.BookedStatus = true; _context.Table.Update(update); await _context.SaveChangesAsync(); var orderlist = HttpContext.Session.Get <List <FoodCart> >("FoodS"); if (orderlist != null) { foreach (var item in orderlist) { CustomerOrderDetails ab = new CustomerOrderDetails() { CustomerOrderDetailsId = 0, FoodItemId = item.FoodItemId, Quantity = item.Quantity, PaymentStatus = false, CustomerOrderedTableId = abc.CustomerOrderedTableId, }; if (Discount != null) { ab.OfferId = Convert.ToInt32(Discount); } await _context.CustomerOrderDetails.AddAsync(ab); await _context.SaveChangesAsync(); } } } else { CustomerOrderedTable tabless = new CustomerOrderedTable() { CustomerOrderedTableId = 0, CustomersId = CustomerDetails.CustomersId, TableId = 1, Date = DateTime.Now }; await _context.CustomerOrderedTable.AddAsync(tabless); await _context.SaveChangesAsync(); var orderlist = HttpContext.Session.Get <List <FoodCart> >("FoodS"); if (orderlist != null) { foreach (var item in orderlist) { CustomerOrderDetails ab = new CustomerOrderDetails() { CustomerOrderDetailsId = 0, FoodItemId = item.FoodItemId, Quantity = item.Quantity, PaymentStatus = false, CustomerOrderedTableId = tabless.CustomerOrderedTableId }; if (Discount != null) { ab.OfferId = Convert.ToInt32(Discount); } await _context.CustomerOrderDetails.AddAsync(ab); await _context.SaveChangesAsync(); } } } var FoodItemList = HttpContext.Session.Get <List <FoodCart> >("FoodS"); foreach (var item in FoodItemList) { var IngredientList = await _context.RequiredMaterial .AsNoTracking().Where(a => a.FoodItemId == item.FoodItemId).ToListAsync(); for (int i = 0; i < IngredientList.Count(); i++) { var Requiered = await _context.RequiredMaterial.AsNoTracking() .Where(a => a.RequiredMaterialId == IngredientList[i].RequiredMaterialId) .FirstOrDefaultAsync(); var NeedToUpdateMaterials = await _context.StockDetails. AsNoTracking().Where(a => a.IngredientId == IngredientList[i].IngredientId) .LastOrDefaultAsync(); for (int j = 0; j < item.Quantity; j++) { var quaantity = NeedToUpdateMaterials.AvailableStock - Requiered.QuantityInGram; NeedToUpdateMaterials.AvailableStock = quaantity; _context.StockDetails.Update(NeedToUpdateMaterials); await _context.SaveChangesAsync(); _context.Entry <StockDetails>(NeedToUpdateMaterials).State = EntityState.Detached; } NeedToUpdateMaterials = new StockDetails(); Requiered = new RequiredMaterial(); } IngredientList = new List <RequiredMaterial>(); } HttpContext.Session.Remove("FoodS"); HttpContext.Session.Remove("Table"); HttpContext.Session.Remove("Discount"); return(RedirectToAction("Index", "Home")); }