protected void btnEdit_Click(object sender, EventArgs e) { bool hasError = false; // Verify that stocks are correctly entered try { int stocks = Convert.ToInt32(txtStocks.Text); // Verify that stocks are >= 0 if (stocks < 0) { hasError = true; // Show error message lblEditError = FormatLbl.Error("Ensure that stocks are a positive value."); } else { artpiece.Stocks = stocks; } } catch (Exception ex) { hasError = true; // Show error message lblEditError = FormatLbl.Error("Ensure that stocks are numerical."); } if (!hasError) { //Update artpiece ArtpieceDao dao = new ArtpieceDao(); dao.Update(artpiece); // Show success msg lblEditError = FormatLbl.Success("Stocks successfully updated"); } // Refresh page //Net.RefreshPage(); }
private void pay() { // Get customer details Customer customer = (Customer)Net.GetSession("customer"); // Get count List <Order_Artwork> oaList = (List <Order_Artwork>)Net.GetSession("oaList"); int itemCount = oaList.Count; double total = 0; // Create order Order order = (Order)Net.GetSession("order"); IdGen IdGen = new IdGen(); order.OrderId = IdGen.GenerateId("custorder"); order.OrderDate = DateTime.Now; order.IsCanceled = false; order.CustomerId = customer.Id; order.DeliveryAddress = txtAddress.Text; foreach (Order_Artwork oa in oaList) { // Cumulate price ArtpieceDao dao = new ArtpieceDao(); Classes.Artpiece artpiece = dao.Get("ARTPIECEID", oa.ArtpieceId); total += oa.Quantity * artpiece.Price; // Set Foreign Keys oa.ArtpieceId = artpiece.ArtpieceId; oa.OrderId = order.OrderId; // Update stocks artpiece.Stocks = artpiece.Stocks - oa.Quantity; // Update artpiece ArtpieceDao artpieceDao = new ArtpieceDao(); artpieceDao.Update(artpiece); } // Set cumulated price as total price order.TotalPrice = total; // Insert order CustorderDao custorderDao = new CustorderDao(); custorderDao.Add(order); // Insert OrderArtwork foreach (Order_Artwork oa in oaList) { OrderArtworkDao orderArtworkDao = new OrderArtworkDao(); orderArtworkDao.Add(oa); } // Send receipt sendReceipt(order, oaList, customer.Email); // Clear cart Net.SetSession("order", new Order()); Net.SetSession("oaList", new List <Order_Artwork>()); Net.SetSession("cartSaved", false); }