예제 #1
0
        /// <summary>
        /// 保存商品分类
        /// </summary>
        public string SaveItemCategory()
        {
            var responseData = new ResponseData();

            int    modelTypeId   = (Int32)Utils.GetIntVal(FormatParamValue(Request("modelTypeId")));
            string modelTypeName = FormatParamValue(Request("modelTypeName"));

            if (modelTypeId == 0)
            {
                responseData.success = false;
                responseData.msg     = "模板ID不能为空";
                return(responseData.ToJSON());
            }

            if (string.IsNullOrEmpty(modelTypeName))
            {
                responseData.success = false;
                responseData.msg     = "模板名称不能为空";
                return(responseData.ToJSON());
            }

            var itemCategory = this.CurrentContext.Request["categoryList"].DeserializeJSONTo <List <ItemCategoryEntity> >();

            if (itemCategory != null && itemCategory.Count > 0)
            {
                //分组ID
                var groupId         = itemCategory.FirstOrDefault().groupId;
                var adAreaBll       = new MHAdAreaBLL(this.CurrentUserInfo);
                var categoryAreaBll = new MHCategoryAreaBLL(this.CurrentUserInfo);
                var homeBll         = new MobileHomeBLL(this.CurrentUserInfo);
                var homeList        = homeBll.QueryByEntity(new MobileHomeEntity {
                    CustomerId = this.CurrentUserInfo.ClientID
                }, null);
                var homeId = homeList.FirstOrDefault().HomeId;

                if (homeList != null && homeList.Length > 0)
                {
                    //判断groupId是否为空,为空则新增,不为空则更新
                    //如果新增,则传入 模板ID,修改则不需要传入模板ID
                    if (groupId == 0 || string.IsNullOrEmpty(groupId.ToString()))
                    {
                        //查找表中最大的groupid
                        groupId = categoryAreaBll.GetMaxGroupId();
                        //在此基础上对groupid+1
                        groupId++;
                        InsertItemCategory(itemCategory, groupId);
                    }
                    else
                    {
                        UpdateItemCategory(itemCategory);
                    }

                    var mHCategoryAreaGroup = new MHCategoryAreaGroupBLL(this.CurrentUserInfo);
                    var categoryAreaGroup   = mHCategoryAreaGroup.QueryByEntity(new MHCategoryAreaGroupEntity()
                    {
                        GroupValue = groupId,
                        CustomerID = this.CurrentUserInfo.ClientID
                    }, null);

                    var categoryAreaGroupEntity = new MHCategoryAreaGroupEntity()
                    {
                        ModelTypeId = modelTypeId,
                        ModelName   = modelTypeName,
                        GroupValue  = groupId,
                        CustomerID  = this.CurrentUserInfo.ClientID
                    };
                    if (categoryAreaGroup == null || !categoryAreaGroup.Any())
                    {
                        categoryAreaGroupEntity.GroupId = mHCategoryAreaGroup.GetMaxGroupId();
                        mHCategoryAreaGroup.Create(categoryAreaGroupEntity);
                    }
                    else
                    {
                        categoryAreaGroupEntity.GroupId = categoryAreaGroup[0].GroupId;
                        mHCategoryAreaGroup.Update(categoryAreaGroupEntity);
                    }
                }
                else
                {
                    responseData.success = false;
                    responseData.msg     = "没有查询到对应首页主表的数据";
                    return(responseData.ToJSON());
                }



                #region 返回商品分类数据

                var content = new CategoryEntity();  //商品分类

                //获取分组ID
                content.modelTypeId   = modelTypeId;
                content.modelTypeName = modelTypeName;
                content.groupId       = groupId.ToString();
                content.itemList      = new List <ItemEntity>();

                var dsItem = adAreaBll.GetItemList(content.groupId, homeId.ToString());
                if (dsItem != null && dsItem.Tables.Count > 0 && dsItem.Tables[0].Rows.Count > 0)
                {
                    content.itemList = DataTableToObject.ConvertToList <ItemEntity>(dsItem.Tables[0]);
                }

                #endregion

                responseData.success = true;
                responseData.data    = content;
                return(responseData.ToJSON());
            }
            else
            {
                responseData.success = false;
                responseData.data    = "查无数据";
                return(responseData.ToJSON());
            }
        }
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 /// <param name="pTran">事务实例,可为null,如果为null,则不使用事务来更新</param>
 public void Update(MHCategoryAreaGroupEntity pEntity, IDbTransaction pTran)
 {
     _currentDAO.Update(pEntity, pTran);
 }
 /// <summary>
 /// 创建一个新实例
 /// </summary>
 /// <param name="pEntity">实体实例</param>
 public void Create(MHCategoryAreaGroupEntity pEntity)
 {
     _currentDAO.Create(pEntity);
 }
 /// <summary>
 /// 分页根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public PagedQueryResult <MHCategoryAreaGroupEntity> PagedQueryByEntity(MHCategoryAreaGroupEntity pQueryEntity, OrderBy[] pOrderBys, int pPageSize, int pCurrentPageIndex)
 {
     return(_currentDAO.PagedQueryByEntity(pQueryEntity, pOrderBys, pPageSize, pCurrentPageIndex));
 }
 /// <summary>
 /// 根据实体条件查询实体
 /// </summary>
 /// <param name="pQueryEntity">以实体形式传入的参数</param>
 /// <param name="pOrderBys">排序组合</param>
 /// <returns>符合条件的实体集</returns>
 public MHCategoryAreaGroupEntity[] QueryByEntity(MHCategoryAreaGroupEntity pQueryEntity, OrderBy[] pOrderBys)
 {
     return(_currentDAO.QueryByEntity(pQueryEntity, pOrderBys));
 }
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="pEntity"></param>
 public void Delete(MHCategoryAreaGroupEntity pEntity)
 {
     _currentDAO.Delete(pEntity);
 }