Esempio n. 1
0
 public void BatchCreateItems(IEnumerable<Item> items)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Items.AddRange(items);
         context.SaveChanges();
     }
 }
Esempio n. 2
0
 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();
     }
 }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
 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;
     }
 }
Esempio n. 6
0
 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;
     }
 }
Esempio n. 7
0
 public Banner GetBanner(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var banner = context.Banners.SingleOrDefault(i => i.Id == id);
         return banner;
     }
 }
Esempio n. 8
0
 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();
     }
 }
Esempio n. 9
0
 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();
     }
 }
Esempio n. 10
0
 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();
     }
 }
Esempio n. 11
0
 public void UpdateNews(News news)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Entry(news).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Esempio n. 12
0
 public IEnumerable<Customer> GetCustomers(Func<Customer,bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcus = context.Customers.Where(predicate).ToArray();
         return dbcus;
     }
 }
Esempio n. 13
0
 public IEnumerable<User> GetUsers(Func<User, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var users = context.Users.Where(predicate).ToArray();
         return users;
     }
 }
Esempio n. 14
0
 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;
     }
 }
Esempio n. 15
0
 public Customer GetCustomer(Func<Customer, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var dbcus = context.Customers.Include("Orders").Where(predicate).FirstOrDefault();
         return dbcus;
     }
 }
Esempio n. 16
0
 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;
     }
 }
Esempio n. 17
0
 public IEnumerable<News> GetConditionalNews(Func<News, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var newsList = context.News.Where(predicate).ToArray();
         return newsList;
     }
 }
Esempio n. 18
0
 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;
     }
 }
Esempio n. 19
0
 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();
     }
 }
Esempio n. 20
0
 public IEnumerable<Item> GetItems(Func<Item, bool> predicate)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var items = context.Items.Include("Category").Where(predicate).ToArray();
         return items;
     }
 }
Esempio n. 21
0
 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();
     }
 }
Esempio n. 22
0
 public News GetNews(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var news = context.News.Include("User").SingleOrDefault(i => i.Id == id);
         return news;
     }
 }
Esempio n. 23
0
        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();
            }
        }
Esempio n. 24
0
 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;
     }
 }
Esempio n. 25
0
 public SiteNew GetPolicyNews(int id)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var policy = context.SiteNews.SingleOrDefault(i => i.Id == id);
         return policy;
     }
 }
Esempio n. 26
0
 public IEnumerable<ShipmentFee> GetShipmentFees()
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var feeList = context.ShipmentFees.ToArray();
         return feeList;
     }
 }
Esempio n. 27
0
 public void UploadPhotoes(IEnumerable<ItemPhoto> photoes)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.ItemPhotoes.AddRange(photoes);
         context.SaveChanges();
     }
 }
Esempio n. 28
0
 public IEnumerable<Unit> GetUnits()
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var units = context.Units.ToArray();
         return units;
     }
 }
Esempio n. 29
0
 public int CreateBanner(Banner banner)
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         context.Banners.Add(banner);
         context.SaveChanges();
         return banner.Id;
     }
 }
Esempio n. 30
0
 public IEnumerable<SiteNew> GetAllPolicyNews()
 {
     using (var context = new GiaikhatNgocMaiEntities())
     {
         var policies = context.SiteNews.ToArray();
         return policies;
     }
 }