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

71 lines
2.1 KiB
C#
Raw Permalink 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.SliderDto;
using ConstructorApp.EntityLayer.Entities;
using Microsoft.AspNetCore.Mvc;
namespace ConstructorAppApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SliderController : ControllerBase
{
private readonly ISliderService _sliderService;
private readonly IMapper _mapper;
public SliderController(ISliderService sliderService, IMapper mapper)
{
_sliderService = sliderService;
_mapper = mapper;
}
[HttpGet]
public IActionResult SliderList()
{
var value = _sliderService.TGetListAll();
var result = _mapper.Map<List<ResultSliderDto>>(value);
return Ok(result);
}
[HttpPost]
public IActionResult CreateSlider(CreateSliderDto createSliderDto)
{
var value = _mapper.Map<Slider>(createSliderDto);
_sliderService.TAdd(value);
return Ok("Slider Bilgisi Eklendi");
}
[HttpDelete("{id}")]
public IActionResult DeleteSlider(int id)
{
var value = _sliderService.TGetByID(id);
if (value != null)
{
_sliderService.TDelete(value);
return Ok("Slider Bilgisi Silindi");
}
return NotFound("Slider Bilgisi Bulunamadı");
}
[HttpPut]
public IActionResult UpdateSlider(UpdateSliderDto updateSliderDto)
{
var value = _mapper.Map<Slider>(updateSliderDto);
_sliderService.TUpdate(value);
return Ok("Slider Alanı Güncellendi");
}
[HttpGet("{id}")]
public IActionResult GetSlider(int id)
{
var value = _sliderService.TGetByID(id);
if (value != null)
{
var result = _mapper.Map<ResultSliderDto>(value);
return Ok(result);
}
return NotFound("Slider Bilgisi Bulunamadı");
}
}
}