public void InsertUserInformstion(UserInformation info) { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); db.UserInformations.Add(info); db.SaveChanges(); }
public void UpdateQuantity(int id, int quantity) { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); Cart cart = db.Carts.Find(id); cart.Amount = quantity; db.SaveChanges(); }
public UserInformation GetUserInformation(string guId) { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); UserInformation info = (from x in db.UserInformations where x.GUID == guId select x).FirstOrDefault(); return(info); }
public List <Cart> GetOrdersInCart(string userId) { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); List <Cart> orders = (from x in db.Carts where x.ClientID == userId && x.IsInCart orderby x.DatePurchased select x).ToList(); return(orders); }
public List <Product> GetAllProducts() { try { using (MyMobileShopDBEntities db = new MyMobileShopDBEntities()) { List <Product> products = (from x in db.Products select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public Product GetProduct(int id) { try { using (MyMobileShopDBEntities db = new MyMobileShopDBEntities()) { Product product = db.Products.Find(id); return(product); } } catch (Exception) { return(null); } }
public List <Product> ProductsByType(int typeId) { try { using (MyMobileShopDBEntities db = new MyMobileShopDBEntities()) { List <Product> products = (from x in db.Products where x.TypeID == typeId select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public string InsertProduct(Product product) { try { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); db.Products.Add(product); db.SaveChanges(); return(product.Name + "was succesfully inserted"); } catch (Exception e) { return("Error:" + e); } }
public string InsertCart(Cart cart) { try { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); db.Carts.Add(cart); db.SaveChanges(); return(cart.DatePurchased + " was succesfully inserted"); } catch (Exception e) { return("Error:" + e); } }
public int GetAmountOfOrders(string userId) { try { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); int amount = (from x in db.Carts where x.ClientID == userId && x.IsInCart select x.Amount).Sum(); return(amount); } catch { return(0); } }
public void MarkOrdersAsPaid(List <Cart> carts) { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); 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 DeleteProduct(int id) { try { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); 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 DeleteCart(int id) { try { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); 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 UpdateProductType(int id, ProductType productType) { try { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); //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 { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); //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 { MyMobileShopDBEntities db = new MyMobileShopDBEntities(); //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 + " was succesfully updated"); } catch (Exception e) { return("Error:" + e); } }