namespace IOL.GreatOffice.Api.Endpoints.V1.Labels;
///
public class DeleteLabelEndpoint : RouteBaseSync.WithRequest.WithActionResult
{
private readonly AppDbContext _context;
///
public DeleteLabelEndpoint(AppDbContext context) {
_context = context;
}
///
/// Delete a time entry label.
///
///
///
[ApiVersion(ApiSpecV1.VERSION_STRING)]
[BasicAuthentication(AppConstants.TOKEN_ALLOW_DELETE)]
[HttpDelete("~/v{version:apiVersion}/labels/{id:guid}/delete")]
public override ActionResult Handle(Guid id) {
var label = _context.TimeLabels
.Where(c => c.UserId == LoggedInUser.Id)
.SingleOrDefault(c => c.Id == id);
if (label == default) {
return NotFound();
}
_context.TimeLabels.Remove(label);
_context.SaveChanges();
return Ok();
}
}