public void AddItem(Item item) { using (var ctx = new ShopsDB()) { ctx.Items.Add(item); ctx.SaveChanges(); } }
public void AddPurchase(PurchaseItem purchaseItem) { using (var ctx = new ShopsDB()) { ctx.PurchaseItems.Add(purchaseItem); ctx.SaveChanges(); DeletePurchaseFromUserFile(purchaseItem); } }
public List <PurchaseItem> GetAllPurchasesOfAllUsers() { List <PurchaseItem> result = new List <PurchaseItem>(); using (var context = new ShopsDB()) { result = context.PurchaseItems.ToList(); } return(result); }
//public void updatePurchases(Purchase newPurchase, Purchase oldPurchase) //{ // using (var ctx = new ShopsDB()) // { // ctx.Purchases.Remove(oldPurchase); // ctx.Purchases.Add(newPurchase); // ctx.SaveChanges(); // } //} #endregion #region add to db public void AddUser(User user) { using (var ctx = new ShopsDB()) { ctx.Users.Add(user); ctx.SaveChanges(); } string CSPath = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetCurrentDirectory()).FullName).FullName).FullName; string FolderPath = Path.Combine(CSPath, @"DAL\UsersLists\" + user.Id + ".txt"); if (!File.Exists(FolderPath)) { File.Create(FolderPath); } }
public List <User> GetAllUsers(Func <User, bool> predicate = null) { List <User> result = new List <User>(); using (var context = new ShopsDB()) { if (predicate == null) { result = context.Users.ToList(); } else { result = context.Users.Where(predicate).ToList(); } } return(result); }
public List <PurchaseItem> GetAllPurchases(Func <PurchaseItem, bool> predicate = null) { List <PurchaseItem> result = new List <PurchaseItem>(); using (var context = new ShopsDB()) { if (predicate == null) { result = context.PurchaseItems.Where(purchase => purchase.UserId == currentUser.Id).ToList(); } else { result = context.PurchaseItems.Where(purchase => purchase.UserId == currentUser.Id).Where(predicate).ToList(); } } return(result); }
public List <Item> GetAllItems(Func <Item, bool> predicate = null) { List <Item> result = new List <Item>(); using (var context = new ShopsDB()) { if (predicate == null) { result = context.Items.ToList(); } else { result = context.Items.Where(predicate).ToList(); } } return(result); }