public string InsertCart(Cart cart) { try { G2Entities db = new G2Entities(); db.Carts.Add(cart); db.SaveChanges(); return "Order was succesfully inserted"; } catch (Exception e) { return "Error:" + e; } }
public string InsertProduct(Product product) { try { G2Entities db = new G2Entities(); db.Products.Add(product); db.SaveChanges(); return product.Name + " was succesfully inserted"; } catch (Exception e) { return "Error:" + e; } }
public string DeleteCart(int id) { try { G2Entities db = new G2Entities(); Cart cart = db.Carts.Find(id); db.Carts.Attach(cart); db.Carts.Remove(cart); db.SaveChanges(); return cart.DatePurchased + "was succesfully deleted"; } catch (Exception e) { return "Error:" + e; } }
public string DeleteProduct(int id) { try { G2Entities db = new G2Entities(); Product product = db.Products.Find(id); db.Products.Attach(product); db.Products.Remove(product); db.SaveChanges(); return product.Name + " was succesfully deleted"; } catch (Exception e) { return "Error:" + e; } }
public string UpdateProductType(int id, ProductType productType) { try { G2Entities db = new G2Entities(); //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; } }
public string UpdateProduct(int id, Product product) { try { G2Entities db = new G2Entities(); 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 { G2Entities db = new G2Entities(); //Fetch object from db Cart p = db.Carts.Find(id); p.DatePurchased = cart.DatePurchased; p.ClientID = cart.ClientID; p.Amount = cart.Amount; p.IsInChart = cart.IsInChart; p.ProductID = cart.ProductID; db.SaveChanges(); return cart.DatePurchased + " was succesfully updated"; } catch (Exception e) { return "Error:" + e; } }
public void UpdateQuantity(int id, int quantity) { G2Entities db = new G2Entities(); Cart p = db.Carts.Find(id); p.Amount = quantity; db.SaveChanges(); }
public void MarkOrdersAsPaid(List<Cart> carts) { G2Entities db = new G2Entities(); if (carts != null) { foreach (Cart cart in carts) { Cart oldCart = db.Carts.Find(cart.ID); oldCart.DatePurchased = DateTime.Now; oldCart.IsInChart = false; } db.SaveChanges(); } }