public List <Cart> GetOrdersInCart(string userId) { CO5027Entities db = new CO5027Entities(); List <Cart> orders = (from x in db.Carts where x.ClientID == userId && x.IsInCart orderby x.DatePurchased select x).ToList(); return(orders); }
public void UpdateQuantity(int id, int quantity) { CO5027Entities db = new CO5027Entities(); Cart cart = db.Carts.Find(id); cart.Amount = quantity; db.SaveChanges(); }
public int GetAmountOfOrders(string userId) { try { CO5027Entities db = new CO5027Entities(); int amount = (from x in db.Carts where x.ClientID == userId && x.IsInCart select x.Amount).Sum(); return(amount); } catch { return(0); } }
public string InsertProductType(ProductType productType) { try { CO5027Entities db = new CO5027Entities(); db.ProductTypes.Add(productType); db.SaveChanges(); return(productType.Name + " was successfully inserted."); } catch (Exception e) { return("Error: " + e); } }
public List <Product> GetProductsByType(int typeId) { try { using (CO5027Entities db = new CO5027Entities()) { List <Product> products = (from x in db.Products where x.TypeID == typeId select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public List <Product> GetAllProduct() { try { using (CO5027Entities db = new CO5027Entities()) { List <Product> products = (from x in db.Products select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public Product GetProduct(int id) { try { using (CO5027Entities db = new CO5027Entities()) { Product product = db.Products.Find(id); return(product); } } catch (Exception) { return(null); } }
public string InsertCart(Cart cart) { try { CO5027Entities db = new CO5027Entities(); db.Carts.Add(cart); db.SaveChanges(); return(cart.DatePurchased + ": successfully added."); } catch (Exception e) { return("Error: " + e); } }
public void MarkOrdersAsPaid(List <Cart> carts) { CO5027Entities db = new CO5027Entities(); if (carts != null) { foreach (Cart cart in carts) { Cart oldCart = db.Carts.Find(cart.ID); oldCart.DatePurchased = DateTime.Now; oldCart.IsInCart = false; } db.SaveChanges(); } }
public string UpdateProductType(int id, ProductType productType) { try { CO5027Entities db = new CO5027Entities(); ProductType p = db.ProductTypes.Find(id); p.Name = productType.Name; return(productType.Name + " was successfully updated."); } catch (Exception e) { return("Error: " + e); } }
public string DeleteProductType(int id) { try { CO5027Entities db = new CO5027Entities(); ProductType productType = db.ProductTypes.Find(id); db.ProductTypes.Attach(productType); db.ProductTypes.Remove(productType); db.SaveChanges(); return(productType.Name + " was successfully deleted."); } catch (Exception e) { return("Error: " + e); } }
public string DeleteCart(int id) { try { CO5027Entities db = new CO5027Entities(); Cart cart = db.Carts.Find(id); db.Carts.Attach(cart); db.Carts.Remove(cart); db.SaveChanges(); return(cart.DatePurchased + ": successfully deleted."); } catch (Exception e) { return("Error: " + e); } }
public string UpdateCart(int id, Cart cart) { try { CO5027Entities db = new CO5027Entities(); 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; return(cart.DatePurchased + ": successfully updated."); } catch (Exception e) { return("Error: " + e); } }
public string UpdateProduct(int id, Product product) { try { CO5027Entities db = new CO5027Entities(); 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 successfully updated."); } catch (Exception e) { return("Error: " + e); } }