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

71 lines
2.0 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.TeamDto;
using ConstructorApp.EntityLayer.Entities;
using Microsoft.AspNetCore.Mvc;
namespace ConstructorAppApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class TeamController : ControllerBase
{
private readonly ITeamService _teamService;
private readonly IMapper _mapper;
public TeamController(ITeamService teamService, IMapper mapper)
{
_teamService = teamService;
_mapper = mapper;
}
[HttpGet]
public IActionResult TeamList()
{
var value = _teamService.TGetListAll();
var result = _mapper.Map<List<ResultTeamDto>>(value);
return Ok(result);
}
[HttpPost]
public IActionResult CreateTeam(CreateTeamDto createTeamDto)
{
var value = _mapper.Map<Team>(createTeamDto);
_teamService.TAdd(value);
return Ok("Team Bilgisi Eklendi");
}
[HttpDelete("{id}")]
public IActionResult DeleteTeam(int id)
{
var value = _teamService.TGetByID(id);
if (value != null)
{
_teamService.TDelete(value);
return Ok("Team Bilgisi Silindi");
}
return NotFound("Team Bilgisi Bulunamadı");
}
[HttpPut]
public IActionResult UpdateTeam(UpdateTeamDto updateTeamDto)
{
var value = _mapper.Map<Team>(updateTeamDto);
_teamService.TUpdate(value);
return Ok("Team Alanı Güncellendi");
}
[HttpGet("{id}")]
public IActionResult GetTeam(int id)
{
var value = _teamService.TGetByID(id);
if (value != null)
{
var result = _mapper.Map<ResultTeamDto>(value);
return Ok(result);
}
return NotFound("Team Bilgisi Bulunamadı");
}
}
}