yavsc/src/Api/Controllers/Business/PerformersApiController.cs

65 lines
2 KiB
C#
Raw Normal View History

2017-01-31 13:21:42 +01:00
2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Mvc;
2017-02-20 15:53:25 +01:00
using System.Security.Claims;
2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Authorization;
2017-01-31 13:21:42 +01:00
namespace Yavsc.Controllers
{
2023-03-19 17:57:55 +00:00
using Microsoft.EntityFrameworkCore;
2017-02-23 03:10:30 +01:00
using Models;
2017-04-30 01:39:22 +02:00
using Yavsc.Helpers;
2018-06-15 15:44:21 +02:00
using Yavsc.Services;
2017-04-30 01:39:22 +02:00
2017-01-31 13:21:42 +01:00
[Produces("application/json")]
[Route("api/performers")]
public class PerformersApiController : Controller
{
ApplicationDbContext dbContext;
2020-10-09 19:35:39 +01:00
private readonly IBillingService billing;
2018-06-15 15:44:21 +02:00
public PerformersApiController(ApplicationDbContext context, IBillingService billing)
2017-01-31 13:21:42 +01:00
{
dbContext = context;
2018-06-15 15:44:21 +02:00
this.billing = billing;
2017-01-31 13:21:42 +01:00
}
2017-02-20 15:53:25 +01:00
/// <summary>
/// Lists profiles on an activity code
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
2017-02-21 20:49:07 +01:00
[Authorize(Roles="Performer"),HttpGet("{id}")]
2017-02-20 15:53:25 +01:00
public IActionResult Get(string id)
2017-01-31 13:21:42 +01:00
{
2017-02-21 20:49:07 +01:00
var pfr = dbContext.Performers.Include(
p=>p.OrganizationAddress
).Include(
p=>p.Performer
).Include(
p=>p.Performer.Posts
).SingleOrDefault(p=> p.PerformerId == id);
2017-02-20 15:53:25 +01:00
if (id==null)
{
2017-02-21 20:49:07 +01:00
ModelState.AddModelError("id","Specifier un identifiant de prestataire valide");
2017-02-20 15:53:25 +01:00
}
2017-02-21 20:49:07 +01:00
else {
2023-03-19 17:57:55 +00:00
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
2017-02-21 20:49:07 +01:00
if (!User.IsInRole("Administrator"))
if (uid != id) return new ChallengeResult();
if (!pfr.Active)
{
ModelState.AddModelError("id","Prestataire désactivé.");
}
}
if (ModelState.IsValid) return Ok(pfr);
return new BadRequestObjectResult(ModelState);
2017-01-31 13:21:42 +01:00
}
2017-04-30 01:39:22 +02:00
[HttpGet("doing/{id}"),AllowAnonymous]
2025-02-24 23:29:48 +00:00
public async Task<IActionResult> ListPerformers(string id)
2017-04-30 01:39:22 +02:00
{
2025-02-24 23:29:48 +00:00
return Ok(await dbContext.ListPerformersAsync(billing, id));
2017-04-30 01:39:22 +02:00
}
2017-01-31 13:21:42 +01:00
}
2017-02-27 19:28:32 +01:00
}