Пример #1
0
        public List <ProductImageProduct> GetProductImage_Product(int ProductId)
        {
            List <ProductImageProduct> GridRecords = new List <ProductImageProduct>();
            var command = dbContext.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "sp_ProductImage_Product_Get";
            command.AddParameter("@ProductId", ProductId, DbType.Int32);
            command.OpenConnection();
            var reader = command.OpenReader();

            while (reader.Read())
            {
                ProductImageProduct GridRecord = new ProductImageProduct()
                {
                    RowId          = reader.ValidateColumnExistExtractAndCastTo <int>("RowId"),
                    ProductId      = reader.ValidateColumnExistExtractAndCastTo <int>("ProductId"),
                    ProductImageId = reader.ValidateColumnExistExtractAndCastTo <int>("ProductImageId"),
                    ImageName      = reader.ValidateColumnExistExtractAndCastTo <string>("ImageName"),
                    ImagePath      = reader.ValidateColumnExistExtractAndCastTo <string>("ImagePath"),
                    ThumbnailPath  = reader.ValidateColumnExistExtractAndCastTo <string>("ThumbnailPath"),
                    //ImageFileStream = Helper.Base64ToImage(reader.ValidateColumnExistExtractAndCastTo<string>("ImagePath")),
                };
                GridRecords.Add(GridRecord);
            }
            ;
            command.CloseConnection();
            return(GridRecords);
        }
Пример #2
0
        public IActionResult UploadMultipleFiles(int ProductId)
        {
            var response = new OperationResponse <ProductImages>();

            try
            {
                if (Request.Form.ContainsKey("ProductId"))
                {
                    ProductId = Convert.ToInt32(Request.Form["ProductId"].ToString());
                }

                if (Request.Form.Files.Count > 0)
                {
                    foreach (var item in Request.Form.Files)
                    {
                        int MaxId = _productImageService.GetMaxProductImageId();

                        var file = item;

                        string OriginalImagePath  = _configuration["ImagePathConfiguration:OriginalImagePath"];
                        string ThumbnailImagePath = _configuration["ImagePathConfiguration:ThumbnailImagePath"];

                        var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                        var fileExt  = fileName.Remove(0, fileName.LastIndexOf('.'));
                        fileName = (MaxId + 1).ToString() + fileExt;

                        ImageCompressHelper.CompressImage(OriginalImagePath, ThumbnailImagePath, file, fileName);

                        ProductImages request = new ProductImages();
                        request.ImageName     = fileName;
                        request.ImagePath     = Path.Combine(OriginalImagePath, fileName);
                        request.ThumbnailPath = Path.Combine(ThumbnailImagePath, fileName);
                        request.Description   = "";
                        request.DisplayOrder  = 1;
                        request.IsDisplay     = true;

                        response.Data = _productImageService.AddProductImages(request);

                        ProductImageProduct request2 = new ProductImageProduct();
                        request2.ProductId      = Convert.ToInt32(ProductId);
                        request2.ProductImageId = response.Data.RowId;
                        _productImageService.AddProductImage_Product(request2);
                    }
                }
                else
                {
                    response.Messages.Add("Please upload Image");
                }
            }
            catch (Exception exception)
            {
                response.State = ResponseState.Error;
                response.Messages.Add(exception.Message);
            }
            return(new JsonResult(response));
        }
Пример #3
0
        public IList <ProductImageProduct> DeleteProductImage_Product_dyId(List <ProductImageProduct> tasks)
        {
            var result  = new List <ProductImageProduct>();
            var command = dbContext.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "sp_ProductImage_Product_d_byId";
            SqlParameter[] sqlParams = new SqlParameter[1];
            sqlParams[0] = new SqlParameter("@RowId", DbType.Int32);
            using (var transaction = new TransactionScope())
            {
                using (command.Connection)
                {
                    if (command.Connection.State == ConnectionState.Closed)
                    {
                        command.Connection.Open();
                    }
                    foreach (var item in tasks)
                    {
                        var data = new ProductImageProduct();
                        command.Parameters.Clear();
                        sqlParams[0].Value = (object)item.RowId;
                        command.Parameters.Add(sqlParams[0]);
                        try
                        {
                            command.ExecuteNonQuery();
                            data.RowId   = item.RowId;
                            data.Message = "";
                        }
                        catch (Exception ex)
                        {
                            data.RowId   = item.RowId;
                            data.Message = "Error while updating record.";
                        }
                        finally
                        {
                            result.Add(data);
                        }
                    }
                }
                transaction.Complete();
            }
            return(result);
        }
Пример #4
0
        public bool DeleteProductImage_Product_dyProductId(ProductImageProduct request)
        {
            int result;
            var command = dbContext.CreateCommand();

            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "sp_ProductImage_Product_d_byProductId";
            command.AddParameter("@ProductId", request.ProductId, DbType.Int32);
            try
            {
                command.OpenConnection();
                result = command.ExecuteNonQuery();
            }
            finally
            {
                command.CloseConnection();
            }
            return(result > 0);
        }