public static int Update(AisleProduct aisleProduct) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblAisleProduct updatedrow = dc.tblAisleProducts.FirstOrDefault(ap => ap.Id == aisleProduct.Id); if (updatedrow != null) { updatedrow.Id = aisleProduct.Id; updatedrow.AisleId = aisleProduct.AisleId; updatedrow.ProductId = aisleProduct.ProductId; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Delete(Guid aisleId, Guid productId) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblAisleProduct deletedrow = dc.tblAisleProducts .FirstOrDefault(u => u.AisleId == aisleId && u.ProductId == productId); if (deletedrow != null) { dc.tblAisleProducts.Remove(deletedrow); return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Delete(Guid id) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblUserProduct row = dc.tblUserProducts .FirstOrDefault(up => up.Id == id); if (row != null) { dc.tblUserProducts.Remove(row); return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(Layout layout) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblLayout updatedrow = dc.tblLayouts.FirstOrDefault(l => l.Id == layout.Id); if (updatedrow != null) { updatedrow.StoreId = layout.StoreId; updatedrow.Title = layout.Title; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(UserProduct userProduct) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblUserProduct tbluserProduct = dc.tblUserProducts.FirstOrDefault(up => up.Id == userProduct.Id); if (tbluserProduct != null) { tbluserProduct.UserId = userProduct.UserId; tbluserProduct.ProductId = userProduct.ProductId; tbluserProduct.Amount = userProduct.Amount; tbluserProduct.Notes = userProduct.Notes; tbluserProduct.InCart = userProduct.InCart; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Insert(Product product) { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblProduct newRow = new tblProduct(); newRow.Id = Guid.NewGuid(); newRow.Title = product.Title; dc.tblProducts.Add(newRow); return(dc.SaveChanges()); } }
public static int Insert(Aisle aisle) { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblAisle tblaisle = new tblAisle(); tblaisle.Id = Guid.NewGuid(); tblaisle.LayoutId = aisle.LayoutId; tblaisle.Number = aisle.Number; tblaisle.Lineup = aisle.Lineup; aisle.Id = tblaisle.Id; dc.tblAisles.Add(tblaisle); return(dc.SaveChanges()); } }
public static int Delete(Guid id) { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblUser deleterow = dc.tblUsers.FirstOrDefault(c => c.Id == id); if (deleterow != null) { dc.tblUsers.Remove(deleterow); return(dc.SaveChanges()); } else { throw new Exception("Row was not found!!!"); } } }
public static int UpdateGroceryList(User user) { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblUser tbluser = dc.tblUsers.FirstOrDefault(u => u.Id == u.Id); if (tbluser != null) { tbluser.FirstName = user.FirstName; tbluser.LastName = user.LastName; tbluser.Email = user.Email; tbluser.UserPass = user.UserPass; // Delete all the tblUserProduct rows and add back in. var existing = dc.tblUserProducts.Where(up => up.UserId == user.Id); dc.tblUserProducts.RemoveRange(existing); List <tblUserProduct> tblUserProducts = new List <tblUserProduct>(); // Also make sense of the tblUserProducts foreach (UserProduct up in user.GroceryList) { tblUserProduct tbluserproduct = new tblUserProduct(); tbluserproduct.Id = Guid.NewGuid(); tbluserproduct.UserId = user.Id; tbluserproduct.ProductId = up.Id; tbluserproduct.InCart = up.InCart; tbluserproduct.Amount = up.Amount; tbluserproduct.Notes = up.Notes; tblUserProducts.Add(tbluserproduct); } dc.tblUserProducts.AddRange(tblUserProducts); int result = dc.SaveChanges(); return(result); } else { throw new Exception("Row was not found!!"); } } }
public static int Update(Aisle aisle) { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblAisle tblaisle = dc.tblAisles.FirstOrDefault(a => a.Id == aisle.Id); if (tblaisle != null) { tblaisle.LayoutId = aisle.LayoutId; tblaisle.Number = aisle.Number; tblaisle.Lineup = aisle.Lineup; return(dc.SaveChanges()); } else { return(0); } } }
public static bool Insert(Store store) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblStore newrow = new tblStore(); newrow.Id = Guid.NewGuid(); newrow.Title = store.Title; dc.tblStores.Add(newrow); dc.SaveChanges(); store.Id = newrow.Id; return(true); } } catch (Exception ex) { throw ex; } }
public static bool Update(User user) { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblUser updatedrow = dc.tblUsers.Where(c => c.Id == user.Id).FirstOrDefault(); if (updatedrow != null) { updatedrow.FirstName = user.FirstName; updatedrow.LastName = user.LastName; updatedrow.Email = user.Email; updatedrow.UserPass = CreateHash(user.UserPass); dc.SaveChanges(); return(true); } else { throw new Exception("Row was not found!"); } } }
public static int Insert(AisleProduct aisleProduct) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblAisleProduct newrow = new tblAisleProduct(); newrow.Id = Guid.NewGuid(); newrow.AisleId = aisleProduct.AisleId; newrow.ProductId = aisleProduct.ProductId; dc.tblAisleProducts.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Delete(Aisle aisle) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblAisle tblaisle = dc.tblAisles.FirstOrDefault(a => a.Id == aisle.Id); if (tblaisle != null) { dc.tblAisles.Remove(tblaisle); return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Insert(UserProduct userProduct) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblUserProduct up = new tblUserProduct(); up.Id = Guid.NewGuid(); up.UserId = userProduct.UserId; up.ProductId = userProduct.ProductId; up.Amount = userProduct.Amount; up.Notes = userProduct.Notes; up.InCart = userProduct.InCart; dc.tblUserProducts.Add(up); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Delete(Guid id) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblAisle deletedrow = dc.tblAisles.FirstOrDefault(a => a.Id == id); if (deletedrow != null) { dc.tblAisles.Remove(deletedrow); return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(Store store) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblStore updatedrow = dc.tblStores.Where(c => c.Id == store.Id).FirstOrDefault(); if (updatedrow != null) { updatedrow.Title = store.Title; return(dc.SaveChanges()); } else { throw new Exception("Row was not found!"); } } } catch (Exception ex) { throw ex; } }
public static int Insert(Layout layout) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { // Make a new row tblLayout newrow = new tblLayout(); // Set the properties newrow.Id = Guid.NewGuid(); newrow.Title = layout.Title; newrow.StoreId = layout.StoreId; // Insert dc.tblLayouts.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Delete(Layout layout) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblLayout deletedrow = dc.tblLayouts.FirstOrDefault(l => l.Id == layout.Id); if (deletedrow != null) { dc.tblLayouts.Remove(deletedrow); return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(Product product) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { tblProduct updatedrow = dc.tblProducts.Where(p => p.Id == product.Id).FirstOrDefault(); if (updatedrow != null) { updatedrow.Title = product.Title; return(dc.SaveChanges()); } else { throw new Exception("Row was not found"); } } } catch (Exception ex) { throw ex; } }
public static int Insert(User user) { try { using (GroceryGetterEntities dc = new GroceryGetterEntities()) { if (user.FirstName != null) { if (user.LastName != null) { if (user.Email != null) { if (user.UserPass != null) // This can be where we test if the password is long enough { tblUser newrow = new tblUser(); newrow.Id = Guid.NewGuid(); newrow.FirstName = user.FirstName; newrow.LastName = user.LastName; newrow.Email = user.Email; newrow.UserPass = CreateHash(user.UserPass); user.Id = newrow.Id; dc.tblUsers.Add(newrow); return(dc.SaveChanges()); } else { throw new Exception("Password is required"); } } else { throw new Exception("Email is required"); } } else { throw new Exception("Last Name is required"); } } else { throw new Exception("First name is required"); } } } catch (System.Data.Entity.Validation.DbEntityValidationException e) // Use this to output validation errors in the output window { foreach (var eve in e.EntityValidationErrors) { System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }