Esempio n. 1
0
 public string Update(int id, string name, int parentId, string icon, string description, string image, string imageBanner,
                      int number, DateTime createdDate, bool status, bool isHome)
 {
     using (var entities = new V308CMSEntities())
     {
         var productType = (from type in entities.ProductType
                            where type.ID == id
                            select type
                            ).FirstOrDefault();
         if (productType != null)
         {
             productType.Name        = name;
             productType.Parent      = parentId;
             productType.Icon        = icon;
             productType.Description = description;
             if (!string.IsNullOrWhiteSpace(image) && productType.Image != image)
             {
                 productType.Image = image;
             }
             if (!string.IsNullOrWhiteSpace(imageBanner) && productType.ImageBanner != imageBanner)
             {
                 productType.ImageBanner = imageBanner;
             }
             productType.Number = number;
             productType.Date   = createdDate;
             productType.Status = status;
             productType.IsHome = isHome;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 2
0
 public List <ProductType> GetListByType(int level, int categoryId = 0)
 {
     using (var entities = new V308CMSEntities())
     {
         if (level == (int)ProductCategoryLevelEnum.Root)
         {
             return((from category in entities.ProductType
                     where category.Parent == 0
                     orderby category.Date.Value descending
                     select category).ToList());
         }
         if (level == (int)ProductCategoryLevelEnum.Parent ||
             level == (int)ProductCategoryLevelEnum.Child)
         {
             if (categoryId > 0)
             {
                 return((from category in entities.ProductType
                         where category.Parent == categoryId
                         orderby category.Date.Value descending
                         select category).ToList());
             }
         }
         return(new List <ProductType>());
     }
 }
Esempio n. 3
0
 public string ChangeState(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         var productTypeItem = (
             from item in entities.ProductType.Include("ListProduct")
             where item.ID == id
             select item
             ).FirstOrDefault();
         if (productTypeItem != null)
         {
             productTypeItem.Status = !productTypeItem.Status;
             entities.SaveChanges();
             if (productTypeItem.ListProduct != null && productTypeItem.ListProduct.Count > 0)
             {
                 foreach (var product in productTypeItem.ListProduct)
                 {
                     product.Status = productTypeItem.Status;
                     entities.SaveChanges();
                 }
             }
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 4
0
 public string ChangeState(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         var categoryItem = (from item in entities.NewsGroups.Include("ListNews")
                             where item.ID == id
                             select item
                             ).FirstOrDefault();
         if (categoryItem != null)
         {
             categoryItem.Status = !categoryItem.Status;
             entities.SaveChanges();
             if (categoryItem.ListNews != null && categoryItem.ListNews.Count > 0)
             {
                 foreach (var news in categoryItem.ListNews)
                 {
                     news.Status = categoryItem.Status;
                     entities.SaveChanges();
                 }
             }
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 5
0
 public string Insert(string name, int parentId, int number, bool state, DateTime date)
 {
     using (var entities = new V308CMSEntities())
     {
         var checkCategory = (from item in entities.NewsGroups
                              where item.Parent == parentId && item.Name == name
                              select item
                              ).FirstOrDefault();
         if (checkCategory == null)
         {
             var newsCategory = new NewsGroups
             {
                 Name   = name,
                 Parent = parentId,
                 Number = number,
                 Status = state,
                 Date   = date
             };
             entities.NewsGroups.Add(newsCategory);
             entities.SaveChanges();
             return("ok");
         }
         return("exists");
     }
 }
Esempio n. 6
0
 public string Insert(NewsGroups category)
 {
     using (var entities = new V308CMSEntities())
     {
         var checkCategory = (from item in entities.NewsGroups
                              where item.Parent == category.Parent && item.Name == category.Name
                              select item
                              ).FirstOrDefault();
         if (checkCategory == null)
         {
             var newsCategory = new NewsGroups
             {
                 Name   = category.Name,
                 Parent = category.Parent,
                 Number = category.Number,
                 Status = category.Status,
                 Date   = category.Date
             };
             entities.NewsGroups.Add(newsCategory);
             entities.SaveChanges();
             return("ok");
         }
         return("exists");
     }
 }
Esempio n. 7
0
 public List <NewsGroups> GetList(int page = 1, int pageSize = 10)
 {
     using (var entities = new V308CMSEntities())
     {
         return((from category in entities.NewsGroups
                 orderby category.Date descending
                 select category).ToList());
     }
 }
Esempio n. 8
0
 public List <NewsGroups> GetList(string keyword = "", int rootId = 0, int parentId = 0, int childId = 0, int page = 1, int pageSize = 10)
 {
     using (var entities = new V308CMSEntities())
     {
         var listGroup = (from newsGroup in entities.NewsGroups.AsEnumerable()
                          orderby newsGroup.ID descending
                          select newsGroup);
         //Loc theo tu khoa
         if (!string.IsNullOrWhiteSpace(keyword))
         {
             var keywordLower = keyword.ToLower();
             listGroup = (from newsGroup in listGroup
                          where newsGroup.Name.ToLower().Contains(keywordLower)
                          orderby newsGroup.ID descending
                          select newsGroup);
         }
         //Loc theo childId
         if (childId > 0)
         {
             return((from newsGroup in listGroup
                     where newsGroup.ID == childId
                     orderby newsGroup.ID descending
                     select newsGroup).ToList());
         }
         //Loc theo ParentId
         if (parentId > 0)
         {
             return((from newsGroup in listGroup
                     where newsGroup.Parent == parentId
                     orderby newsGroup.ID descending
                     select newsGroup).Skip((page - 1) * pageSize).Take(pageSize).ToList());
         }
         //Loc theo RootId
         if (rootId > 0)
         {
             var listParent = (from newsGroup in listGroup
                               where newsGroup.Parent == rootId
                               orderby newsGroup.ID descending
                               select newsGroup.ID).ToList();
             if (listParent.Count > 0)
             {
                 var listParentString = string.Join(",", listParent.ToArray());
                 listGroup = (from newsGroup in listGroup.AsEnumerable()
                              where newsGroup.Parent > 0 && ((newsGroup.Parent == rootId) || (listParentString.Contains(newsGroup.Parent + ",") ||
                                                                                              listParentString.Contains("," + newsGroup.Parent)))
                              orderby newsGroup.ID descending
                              select newsGroup);
             }
             else
             {
                 return(new List <NewsGroups>());
             }
         }
         return(listGroup.Skip((page - 1) * pageSize).Take(pageSize).ToList());
     }
 }
Esempio n. 9
0
 public ProductType Find(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         return((from item in entities.ProductType
                 where item.ID == id
                 select item
                 ).FirstOrDefault());
     }
 }
Esempio n. 10
0
 public NewsGroups Find(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         return((from item in entities.NewsGroups
                 where item.ID == id
                 select item
                 ).FirstOrDefault());
     }
 }
Esempio n. 11
0
 public List <ProductType> GetAllWeb()
 {
     using (var entities = new V308CMSEntities())
     {
         return((from category in entities.ProductType
                 orderby category.Number ascending
                 select category
                 ).ToList());
     }
 }
Esempio n. 12
0
 public List <Contact> GetAll()
 {
     using (var entities = new V308CMSEntities())
     {
         return((from contact in entities.Contact
                 orderby contact.CreatedDate descending
                 select contact
                 ).ToList());
     }
 }
Esempio n. 13
0
 public Contact Find(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         return((from contact in entities.Contact
                 where contact.ID == id
                 select contact
                 ).FirstOrDefault());
     }
 }
Esempio n. 14
0
 public List <NewsGroups> GetListRoot()
 {
     using (var entities = new V308CMSEntities())
     {
         return((from item in entities.NewsGroups
                 where item.Parent == 0
                 orderby item.ID descending
                 select item
                 ).ToList());
     }
 }
Esempio n. 15
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (this.entities != null)
         {
             this.entities.Dispose();
             this.entities = null;
         }
     }
 }
Esempio n. 16
0
 public List <NewsGroups> GetListParent(int rootId = 0)
 {
     using (var entities = new V308CMSEntities())
     {
         return(rootId == 0 ?
                new List <NewsGroups>() :
                (from item in entities.NewsGroups
                 where item.Parent == rootId
                 orderby item.ID descending
                 select item
                ).ToList());
     }
 }
Esempio n. 17
0
 public List <ProductType> GetAll(bool state = true)
 {
     using (var entities = new V308CMSEntities())
     {
         return(state ? (from category in entities.ProductType
                         where category.Status == true
                         orderby category.Date.Value descending
                         select category).ToList() :
                (from category in entities.ProductType
                 orderby category.Date.Value descending
                 select category).ToList());
     }
 }
Esempio n. 18
0
 public List <NewsGroups> GetAll(bool state = true)
 {
     using (var entities = new V308CMSEntities())
     {
         return(state ? (from category in entities.NewsGroups
                         orderby category.Date.Value descending
                         where category.Status == true
                         select category).ToList() :
                (from category in entities.NewsGroups
                 orderby category.Date.Value descending
                 select category).ToList());
     }
 }
Esempio n. 19
0
        public string Delete(int id)
        {
            using (var entities = new V308CMSEntities())
            {
                var productTypeItem = (
                    from item in entities.ProductType.Include("ListProduct")
                    where item.ID == id
                    select item
                    ).FirstOrDefault();
                if (productTypeItem != null)
                {
                    if (productTypeItem.ListProduct != null && productTypeItem.ListProduct.Count > 0)
                    {
                        foreach (var product in productTypeItem.ListProduct)
                        {
                            entities.Product.Remove(product);
                            entities.SaveChanges();
                        }
                    }
                    entities.ProductType.Remove(productTypeItem);
                    entities.SaveChanges();
                    var listSubType = (
                        from item in entities.ProductType.Include("ListProduct")
                        where item.ID == productTypeItem.ID
                        select item
                        ).ToList();
                    if (listSubType.Count > 0)
                    {
                        foreach (var subType in listSubType)
                        {
                            if (subType.ListProduct != null && subType.ListProduct.Count > 0)
                            {
                                foreach (var product in subType.ListProduct)
                                {
                                    entities.Product.Remove(product);
                                    entities.SaveChanges();
                                }
                            }
                            entities.ProductType.Remove(subType);
                            entities.SaveChanges();
                        }
                    }
                    return("ok");
                }
                return("not_exists");
            }

            return("not_exists");
        }
Esempio n. 20
0
 public string Delete(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         var contactDelete = (from contact in entities.Contact
                              where contact.ID == id
                              select contact
                              ).FirstOrDefault();
         if (contactDelete != null)
         {
             entities.Contact.Remove(contactDelete);
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 21
0
 public string Delete(int id)
 {
     using (var entities = new V308CMSEntities())
     {
         var categoryItem = (
             from item in entities.NewsGroups.Include("ListNews")
             where item.ID == id
             select item
             ).FirstOrDefault();
         if (categoryItem != null)
         {
             if (categoryItem.ListNews != null && categoryItem.ListNews.Count > 0)
             {
                 foreach (var news in categoryItem.ListNews)
                 {
                     entities.News.Remove(news);
                     entities.SaveChanges();
                 }
             }
             entities.NewsGroups.Remove(categoryItem);
             entities.SaveChanges();
             var listSubCategory = (
                 from item in entities.NewsGroups.Include("ListNews")
                 where item.ID == categoryItem.ID
                 select item
                 ).ToList();
             if (listSubCategory.Count > 0)
             {
                 foreach (var subCategory in listSubCategory)
                 {
                     if (subCategory.ListNews != null && subCategory.ListNews.Count > 0)
                     {
                         foreach (var news in subCategory.ListNews)
                         {
                             entities.News.Remove(news);
                             entities.SaveChanges();
                         }
                     }
                     entities.NewsGroups.Remove(subCategory);
                     entities.SaveChanges();
                 }
             }
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 22
0
 public string Insert(string fullName, string email, string phone, string message, DateTime createdDate)
 {
     using (var entities = new V308CMSEntities())
     {
         var contact = new Contact
         {
             FullName    = fullName,
             Email       = email,
             Phone       = phone,
             Message     = message,
             CreatedDate = createdDate
         };
         entities.Contact.Add(contact);
         entities.SaveChanges();
         return("ok");
     }
 }
Esempio n. 23
0
 public string Update(int id, string name, int parentId, int number, bool state, DateTime createdDate)
 {
     using (var entities = new V308CMSEntities())
     {
         var newsCategory = (from item in entities.NewsGroups
                             where item.ID == id
                             select item).FirstOrDefault();
         if (newsCategory != null)
         {
             newsCategory.Name   = name;
             newsCategory.Parent = parentId;
             newsCategory.Number = number;
             newsCategory.Status = state;
             newsCategory.Date   = createdDate;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 24
0
 public string Insert(
     string name,
     int parentId,
     string icon,
     string description,
     string image,
     string imageBanner,
     int number,
     DateTime createdDate,
     bool status,
     bool isHome
     )
 {
     using (var entities = new V308CMSEntities())
     {
         var checkProductType = (from type in entities.ProductType
                                 where type.Name == name && type.Parent == parentId
                                 select type
                                 ).FirstOrDefault();
         if (checkProductType == null)
         {
             var newProductType = new ProductType
             {
                 Name        = name,
                 Parent      = parentId,
                 Icon        = icon,
                 Description = description,
                 Image       = image,
                 ImageBanner = imageBanner,
                 Number      = number,
                 Date        = createdDate,
                 Status      = status,
                 IsHome      = isHome
             };
             entities.ProductType.Add(newProductType);
             entities.SaveChanges();
             return("ok");
         }
         return("exists");
     }
 }
Esempio n. 25
0
 public string Update(int id, string fullName, string email, string phone, string message, DateTime createdDate)
 {
     using (var entities = new V308CMSEntities())
     {
         var contactUpdate = (from contact in entities.Contact
                              where contact.ID == id
                              select contact
                              ).FirstOrDefault();
         if (contactUpdate != null)
         {
             contactUpdate.FullName    = fullName;
             contactUpdate.Email       = email;
             contactUpdate.Phone       = phone;
             contactUpdate.Message     = message;
             contactUpdate.CreatedDate = createdDate;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 26
0
 public string Update(NewsGroups category)
 {
     using (var entities = new V308CMSEntities())
     {
         var newsCategory = (from item in entities.NewsGroups
                             where item.ID == category.ID
                             select item
                             ).FirstOrDefault();
         if (newsCategory != null)
         {
             newsCategory.Name   = category.Name;
             newsCategory.Parent = category.Parent;
             newsCategory.Number = category.Number;
             newsCategory.Status = category.Status;
             newsCategory.Date   = category.Date;
             entities.SaveChanges();
             return("ok");
         }
         return("not_exists");
     }
 }
Esempio n. 27
0
        public List <ProductType> GetList(int rootId = 0, int parentId = 0, int childId = 0)
        {
            using (var entities = new V308CMSEntities())
            {
                //Tat ca danh muc
                var allCategory = (from category in entities.ProductType
                                   orderby category.Parent
                                   select category).ToList();
                if (rootId == 0 && parentId == 0 && childId == 0)
                {
                    return(allCategory);
                }
                //Danh muc goc

                //Loc theo danh muc con
                var result = new List <ProductType>();


                if (childId > 0)
                {
                    GetListByParent(2, ref result, allCategory, childId);
                    return(result.Distinct().ToList());
                }
                if (parentId > 0)
                {
                    GetListByParent(1, ref result, allCategory, parentId);
                    return(result.Distinct().ToList());
                }
                if (rootId > 0)
                {
                    GetListByParent(0, ref result, allCategory, rootId);
                    return(result.Distinct().ToList());
                }

                return((from category in result
                        orderby category.Date.Value descending
                        select category).ToList());
            }
        }
Esempio n. 28
0
 public MarketRepository(V308CMSEntities mEntities)
 {
     this.entities = mEntities;
 }
Esempio n. 29
0
 public MarketRepository()
 {
     this.entities = new V308CMSEntities();
 }
Esempio n. 30
0
 public ProductWishlistRepositry(V308CMSEntities entities)
 {
     _entities = entities;
 }