コード例 #1
0
        /// <summary>
        /// 产品图
        /// </summary>
        /// <param name="rowId">行数下标</param>
        /// <param name="sortType">1、上移;2、下移</param>
        /// <returns></returns>
        public JsonResult UpdatePlace(long?productImageId, int rowId, int sortType, string productName, int ImageType, int PagedIndex, int PagedSize)
        {
            var resultModel = new ResultModel();

            resultModel.Messages = new List <string> {
                "Move success."
            };
            if (productImageId.HasValue)
            {
                List <ProductImageModel> paramList =
                    _productImageService.Select(new SearchProductImageModel
                {
                    PagedIndex  = PagedIndex,
                    PagedSize   = PagedSize,
                    ProductName = productName,
                    ImageType   = ImageType
                }).Data;
                if (paramList != null && paramList.Count > 0)
                {
                    switch (sortType)
                    {
                    case 1:    //上移
                        if (rowId > 0)
                        {
                            _productImageService.UpdatePlace(paramList[rowId].ProductImageId, (int)paramList[rowId - 1].place);
                            _productImageService.UpdatePlace(paramList[rowId - 1].ProductImageId, (int)paramList[rowId].place);
                        }
                        else
                        {
                            resultModel.IsValid  = false;
                            resultModel.Messages = new List <string> {
                                "This is top line."
                            };
                        }
                        break;

                    case 2:    //下移
                        if (rowId < (paramList.Count - 1))
                        {
                            _productImageService.UpdatePlace(paramList[rowId].ProductImageId, (int)paramList[rowId + 1].place);
                            _productImageService.UpdatePlace(paramList[rowId + 1].ProductImageId, (int)paramList[rowId].place);
                        }
                        else
                        {
                            resultModel.IsValid  = false;
                            resultModel.Messages = new List <string> {
                                "This is last line!."
                            };
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            else
            {
                resultModel.IsValid  = false;
                resultModel.Messages = new List <string> {
                    "Failed, ID error."
                };
            }
            return(Json(resultModel, JsonRequestBehavior.AllowGet));
        }