コード例 #1
0
 public void AddItems(List <Item> items)
 {
     using (PriceCompareContext db = new PriceCompareContext())
     {
         db.Items.AddRange(items);
         db.SaveChanges();
     }
 }
コード例 #2
0
 public void AddItem(Item item)
 {
     using (PriceCompareContext db = new PriceCompareContext())
     {
         db.Items.Add(item);
         db.SaveChanges();
     }
 }
コード例 #3
0
 public void DeleteAll()
 {
     using (PriceCompareContext db = new PriceCompareContext())
     {
         db.Items.RemoveRange(db.Items);
         db.Users.RemoveRange(db.Users);
         db.Stores.RemoveRange(db.Stores);
         db.SaveChanges();
     }
 }
コード例 #4
0
 public void AddStore(Store store)
 {
     using (PriceCompareContext db = new PriceCompareContext())
     {
         if (db.Stores.Where(dbStore => dbStore.Name.Equals(store.Name) && dbStore.ChainStoreName.Equals(store.ChainStoreName)).ToList().Count == 0)
         {
             db.Stores.Add(store);
             db.SaveChanges();
         }
     }
 }
コード例 #5
0
 public void AddUser(User user)
 {
     using (PriceCompareContext db = new PriceCompareContext())
     {
         if (String.IsNullOrEmpty(user.Name) || String.IsNullOrEmpty(user.Password))
         {
             throw new ArgumentException("Please enter name and password!");
         }
         if (db.Users.Where(dbUser => dbUser.Name == user.Name).ToList().Count != 0)
         {
             throw new ArgumentException($"There is user with the name {user.Name}!");
         }
         db.Users.Add(user);
         db.SaveChanges();
     }
 }