You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.1 KiB
76 lines
2.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using DTO;
|
|
using Entity;
|
|
using Shared;
|
|
using Dto2Entities;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace ServicesApi
|
|
{
|
|
public class ImageService : IImagesService<ImageDTO>
|
|
{
|
|
private IImagesService<Images> imageService;
|
|
|
|
public ImageService(IImagesService<Images> image)
|
|
{
|
|
imageService = image;
|
|
}
|
|
|
|
public async Task AddImage(ImageDTO image)
|
|
{
|
|
await imageService.AddImage(image.ToEntity());
|
|
}
|
|
|
|
public async Task<PaginationResult<ImageDTO>> GetAllImage()
|
|
{
|
|
var images = imageService.GetAllImage().Result.items;
|
|
return new PaginationResult<ImageDTO>(images.Count(), 0, 10, images.ToDto());
|
|
}
|
|
|
|
public async Task<ImageDTO> GetImageById(int id)
|
|
{
|
|
var image = await imageService.GetImageById(id);
|
|
if (image == null)
|
|
{
|
|
throw new KeyNotFoundException($"No image with the id {id}");
|
|
}
|
|
return image.ToDto();
|
|
}
|
|
|
|
public async Task<ImageDTO?> GetImageByPath(string path)
|
|
{
|
|
var image = await imageService.GetImageByPath(path);
|
|
if (image == null)
|
|
{
|
|
return null;
|
|
}
|
|
return image.ToDto();
|
|
}
|
|
|
|
public async Task<int> GetLastImageId()
|
|
{
|
|
return await imageService.GetLastImageId();
|
|
}
|
|
|
|
public async Task<PaginationResult<ImageDTO>> GetSomeImage(int index, int pageSize)
|
|
{
|
|
var images = imageService.GetSomeImage(index,pageSize).Result.items;
|
|
return new PaginationResult<ImageDTO>(images.Count(), 0, 10, images.ToDto());
|
|
}
|
|
|
|
public async Task RemoveImage(int id)
|
|
{
|
|
await imageService.RemoveImage(id);
|
|
}
|
|
|
|
public async Task UpdateImage(int id, ImageDTO image)
|
|
{
|
|
await imageService.UpdateImage(id, image.ToEntity());
|
|
}
|
|
}
|
|
}
|