/////// /// <summary> /// Add Product /// </summary> /// <param name="product">AddProduct</param> public void AddProduct(Product product) { var db = new LLDbContext(); db.Products.Add(product); db.SaveChanges(); }
// Add new Member to database public void AddMember(Member member) { var db = new LLDbContext(); db.Members.Add(member); db.SaveChanges(); }
//Method to add content to the database. public void AddContent(Content contentToBeAdded) { LLDbContext contentDB = new LLDbContext(); contentDB.Content.Add(contentToBeAdded); contentDB.SaveChanges(); }
/// <summary> /// Delete Product /// </summary> /// <param name="productID">DeleteProduct</param> /// <returns></returns> public Product DeleteProduct(int productID) { var db = new LLDbContext(); Product dbEntry = db.Products.Find(productID); if (dbEntry != null) { db.Products.Remove(dbEntry); db.SaveChanges(); } return dbEntry; }
// Deletes member from database public Member DeleteMember(int memberId) { var db = new LLDbContext(); Member dbEntry = db.Members.Find(memberId); if (dbEntry != null) { db.Members.Remove(dbEntry); db.SaveChanges(); } return(dbEntry); }
/// <summary> /// Delete Product /// </summary> /// <param name="productID">DeleteProduct</param> /// <returns></returns> public Product DeleteProduct(int productID) { var db = new LLDbContext(); Product dbEntry = db.Products.Find(productID); if (dbEntry != null) { db.Products.Remove(dbEntry); db.SaveChanges(); } return(dbEntry); }
//To be used in conjunction with the UpdateSection method of the Content class. //This will take the content object passed in, attempt to find it in the database, and then update the information in the database. public void SaveContent(Content content) { LLDbContext contentDB = new LLDbContext(); //Find the content in the DB: Content contentToUpdate = contentDB.Content.Find(content.ContentID); if (contentToUpdate != null) { //Edit its existing content to reflect the changes. //Take the entry in the database and make it have the new (updated) text from the object passed in as a parameter. contentToUpdate.CurrentText = content.NewText; } contentDB.SaveChanges(); }
// Saves member information to database public void SaveMember(Member member) { var db = new LLDbContext(); if (member.MemberId == 0) { db.Members.Add(member); } else { // If member exists, it updates information Member dbEntry = db.Members.Find(member.MemberId); if (dbEntry != null) { dbEntry.LoginName = member.LoginName; dbEntry.Password = member.Password; dbEntry.FirstName = member.FirstName; dbEntry.LastName = member.LastName; dbEntry.Email = member.Email; } } db.SaveChanges(); }
/// <summary> /// Save Product /// </summary> /// <param name="product">Save Product</param> public void SaveProduct(Product product) { var db = new LLDbContext(); if (product.ProductID == 0) { db.Products.Add(product); } else { Product dbEntry = db.Products.Find(product.ProductID); if (dbEntry != null) { dbEntry.ProductName = product.ProductName; dbEntry.Price = product.Price; dbEntry.Shipping = product.Shipping; dbEntry.Category = product.Category; dbEntry.Description = product.Description; dbEntry.InStock = product.InStock;//May be disabled if not used?! but must be done in all refd } } db.SaveChanges(); }
/// <summary> /// Save Product /// </summary> /// <param name="product">Save Product</param> public void SaveProduct(Product product) { var db = new LLDbContext(); if (product.ProductID == 0) { db.Products.Add(product); } else { Product dbEntry = db.Products.Find(product.ProductID); if (dbEntry != null) { dbEntry.ProductName = product.ProductName; dbEntry.Price = product.Price; //dbEntry.Shipping = product.Shipping; dbEntry.Category = product.Category; dbEntry.Description = product.Description; dbEntry.InStock = product.InStock;//May be disabled if not used?! but must be done in all refd } } db.SaveChanges(); }