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)); } }
/// <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); }
public IEnumerable <ImageInfo> GetAllImages() { return(repository.GetAll()); }