コード例 #1
0
        public IActionResult AddProductColorImage([FromForm] AddProductColorModel addProduct)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var      existImageCount = iProduct.GetImageCountByProductColorId(DBHelper.ParseInt64(addProduct.productId), addProduct.ColorId);
                    string[] deleteImage     = null;
                    if (!string.IsNullOrWhiteSpace(addProduct.DeleteImageId))
                    {
                        deleteImage = addProduct.DeleteImageId.Split(',');
                    }
                    if (existImageCount == 0 && (addProduct.image == null || Request.Form.Files.Count <= 0))
                    {
                        if (deleteImage != null && deleteImage.Length == existImageCount)
                        {
                            return(Ok(ResponseHelper.Error(MessageConstants.AtleastOneImageColor)));
                        }
                    }
                    else if (!string.IsNullOrWhiteSpace(addProduct.DeleteImageId))
                    {
                        if ((addProduct.image == null || Request.Form.Files.Count <= 0) && deleteImage != null && existImageCount == deleteImage.Length)
                        {
                            return(Ok(ResponseHelper.Error(MessageConstants.AtleastOneImageColor)));
                        }
                    }

                    if (addProduct.image == null && Request.Form != null && Request.Form.Files.Count > 0)
                    {
                        addProduct.image = new List <Microsoft.AspNetCore.Http.IFormFile>();
                        foreach (var file in Request.Form.Files)
                        {
                            addProduct.image.Add(file);
                        }
                    }
                    var  hostingPath    = env.ContentRootPath;
                    long productColorId = iProduct.AddProductColorImage(DBHelper.ParseInt64(addProduct.productId), addProduct.ColorId, addProduct.image, hostingPath, addProduct.DeleteImageId);
                    if (productColorId > 0)
                    {
                        return(Ok(ResponseHelper.Success(MessageConstants.ProductColorImageUpdated)));
                    }
                    else if (productColorId == ReturnCode.AlreadyExist.GetHashCode())
                    {
                        return(Ok(ResponseHelper.Error(MessageConstants.TryDifferentName)));
                    }
                    else
                    {
                        return(Ok(ResponseHelper.Error(MessageConstants.ProductColorImageNotUpdated)));
                    }
                }
                else
                {
                    return(Ok(ResponseHelper.Error(MessageConstants.CompulsoryData)));
                }
            }
            catch (Exception ex)
            {
                LogHelper.ExceptionLog(ex.Message + "  :::::  " + ex.StackTrace);
                return(Ok(ResponseHelper.Error(ex.Message)));
            }
        }