コード例 #1
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void BatchCreateItems(IEnumerable<Item> items)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Items.AddRange(items);
         context.SaveChanges();
     }
 }
コード例 #2
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void BatchUpdateItem(IEnumerable<Item> items)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         items.Select(i => context.Entry(i).State = System.Data.Entity.EntityState.Modified);
         context.Items.AddRange(items);
         context.SaveChanges();
     }
 }
コード例 #3
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
        public void BatchUpdateShipmentFee(IEnumerable<ShipmentFee> fee)
        {
            using (var context = new GiaikhatNgocMaiEntities())
            {
                var newFeeList = fee.OrderBy(i => i.Id).ToList();
                var dbFeeList = context.ShipmentFees.OrderBy(i => i.Id);
                foreach (var item in dbFeeList)
                {
                    var existedFee = newFeeList.SingleOrDefault(i => i.Id == item.Id);
                    if (existedFee == null)
                    {
                        context.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                        continue;
                    }

                    context.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    newFeeList.Remove(existedFee);
                }
                newFeeList.Select(i => context.Entry(i).State = System.Data.Entity.EntityState.Added);
                context.SaveChanges();
            }
        }
コード例 #4
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
        public void BatchUpdateUnit(IEnumerable<Unit> units)
        {
            using (var context = new GiaikhatNgocMaiEntities())
            {
                var newUnits = units.OrderBy(i => i.Id).ToList();
                var dbUnits = context.Units.OrderBy(i => i.Id);
                foreach (var u in dbUnits)
                {
                    var existedUnit = newUnits.SingleOrDefault(i => i.Id == u.Id);
                    if (existedUnit == null)
                    {
                        context.Entry(u).State = System.Data.Entity.EntityState.Deleted;
                        continue;
                    }

                    context.Entry(u).State = System.Data.Entity.EntityState.Modified;
                    newUnits.Remove(existedUnit);
                }
                newUnits.Select(i => context.Entry(i).State = System.Data.Entity.EntityState.Added);
                context.SaveChanges();
            }
        }
コード例 #5
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public Item GetItem(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var item = context.Items.Include("Category").Include("ItemPhotoes").SingleOrDefault(i => i.Id == id);
         return item;
     }
 }
コード例 #6
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public User GetUser(string email, string password)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         var user = context.Users.Include("Orders").SingleOrDefault(u => u.Email == email && u.Password == password);
         return user;
     }
 }
コード例 #7
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public Banner GetBanner(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var banner = context.Banners.SingleOrDefault(i => i.Id == id);
         return banner;
     }
 }
コード例 #8
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void UpdatePolicyNews(SiteNew news)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         news.DateUpdated = DateTime.Now;
         context.Entry(news).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #9
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void UpdateUser(User user)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbUser = context.Users.SingleOrDefault(u => u.Id == user.Id);
         if (dbUser == null) throw new NullReferenceException("Can not found user " + user.UserName);
         context.Entry(user).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #10
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void UpdateCustomer(Customer customer)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcustomer = context.Customers.SingleOrDefault(i => i.Id == customer.Id);
         if (dbcustomer == null) throw new NullReferenceException();
         dbcustomer.RecieveInfo = customer.RecieveInfo;
         dbcustomer.CustomerName = customer.CustomerName;
         dbcustomer.CustomerPassword = customer.CustomerPassword;
         dbcustomer.CustomerPoint = customer.CustomerPoint;
         dbcustomer.CustomerPhone = customer.CustomerPhone;
         dbcustomer.ShipAddress = customer.ShipAddress;
         dbcustomer.ShipDistrict = customer.ShipDistrict;
         context.Entry(dbcustomer).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #11
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void UpdateNews(News news)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Entry(news).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #12
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<Customer> GetCustomers(Func<Customer,bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcus = context.Customers.Where(predicate).ToArray();
         return dbcus;
     }
 }
コード例 #13
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<User> GetUsers(Func<User, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var users = context.Users.Where(predicate).ToArray();
         return users;
     }
 }
コード例 #14
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<Category> GetCategories(Func<Category, bool> predicate, bool passbyItem = true)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcate = passbyItem ? context.Categories.Include("Category1").Where(predicate).ToArray() :
                                   context.Categories.Include("Category1").Include("Items").Where(predicate).ToArray();
         return dbcate;
     }
 }
コード例 #15
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public Customer GetCustomer(Func<Customer, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcus = context.Customers.Include("Orders").Where(predicate).FirstOrDefault();
         return dbcus;
     }
 }
コード例 #16
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public Customer GetCustomer(string email, string password)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcus = context.Customers.SingleOrDefault(i => i.CustomerEmail == email && i.CustomerPassword == password);
         return dbcus;
     }
 }
コード例 #17
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<News> GetConditionalNews(Func<News, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var newsList = context.News.Where(predicate).ToArray();
         return newsList;
     }
 }
コード例 #18
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public Category GetCategory(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcate = context.Categories.Include("Category1").Include("Items").SingleOrDefault(i => i.Id == id);
         return dbcate;
     }
 }
コード例 #19
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void UpdateCategory(Category category)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Categories.Add(category);
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #20
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<Item> GetItems(Func<Item, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var items = context.Items.Include("Category").Where(predicate).ToArray();
         return items;
     }
 }
コード例 #21
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void UpdateItem(Item item)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         context.Items.Add(item);
         context.SaveChanges();
     }
 }
コード例 #22
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public News GetNews(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var news = context.News.Include("User").SingleOrDefault(i => i.Id == id);
         return news;
     }
 }
コード例 #23
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
        public void UpdateOrder(Order order)
        {
            using (var context = new GiaikhatNgocMaiEntities())
            {
                var dbItemList = context.OrderDetails.Where(i => i.OrderId == order.Id).OrderBy(i => i.Id);
                var newItemList = order.OrderDetails.OrderBy(i => i.Id).ToList();
                foreach (var dt in dbItemList)
                {
                    var existedItem = newItemList.SingleOrDefault(i => i.Id == dt.Id);
                    if (existedItem == null)
                    {
                        context.Entry(dt).State = System.Data.Entity.EntityState.Deleted;
                        continue;
                    }

                    context.Entry(dt).State = System.Data.Entity.EntityState.Modified;
                    newItemList.Remove(existedItem);
                }

                newItemList.Select(i => context.Entry(i).State = System.Data.Entity.EntityState.Added);

                context.Entry(order).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
コード例 #24
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public Order GetOrder(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var order = context.Orders.Include("OrderDetails").Include("User").Include("Customer").SingleOrDefault(i => i.Id == id);
         return order;
     }
 }
コード例 #25
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public SiteNew GetPolicyNews(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var policy = context.SiteNews.SingleOrDefault(i => i.Id == id);
         return policy;
     }
 }
コード例 #26
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<ShipmentFee> GetShipmentFees()
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var feeList = context.ShipmentFees.ToArray();
         return feeList;
     }
 }
コード例 #27
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public void UploadPhotoes(IEnumerable<ItemPhoto> photoes)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.ItemPhotoes.AddRange(photoes);
         context.SaveChanges();
     }
 }
コード例 #28
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<Unit> GetUnits()
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var units = context.Units.ToArray();
         return units;
     }
 }
コード例 #29
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public int CreateBanner(Banner banner)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Banners.Add(banner);
         context.SaveChanges();
         return banner.Id;
     }
 }
コード例 #30
0
ファイル: GKNMDBContext.cs プロジェクト: meothailand/GKNMShop
 public IEnumerable<SiteNew> GetAllPolicyNews()
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var policies = context.SiteNews.ToArray();
         return policies;
     }
 }