示例#1
0
        public IEnumerable <shCategory> DanhSachCategory()
        {
            shCategoryService _category = new shCategoryService();

            IEnumerable <shCategory> dsCategory = _category.FindList()
                                                  .Where(x => x.Status == true)
                                                  .OrderBy(x => x.CategoryId);

            return(dsCategory);
        }
示例#2
0
        public IEnumerable <shCategory> DanhSachCategory_ByParentId(string ParentId)
        {
            shCategoryService _category = new shCategoryService();

            IEnumerable <shCategory> dsCategory = _category.FindList()
                                                  .Where(x => x.Status == true &&
                                                         x.ParentId == ParentId)
                                                  .OrderBy(x => x.CategoryId);

            return(dsCategory);
        }
示例#3
0
        public void UpdateTopHot(string CategoryGuid, bool TopHot)
        {
            shCategoryService _category = new shCategoryService();
            shCategory        category  = _category.FindByKey(CategoryGuid);

            if (category != null)
            {
                category.TopHot = TopHot;
                _category.Update(category);
            }
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="CategoryGuid"></param>
        /// <param name="CategoryName"></param>
        /// <returns></returns>
        public string TaoLinkUrl(string CategoryGuid, string CategoryName)
        {
            string            controller = CommonHelper.GetUrlTheFirst(CategoryGuid);
            shCategoryService _category  = new shCategoryService();
            string            Metatitle  = _category.CategoryMetaTitle(controller);

            int    idex = Metatitle.LastIndexOf("/");
            string meta = Metatitle.Substring(0, idex);

            meta += "/" + StringHelper.ToUnsignString(CategoryName).ToLower();

            return(Metatitle);
        }
示例#5
0
        public string CategoryName(string CategoryGuid)
        {
            if (!string.IsNullOrWhiteSpace(CategoryGuid))
            {
                shCategoryService _category = new shCategoryService();
                shCategory        category  = _category.FindByKey(CategoryGuid);

                if (category != null)
                {
                    return(category.CategoryName);
                }
                return(string.Empty);
            }
            return(string.Empty);
        }
示例#6
0
        public string CategoryName(int?CategoryId)
        {
            if (CategoryId.HasValue)
            {
                shCategoryService _category = new shCategoryService();
                shCategory        category  = _category.FindByKey(CategoryId);

                if (category != null)
                {
                    return(category.CategoryName);
                }
                return(string.Empty);
            }
            return(string.Empty);
        }
示例#7
0
        public string CategoryMetaTitle(string CategoryGuid)
        {
            string metatitle = string.Empty;

            if (!string.IsNullOrWhiteSpace(CategoryGuid))
            {
                shCategoryService _category = new shCategoryService();
                shCategory        category  = _category.FindByKey(CategoryGuid);

                if (category != null)
                {
                    return(category.MetaTitle);
                }
                return(metatitle);
            }
            return(metatitle);
        }
示例#8
0
        public IEnumerable <shProduct> DanhSachProduct_ByUserId(int?UserId)
        {
            List <shProduct> dsProduct = new List <shProduct>();

            if (UserId.HasValue)
            {
                shCategoryService        _category = new shCategoryService();
                IEnumerable <shCategory> dsParent  = _category.FindList().Where(x => x.UserId == UserId);
                foreach (var parent in dsParent)
                {
                    if (!string.IsNullOrEmpty(parent.ParentId) || !string.IsNullOrWhiteSpace(parent.ParentId))   // là danh mục con.. Chỉ được load danh mục con
                    {
                        dsProduct.AddRange(DanhSachProduct_TheoDanhMuc(parent.CategoryGuid));
                    }
                    else  // là danh mục cha   => tìm các danh muc con
                    {
                        dsProduct.AddRange(DanhSachProduct_TheoDanhMuc(parent.CategoryGuid));

                        IEnumerable <shCategory> dsChild = _category.DanhSachCategory_ByParentId(parent.CategoryGuid);
                        foreach (var child in dsChild)
                        {
                            if (child.UserId.HasValue)
                            {
                                if (child.UserId == UserId)
                                {
                                    dsProduct.AddRange(DanhSachProduct_TheoDanhMuc(child.CategoryGuid));
                                }
                            }
                            else
                            {
                                dsProduct.AddRange(DanhSachProduct_TheoDanhMuc(child.CategoryGuid));
                            }
                        }
                    }
                }
            }
            else
            {
                dsProduct = DanhSachProduct().ToList();
            }

            return(dsProduct.OrderBy(x => x.ProductId));
        }
示例#9
0
        public IEnumerable <shCategory> GetCategoryByParentId(string CategoryGuid)
        {
            shCategoryService _categories = new shCategoryService();

            return(_categories.FindList().Where(x => x.ParentId == CategoryGuid));
        }
示例#10
0
        public shCategory ThemMoi_HieuChinhCategory(string CategoryGuid, int?CategoryId, string CategoryName, string ParentId, int?UserId, bool?Status, DateTime?CreatedDate, string MetaTitle, string Description, int?SortOrder, string FileName)
        {
            shCategoryService _category = new shCategoryService();
            shCategory        category  = new shCategory();

            if (!string.IsNullOrWhiteSpace(CategoryGuid))
            {
                category = _category.FindByKey(CategoryGuid);
            }
            else
            {
                CategoryGuid = GuidUnique.getInstance().GenerateUnique();
            }

            try
            {
                // Your code...
                // Could also be before try if you know the exception occurs in SaveChanges
                category.CategoryGuid = CategoryGuid;
                category.CategoryName = CategoryName;
                category.ParentId     = ParentId;
                category.UserId       = UserId;
                category.Status       = Status;
                category.CreatedDate  = CreatedDate;

                category.Description = Description;
                category.SortOrder   = SortOrder;

                if (string.IsNullOrWhiteSpace(ParentId) || string.IsNullOrEmpty(ParentId))
                {
                    category.MetaTitle = "/" + StringHelper.ToUnsignString(CategoryName).ToLower()
                                         + "/" + StringHelper.ToUnsignString(Description.Substring(0, 60)).ToLower();
                }
                else
                {
                    category.MetaTitle = TaoLinkUrl(CategoryGuid, CategoryName);
                }
                category.FileName = FileName;

                if (category.CategoryId > 0)
                {
                    _category.Update(category);
                }
                else
                {
                    _category.Insert(category);
                }

                return(category);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                return(category);
            }
        }