public void InsertUserInformation(UserInformation info) { GarageDBEntities3 db = new GarageDBEntities3(); db.UserInformation.Add(info); db.SaveChanges(); }
public void UpdateQuantity(int id, int quantity) { GarageDBEntities3 db = new GarageDBEntities3(); Purchase purchase = db.Purchase.Find(id); purchase.Amount = quantity; db.SaveChanges(); }
public UserInformation GetUserInformation(string guId) { GarageDBEntities3 db = new GarageDBEntities3(); UserInformation info = (from x in db.UserInformation where x.GUID == guId select x).FirstOrDefault(); return(info); }
public string InsertProductType(ProductType productType) { try { GarageDBEntities3 db = new GarageDBEntities3(); db.ProductType.Add(productType); db.SaveChanges(); return(productType.Name + " was succesfully inserted"); } catch (Exception e) { return("Error" + e); } }
public string InsertPurchase(Purchase purchase) { try { GarageDBEntities3 db = new GarageDBEntities3(); db.Purchase.Add(purchase); db.SaveChanges(); return(purchase.Date + " was succesfully inserted"); } catch (Exception e) { return("Error" + e); } }
public Product GetProduct(int id) { try { using (GarageDBEntities3 db = new GarageDBEntities3()) { Product product = db.Product.Find(id); return(product); } } catch (Exception) { return(null); } }
public void MarkOrderAsPaid(List <Purchase> purchases) { GarageDBEntities3 db = new GarageDBEntities3(); if (purchases != null) { foreach (Purchase purchase in purchases) { Purchase oldpurchase = db.Purchase.Find(purchase.ID); oldpurchase.Date = DateTime.Now; oldpurchase.IsInCart = false; } db.SaveChanges(); } }
public List <Product> GetAllProducts() { try { using (GarageDBEntities3 db = new GarageDBEntities3()) { List <Product> products = (from x in db.Product select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public List <Product> GetProductsByType(int typeid) { try { using (GarageDBEntities3 db = new GarageDBEntities3()) { List <Product> products = (from x in db.Product where x.TypeID == typeid select x).ToList(); return(products); } } catch (Exception) { return(null); } }
public List <Purchase> GetOrdersInPurchase(string userId) { int i = 0; if (!Int32.TryParse(userId, out i)) { i = 1; } GarageDBEntities3 db = new GarageDBEntities3(); List <Purchase> orders = (from x in db.Purchase where x.CustomerID == i && x.IsInCart orderby x.Date select x).ToList(); return(orders); }
public string DeleteProductType(int id) { try { GarageDBEntities3 db = new GarageDBEntities3(); ProductType productType = db.ProductType.Find(id); db.ProductType.Attach(productType); db.ProductType.Attach(productType); db.SaveChanges(); return(productType.Name + " was successully deleted"); } catch (Exception e) { return("Error" + e); } }
public string DeletePurchase(int id) { try { GarageDBEntities3 db = new GarageDBEntities3(); Purchase purchase = db.Purchase.Find(id); db.Purchase.Attach(purchase); db.Purchase.Remove(purchase); db.SaveChanges(); return(purchase.Date + " was successully deleted"); } catch (Exception e) { return("Error" + e); } }
public string UpdateProductType(int id, ProductType productType) { try { GarageDBEntities3 db = new GarageDBEntities3(); ProductType p = db.ProductType.Find(id); p.Name = productType.Name; db.SaveChanges(); return(productType.Name + " was successfully updated"); } catch (Exception e) { return("Error" + e); } }
public int GetAmountOfOrders(string userId) { try { int i = 0; if (!Int32.TryParse(userId, out i)) { i = 1; } GarageDBEntities3 db = new GarageDBEntities3(); int amount = (from x in db.Purchase where x.CustomerID == i && x.IsInCart select x.Amount).Sum(); return(amount); } catch { return(0); } }
public string UpdateProduct(int id, Product product) { try { GarageDBEntities3 db = new GarageDBEntities3(); Product p = db.Product.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); } }
public string UpdatePurchase(int id, Purchase purchase) { try { GarageDBEntities3 db = new GarageDBEntities3(); Purchase p = db.Purchase.Find(id); p.Date = purchase.Date; p.CustomerID = purchase.CustomerID; p.Amount = purchase.Amount; p.IsInCart = purchase.IsInCart; p.ProductID = purchase.ProductID; db.SaveChanges(); return(purchase.Date + " was successfully updated"); } catch (Exception e) { return("Error" + e); } }