public IActionResult DeleteGoodsInDetailImage(long id)
        {
            if (id <= 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "找不到该商品详情图片!")));
            }
            GoodsInDetailImage detailImage = goodsInDetailImageService.GetSingleGoodsInDetailImage(id);
            bool result = goodsInDetailImageService.DeleteGoodsInDetailImage(detailImage);

            if (result)
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "删除成功!")));
            }
            return(Json(new StatusMessageData(StatusMessageType.Error, "删除失败!")));
        }
        public async Task <IActionResult> EditGoodsInDetailImage([FromServices] IHostingEnvironment env, IList <IFormFile> imgfile, long id, int number)
        {
            if (id <= 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "找不到该商品详情图片!")));
            }
            const string fileFilt   = ".gif|.jpg|.jpeg|.png|.webp|";
            const string saveSuffix = ".jpeg";

            foreach (var file in Request.Form.Files)
            {
                var fileExtension = Path.GetExtension(file.FileName);
                if (fileExtension == null)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件没有后缀")));
                }
                if (fileFilt.IndexOf(fileExtension.ToLower(), StringComparison.Ordinal) <= -1)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不是图片")));
                }
                if (file.Length > 1024 * 1024 * 2)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不能大于2M")));
                }
            }

            GoodsInDetailImage goodsInDetailImage = goodsInDetailImageService.GetSingleGoodsInDetailImage(id);

            if (number != goodsInDetailImage.Number)
            {
                goodsInDetailImage.Number = number;
            }

            if (imgfile.Count > 0)
            {
                IFormFile imgFile = imgfile[0];
                goodsInDetailImage.GoodsDetaiImage = await Utility.SaveImage(env, imgFile, Request, saveSuffix);
            }

            bool result = goodsInDetailImageService.EditGoodsInDetailImage(goodsInDetailImage);

            if (result)
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "编辑成功!")));
            }
            return(Json(new StatusMessageData(StatusMessageType.Error, "编辑失败!")));
        }
        public async Task <IActionResult> AddGoodsInDetailImage([FromServices] IHostingEnvironment env, IList <IFormFile> addImgFiles, long goodsId, int number)
        {
            if (goodsId <= 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "找不到该商品!")));
            }
            else if (addImgFiles.Count <= 0)
            {
                return(Json(new StatusMessageData(StatusMessageType.Error, "添加失败!")));
            }
            const string fileFilt   = ".gif|.jpg|.jpeg|.png|.webp|";
            const string saveSuffix = ".jpeg";

            foreach (var file in Request.Form.Files)
            {
                var fileExtension = Path.GetExtension(file.FileName);
                if (fileExtension == null)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件没有后缀")));
                }
                if (fileFilt.IndexOf(fileExtension.ToLower(), StringComparison.Ordinal) <= -1)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不是图片")));
                }
                if (file.Length > 1024 * 1024 * 2)
                {
                    return(Json(new StatusMessageData(StatusMessageType.Error, "上传的文件不能大于2M")));
                }
            }

            IEnumerable <GoodsInDetailImage> detailImageLists = goodsInDetailImageService.GetAllGoodsInDetailImage(goodsId);

            int imgMaxIndex = 0;

            if (detailImageLists.Count() <= 0)
            {
                imgMaxIndex = 0;
            }
            else
            {
                imgMaxIndex = detailImageLists.Max(m => m.Number);
            }

            List <bool> resultList = new List <bool>();

            foreach (var img in addImgFiles)
            {
                GoodsInDetailImage imgModel = new GoodsInDetailImage();
                var       imgIndex          = addImgFiles.IndexOf(img);
                IFormFile file = addImgFiles[imgIndex];
                imgModel.Number          = ++imgMaxIndex;
                imgModel.Goodsid         = goodsId;
                imgModel.GoodsDetaiImage = await Utility.SaveImage(env, file, Request, saveSuffix);

                bool result = goodsInDetailImageService.AddGoodsInDetailImage(imgModel);
                resultList.Add(result);
            }
            if (resultList.All(m => m == true))
            {
                return(Json(new StatusMessageData(StatusMessageType.Success, "添加成功!")));
            }
            return(Json(new StatusMessageData(StatusMessageType.Error, "添加失败!")));
        }