public void UpdateQuantity(int id, int quantity) { cspDBEntities db = new cspDBEntities(); Cart p = db.Carts.Find(id); p.Amount = quantity; db.SaveChanges(); }
public string InsertProductType(ProductType productType) { try { cspDBEntities db = new cspDBEntities(); db.ProductTypes.Add(productType); db.SaveChanges(); return(productType.Name + "was succesfully inserted"); } catch (Exception e) { return("Error:" + e); } }
public string InsertCart(Cart cart) { try { cspDBEntities db = new cspDBEntities(); db.Carts.Add(cart); db.SaveChanges(); return("Order inserted successfully!!!"); } catch (Exception e) { return("Error:" + e); } }
public void MarkOrdersAsPaid(List <Cart> carts) { cspDBEntities db = new cspDBEntities(); if (carts != null) { foreach (Cart cart in carts) { Cart oldCart = db.Carts.Find(cart.ID); oldCart.DatePurchased = DateTime.Now; oldCart.IsInCart = false; } db.SaveChanges(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { try { ProductType pt = new ProductType(); pt.Name = txtBoxName.Text; csp.ProductTypes.Add(pt); csp.SaveChanges(); lblError.Text = txtBoxName.Text + " added successfully!!!"; } catch (Exception ex) { lblError.Text = "Error : " + ex.ToString(); } }
public string DeleteProductType(int id) { try { cspDBEntities db = new cspDBEntities(); ProductType productType = db.ProductTypes.Find(id); db.ProductTypes.Attach(productType); db.ProductTypes.Remove(productType); db.SaveChanges(); return(productType.Name + "was succesfully deleted"); } catch (Exception e) { return("Error:" + e); } }
public string DeleteCart(int id) { try { cspDBEntities db = new cspDBEntities(); Cart cart = db.Carts.Find(id); db.Carts.Attach(cart); db.Carts.Remove(cart); db.SaveChanges(); return(cart.DatePurchased + " deleted succesfully"); } catch (Exception e) { return("Error:" + e); } }
public string UpdateProductType(int id, ProductType productType) { try { cspDBEntities db = new cspDBEntities(); //Fetch object from db ProductType p = db.ProductTypes.Find(id); p.Name = productType.Name; db.SaveChanges(); return(productType.Name + "was succesfully updated"); } catch (Exception e) { return("Error:" + e); } }
void AddProducts() { try { Product p = new Product(); p.Name = txtBoxName.Text; p.Price = Convert.ToInt32(txtBoxPrice.Text); p.TypeId = Convert.ToInt32(ddType.SelectedValue); p.Description = txtDescription.Text; p.Image = ddImage.SelectedValue; csp.Products.Add(p); csp.SaveChanges(); lblResult.Text = txtBoxName.Text + " added successfully!!!"; } catch (Exception ex) { lblResult.Text = "Error : " + ex.ToString(); } }
public string UpdateProduct(int id, Product product) { try { cspDBEntities db = new cspDBEntities(); //Fetch object from db Product p = db.Products.Find(id); p.Name = product.Name; p.Price = product.Price; p.TypeId = product.TypeId; p.Description = product.Description; p.Image = product.Image; db.SaveChanges(); return(product.Name + " was succesfully updated"); } catch (Exception e) { return("Error:" + e); } }
public string UpdateCart(int id, Cart cart) { try { cspDBEntities db = new cspDBEntities(); //Fetch object from db Cart p = db.Carts.Find(id); p.DatePurchased = cart.DatePurchased; p.ClientID = cart.ClientID; p.Amount = cart.Amount; p.IsInCart = cart.IsInCart; p.ProductID = cart.ProductID; db.SaveChanges(); return(cart.DatePurchased + " updated succesfully "); } catch (Exception e) { return("Error:" + e); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (txtBoxFName.Text == "") { lblName.Text = "*"; lblUname0.Text = ""; lblLname.Text = ""; lblPassword.Text = ""; lblEmail.Text = ""; lblCity.Text = ""; lblResult.Text = ""; lblAddress.Text = ""; lblPostalCode.Text = ""; } else if (txtBoxLName.Text == "") { lblLname.Text = "*"; lblUname0.Text = ""; lblName.Text = ""; lblPassword.Text = ""; lblEmail.Text = ""; lblCity.Text = ""; lblResult.Text = ""; lblAddress.Text = ""; lblPostalCode.Text = ""; } else if (txtBoxUName.Text == "") { lblLname.Text = ""; lblUname0.Text = "*"; lblName.Text = ""; lblPassword.Text = ""; lblEmail.Text = ""; lblCity.Text = ""; lblResult.Text = ""; lblAddress.Text = ""; lblPostalCode.Text = ""; } else if (txtBoxPassword.Text == "") { lblLname.Text = ""; lblUname0.Text = ""; lblName.Text = ""; lblPassword.Text = "*"; lblEmail.Text = ""; lblCity.Text = ""; lblResult.Text = ""; lblAddress.Text = ""; lblPostalCode.Text = ""; } else if (txtBoxEmail.Text == "") { lblLname.Text = ""; lblUname0.Text = ""; lblName.Text = ""; lblPassword.Text = ""; lblEmail.Text = "*"; lblCity.Text = ""; lblResult.Text = ""; lblAddress.Text = ""; lblPostalCode.Text = ""; } else if (ddCity.SelectedValue == "Please select your City...") { lblLname.Text = ""; lblUname0.Text = ""; lblName.Text = ""; lblPassword.Text = ""; lblEmail.Text = ""; lblCity.Text = "*"; lblResult.Text = ""; lblAddress.Text = ""; lblPostalCode.Text = ""; } else if (txtBoxPostalCode.Text == "") { lblLname.Text = ""; lblUname0.Text = ""; lblName.Text = ""; lblPassword.Text = ""; lblPostalCode.Text = "*"; lblCity.Text = ""; lblResult.Text = ""; lblAddress.Text = ""; } else if (txtBoxAddress.Text == "") { lblLname.Text = ""; lblUname0.Text = ""; lblName.Text = ""; lblPassword.Text = ""; lblAddress.Text = "*"; lblCity.Text = ""; lblResult.Text = ""; lblPostalCode.Text = ""; } else { try { int pCode = int.Parse(txtBoxPostalCode.Text); Registration r = new Registration(); r.F_Name = txtBoxFName.Text; r.L_Name = txtBoxLName.Text; r.U_Name = txtBoxUName.Text; r.Email = txtBoxEmail.Text; r.Password = txtBoxPassword.Text; r.City = ddCity.SelectedValue; r.Address = txtBoxAddress.Text; r.PostalCode = pCode; csp.Registration.Add(r); csp.SaveChanges(); lblResult.Text = "Registered successfully!!!"; txtBoxEmail.Text = ""; txtBoxFName.Text = ""; txtBoxLName.Text = ""; txtBoxPassword.Text = ""; txtBoxUName.Text = ""; lblAddress.Text = ""; lblPostalCode.Text = ""; ddCity.SelectedValue = "Please select your City..."; var secretID = csp.Registration.Select(en => en.ID).Max(); lblResult.Text += " \r\n" + secretID.ToString() + " is your unique ID." + "\r\n" + "Remember it for Login."; } catch (Exception ex) { lblResult.Text = "Error : " + ex.ToString(); } } }