示例#1
0
        public ActionResult Image(string id, int?width, int?height, bool crop = true, bool center = true)
        {
            IImagesRepository repository = DependencyResolver.Current.GetService <IImagesRepository>();

            var imageEntity = repository.GetById(new Guid(id));

            byte[] binary;
            if (width == null && height == null)
            {
                binary = imageEntity.Binary;
            }
            else
            {
                string key = "File_" + id + "_width_" + width + "_height_" + height + "_crop_" + crop + "_center_" + center;

                binary = this.HttpContext.Cache[key] as byte[];
                if (binary == null)
                {
                    binary = crop ?
                             ImageHelper.GetImageCroped(imageEntity.Binary, width.Value, height.Value, center) :
                             ImageHelper.GetImageResized(imageEntity.Binary, width.Value, height.Value);
                    this.HttpContext.Cache.Insert(key, binary);
                }
            }

            return(File(new MemoryStream(binary), ImageHelper.GetContentType(Path.GetExtension(imageEntity.Name)), imageEntity.Name));
        }
示例#2
0
        /// <summary>
        /// Повертає екземпляр зображення за ідентифікатором
        /// </summary>
        /// <param name="id">Ідентифікатор зображення</param>
        /// <returns>Екземпляр зображення</returns>
        public ImagesDtoModel GetImageById(int id)
        {
            var            mapper   = new MapperConfiguration(cfg => cfg.CreateMap <ImagesModel, ImagesDtoModel>()).CreateMapper();
            ImagesDtoModel imageDto = mapper.Map <ImagesDtoModel>(imagesRepository.GetById(id));

            imageDto.ProductName = commonRepository.GetProductsIdNames()[imageDto.ProductId];

            return(imageDto);
        }
示例#3
0
        public ActionResult Image(string id)
        {
            var imageEntity = repository.GetById(new Guid(id));

            string key = "File_" + id;

            byte[] binary = this.HttpContext.Cache[key] as byte[];
            if (binary == null)
            {
                binary = ImageHelper.GetImageCroped(imageEntity.Binary, 100, 100, true);
                this.HttpContext.Cache.Insert(key, binary);
            }

            return(File(new MemoryStream(binary), ImageHelper.GetContentType(Path.GetExtension(imageEntity.Name)), imageEntity.Name));
        }
示例#4
0
 public async Task <ImageStatusResult> GetImageStatus(Guid imageId)
 => (ImageStatusResult)await _imagesRepository.GetById(imageId);