Exemplo n.º 1
0
        public IEnumerable <ItemDTO> GetByCategory(string categName)
        {
            Category categ = _categoryDal.GetByName(categName);

            List <ItemDTO> itemsDTO = new List <ItemDTO>();

            foreach (var item in _itemDal.GetByFieldName("categoryid", categ.Id.ToString()))
            {
                ItemDTO itemDTO = _mapper.Map <Item, ItemDTO>(item);
                itemsDTO.Add(itemDTO);
            }
            return(itemsDTO);
        }
Exemplo n.º 2
0
        public CategoryDTO GetByName(string name)
        {
            Category    categ    = _categoryDal.GetByName(name);
            CategoryDTO categDTO = _mapper.Map <Category, CategoryDTO>(categ);

            return(categDTO);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加或修改分类信息
        /// <br/>
        /// 清除分类缓存
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public ReturnValue AddOrEdit(Category entity)
        {
            ReturnValue retValue = new ReturnValue();

            if (string.IsNullOrEmpty(entity.Name))
            {
                retValue.IsExists = false;
                retValue.Message = "分类名称";
                return retValue;
            }
            if (string.IsNullOrEmpty(entity.Title))
            {
                retValue.IsExists = false;
                retValue.Message = "分类显示名称";
                return retValue;
            }

            using (CategoryDal dal = new CategoryDal())
            {
                Category old = dal.Get(entity.CategoryID);
                if (old == null)//添加
                {
                    old = dal.GetByName(entity.Name);
                    if (old != null)
                    {
                        retValue.IsExists = false;
                        retValue.Message = "分类已存在";
                        return retValue;
                    }
                    if (dal.Add(entity))
                    {
                        retValue.IsExists = true;
                        retValue.Message = "分类添加成功";
                    }
                    else
                    {
                        retValue.IsExists = false;
                        retValue.Message = "分类添加失败";
                    }
                }
                else
                {
                    if (entity.Name != old.Name)
                    {
                        old = dal.GetByName(entity.Name);
                        if (old != null)
                        {
                            retValue.IsExists = false;
                            retValue.Message = "分类已存在";
                            return retValue;
                        }
                    }
                    if (dal.Modify(entity))
                    {
                        retValue.IsExists = true;
                        retValue.Message = "分类修改成功";
                    }
                    else
                    {
                        retValue.IsExists = false;
                        retValue.Message = "分类修改失败";
                    }
                }
            }
            if (retValue.IsExists)
            {
                ClearCache();
            }
            return retValue;
        }
Exemplo n.º 4
0
 /// <summary>
 /// 根据分类名字获取分类信息
 /// </summary>
 /// <param name="categoryName"></param>
 /// <returns></returns>
 public Category GetName(string categoryName)
 {
     if (string.IsNullOrEmpty(categoryName))
     {
         return null;
     }
     Category entity = this.GetAllCache().Where(x => x.Name == categoryName).SingleOrDefault();
     if (entity == null)
     {
         using (CategoryDal dal = new CategoryDal())
         {
             entity = dal.GetByName(categoryName);
         }
     }
     return entity;
 }