コード例 #1
0
 public void AddItem(Item item)
 {
     using (var ctx = new ShopsDB())
     {
         ctx.Items.Add(item);
         ctx.SaveChanges();
     }
 }
コード例 #2
0
 public void AddPurchase(PurchaseItem purchaseItem)
 {
     using (var ctx = new ShopsDB())
     {
         ctx.PurchaseItems.Add(purchaseItem);
         ctx.SaveChanges();
         DeletePurchaseFromUserFile(purchaseItem);
     }
 }
コード例 #3
0
        public List <PurchaseItem> GetAllPurchasesOfAllUsers()
        {
            List <PurchaseItem> result = new List <PurchaseItem>();

            using (var context = new ShopsDB())
            {
                result = context.PurchaseItems.ToList();
            }
            return(result);
        }
コード例 #4
0
        //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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }