Files
constructdemo/ConstructorAppApi/Controllers/ProjectGalleryController.cs
2025-05-01 15:18:30 +03:00

78 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AutoMapper;
using ConstructorApp.BusinessLayer.Abstract;
using ConstructorApp.DtoLayer.ProjectGalleryDto;
using ConstructorApp.EntityLayer.Entities;
using Microsoft.AspNetCore.Mvc;
namespace ConstructorAppApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ProjectGalleryController : ControllerBase
{
private readonly IProjectGalleryService _projectGalleryService;
private readonly IMapper _mapper;
public ProjectGalleryController(IProjectGalleryService projectGalleryService, IMapper mapper)
{
_projectGalleryService = projectGalleryService;
_mapper = mapper;
}
[HttpGet]
public IActionResult ProjectGalleryList()
{
var value = _projectGalleryService.TGetListAll();
var result = _mapper.Map<List<ResultProjectGalleryDto>>(value);
return Ok(result);
}
[HttpPost]
public IActionResult CreateProjectGallery(CreateProjectGalleryDto createProjectGalleryDto)
{
var value = _mapper.Map<ProjectGallery>(createProjectGalleryDto);
_projectGalleryService.TAdd(value);
return Ok("Galeri Bilgisi Eklendi");
}
[HttpDelete("{id}")]
public IActionResult DeleteProjectGallery(int id)
{
var value = _projectGalleryService.TGetByID(id);
if (value != null)
{
_projectGalleryService.TDelete(value);
return Ok("Galeri Bilgisi Silindi");
}
return NotFound("Galeri Bilgisi Bulunamadı");
}
[HttpPut]
public IActionResult UpdateProjectGallery(UpdateProjectGalleryDto updateProjectGalleryDto)
{
var value = _mapper.Map<ProjectGallery>(updateProjectGalleryDto);
_projectGalleryService.TUpdate(value);
return Ok("Galeri Alanı Güncellendi");
}
[HttpGet("{id}")]
public IActionResult GetProjectGallery(int id)
{
var value = _projectGalleryService.TGetByID(id);
if (value != null)
{
var result = _mapper.Map<ResultProjectGalleryDto>(value);
return Ok(result);
}
return NotFound("Galeri Bilgisi Bulunamadı");
}
[HttpGet("GetByProjectId/{projectId}")]
public IActionResult GetImagesByProjectId(int projectId)
{
var images = _projectGalleryService.TGetImagesByProjectId(projectId);
return Ok(images);
}
}
}