コード例 #1
0
        public ActionResult <List <ImageDTO> > GetImages()
        {
            IEnumerable <Image> listImages = repository.GetAll();
            List <ImageDTO>     list       = new List <ImageDTO>();

            if (listImages == null)
            {
                return(NotFound());
            }
            else
            {
                foreach (Image i in listImages)
                {
                    Byte[]   b = System.IO.File.ReadAllBytes(i.ImgUrl); // You can use your own method over here.
                    string   base64ImageRepresentation = "data:image/jpeg;base64," + Convert.ToBase64String(b);
                    ImageDTO img = new ImageDTO
                    {
                        imageId        = i.ImageId,
                        imgName        = i.ImgName,
                        imgDescription = i.ImgDescription,
                        imgUrl         = base64ImageRepresentation,
                        platform       = i.PlatformId
                    };
                    list.Add(img);
                }

                return(Ok(list));
            }
        }
コード例 #2
0
        /// <summary>
        /// Повертає список зображень
        /// </summary>
        /// <returns>Список зображень</returns>
        public IEnumerable <ImagesDtoModel> GetImages()
        {
            List <ImagesDtoModel>    imagesDtos      = new List <ImagesDtoModel>();
            Dictionary <int, string> productsIdNames = commonRepository.GetProductsIdNames();

            var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ImagesModel, ImagesDtoModel>()).CreateMapper();

            foreach (ImagesModel image in imagesRepository.GetAll())
            {
                ImagesDtoModel imagesDto = mapper.Map <ImagesDtoModel>(image);
                imagesDto.ProductName = productsIdNames[image.ProductId];
                imagesDtos.Add(imagesDto);
            }

            return(imagesDtos);
        }
コード例 #3
0
 public IEnumerable <ImageInfo> GetAllImages()
 {
     return(repository.GetAll());
 }