|
@@ -13,7 +13,7 @@ using System.Text.Json;
|
|
|
namespace OnlineMetodist.API.Controllers
|
|
|
{
|
|
|
[Authorize]
|
|
|
- [Route("api/[controller]")]
|
|
|
+ [Route("api/[controller]/[action]")]
|
|
|
[ApiController]
|
|
|
public class EventsController : ControllerBase
|
|
|
{
|
|
@@ -30,7 +30,7 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
|
- [Route("GetParticipationForms")]
|
|
|
+ //[Route("GetParticipationForms")]
|
|
|
public async Task<ActionResult<List<string>>> GetParticipationForms()
|
|
|
{
|
|
|
if(EnumsEvent.ParticipationForms.Any())
|
|
@@ -42,7 +42,7 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
|
- [Route("GetEventForms")]
|
|
|
+ //[Route("GetEventForms")]
|
|
|
public async Task<ActionResult<List<string>>> GetEventForms()
|
|
|
{
|
|
|
if(EnumsEvent.EventForms.Any())
|
|
@@ -54,7 +54,7 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
|
- [Route("GetStatusEvents")]
|
|
|
+ //[Route("GetStatusEvents")]
|
|
|
public async Task<ActionResult<List<string>>> GetStatusEvents()
|
|
|
{
|
|
|
if(EnumsEvent.StatusEvents.Any())
|
|
@@ -66,7 +66,7 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
|
- [Route("GetResultEvents")]
|
|
|
+ //[Route("GetResultEvents")]
|
|
|
public async Task<ActionResult<List<string>>> GetResultEvents()
|
|
|
{
|
|
|
if(EnumsEvent.ResultEvents.Any())
|
|
@@ -78,7 +78,7 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
|
- [Route("GetEvents")]
|
|
|
+ //[Route("GetEvents")]
|
|
|
public async Task<ActionResult<IEnumerable<Event>>> GetEvent()
|
|
|
{
|
|
|
try
|
|
@@ -101,8 +101,37 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [HttpGet("{nameFormOfWork}")]
|
|
|
+ //[Route("GetEvents")]
|
|
|
+ public async Task<ActionResult<IEnumerable<Event>>> GetEvent(string nameFormOfWork)
|
|
|
+ {
|
|
|
+ if (!_context.FormsOfWorks.Any(x => x.Name.ToLower() == nameFormOfWork.ToLower()))
|
|
|
+ {
|
|
|
+ _logger.LogError($"Incorrect name form of work.");
|
|
|
+ return BadRequest("Incorrect name form of work.");
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ApplicationUser applicationUser = await _userManager.Users
|
|
|
+ .Include(x => x.Employee).ThenInclude(e => e.Events).ThenInclude( ev => ev.FormOfWorkFK)
|
|
|
+ .FirstAsync(x => x.UserName == User.Identity.Name);
|
|
|
+ var events = applicationUser.Employee.Events.Where(x => x.FormOfWorkFK.Name.ToLower() == nameFormOfWork.ToLower());
|
|
|
+ if (events == null)
|
|
|
+ {
|
|
|
+ _logger.LogInformation($"Events sent from client is null.");
|
|
|
+ return NoContent();
|
|
|
+ }
|
|
|
+ return Ok(events);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError($"Something went wrong inside GetEvent action: {ex.Message}");
|
|
|
+ return StatusCode(500, "Internal server error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[HttpPost]
|
|
|
- [Route("CreateHoldingEvent")]
|
|
|
+ //[Route("CreateHoldingEvent")]
|
|
|
public async Task<ActionResult<Event>> CreateHoldingEvent(HoldingEvent model)
|
|
|
{
|
|
|
if (!ModelState.IsValid)
|
|
@@ -148,7 +177,7 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
|
|
|
[HttpPost]
|
|
|
- [Route("CreateParticipationEvent")]
|
|
|
+ //[Route("CreateParticipationEvent")]
|
|
|
public async Task<ActionResult<Event>> CreateParticipationEvent(ParticipationEvent model)
|
|
|
{
|
|
|
if (!ModelState.IsValid)
|
|
@@ -193,5 +222,91 @@ namespace OnlineMetodist.API.Controllers
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [HttpPost]
|
|
|
+ //[Route("CreateInternshipEvent")]
|
|
|
+ public async Task<ActionResult<Event>> CreateInternshipEvent(InternshipEvent model)
|
|
|
+ {
|
|
|
+ if (!ModelState.IsValid)
|
|
|
+ {
|
|
|
+ _logger.LogError("Invalid InternshipEvent object sent from client.");
|
|
|
+ return BadRequest("Invalid model object");
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FormOfWork form = await _context.FormsOfWorks.FirstAsync(x => x.Name == "Стажировка");
|
|
|
+ ApplicationUser applicationUser = await _userManager.Users
|
|
|
+ .Include(x => x.Employee)
|
|
|
+ .FirstAsync(x => x.UserName == User.Identity.Name);
|
|
|
+ Internship internshipEvent = new()
|
|
|
+ {
|
|
|
+ Location = model.Location,
|
|
|
+ QuantityOfHours = model.QuantityOfHours
|
|
|
+ };
|
|
|
+ string specifications = JsonSerializer.Serialize(internshipEvent);
|
|
|
+ Models.Event newEvent = new()
|
|
|
+ {
|
|
|
+ DateOfEvent = model.DateOfEvent,
|
|
|
+ EndDateOfEvent = model.EndDateOfEvent,
|
|
|
+ FormOfWorkFK = form,
|
|
|
+ IdFormOfWork = form.Id,
|
|
|
+ Specifications = specifications,
|
|
|
+ EmployeeId = applicationUser.Employee.Id,
|
|
|
+ Employee = applicationUser.Employee
|
|
|
+ };
|
|
|
+ await _context.Events.AddAsync(newEvent);
|
|
|
+ await _context.SaveChangesAsync();
|
|
|
+ return CreatedAtAction("CreateInternshipEvent", new { id = newEvent.Id }, newEvent);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError($"Something went wrong inside CreateInternshipEvent action: {ex.Message}");
|
|
|
+ return StatusCode(500, "Internal server error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [HttpPost]
|
|
|
+ //[Route("CreatePublicationEvent")]
|
|
|
+ public async Task<ActionResult<Event>> CreatePublicationEvent(PublicationEvent model)
|
|
|
+ {
|
|
|
+ if (!ModelState.IsValid)
|
|
|
+ {
|
|
|
+ _logger.LogError("Invalid PublicationEvent object sent from client.");
|
|
|
+ return BadRequest("Invalid model object");
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ FormOfWork form = await _context.FormsOfWorks.FirstAsync(x => x.Name == "Стажировка");
|
|
|
+ ApplicationUser applicationUser = await _userManager.Users
|
|
|
+ .Include(x => x.Employee)
|
|
|
+ .FirstAsync(x => x.UserName == User.Identity.Name);
|
|
|
+ PublicationEvent publicationEvent = new()
|
|
|
+ {
|
|
|
+ Type = model.Type,
|
|
|
+ Name = model.Name,
|
|
|
+ Place = model.Place
|
|
|
+ };
|
|
|
+ string specifications = JsonSerializer.Serialize(publicationEvent);
|
|
|
+ Models.Event newEvent = new()
|
|
|
+ {
|
|
|
+ DateOfEvent = model.DateOfEvent,
|
|
|
+ EndDateOfEvent = model.EndDateOfEvent,
|
|
|
+ FormOfWorkFK = form,
|
|
|
+ IdFormOfWork = form.Id,
|
|
|
+ Specifications = specifications,
|
|
|
+ EmployeeId = applicationUser.Employee.Id,
|
|
|
+ Employee = applicationUser.Employee
|
|
|
+ };
|
|
|
+ await _context.Events.AddAsync(newEvent);
|
|
|
+ await _context.SaveChangesAsync();
|
|
|
+ return CreatedAtAction("CreatePublicationEvent", new { id = newEvent.Id }, newEvent);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError($"Something went wrong inside CreatePublicationEvent action: {ex.Message}");
|
|
|
+ return StatusCode(500, "Internal server error");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|