Add update order method
This commit is contained in:
parent
37c667cd46
commit
f842a56ce0
@ -462,6 +462,52 @@ namespace ManagerService.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update sections order
|
||||
/// </summary>
|
||||
/// <param name="updatedSectionsOrder">New sections order</param>
|
||||
[ProducesResponseType(typeof(string), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
[HttpPut("order")]
|
||||
public ObjectResult UpdateOrder([FromBody] List<SectionDTO> updatedSectionsOrder)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updatedSectionsOrder == null)
|
||||
throw new ArgumentNullException("Sections param is null");
|
||||
|
||||
foreach (var section in updatedSectionsOrder)
|
||||
{
|
||||
if (!_sectionService.IsExist(section.Id))
|
||||
throw new KeyNotFoundException($"Section {section.Label} with id {section.Id} does not exist");
|
||||
}
|
||||
|
||||
foreach (var updatedSection in updatedSectionsOrder)
|
||||
{
|
||||
Section section = _sectionService.GetById(updatedSection.Id);
|
||||
section.Order = updatedSection.Order;
|
||||
|
||||
_sectionService.Update(section.Id, section);
|
||||
}
|
||||
|
||||
return new ObjectResult("Sections order has been successfully modified") { StatusCode = 200 };
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
return new BadRequestObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (KeyNotFoundException ex)
|
||||
{
|
||||
return new NotFoundObjectResult(ex.Message) { };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete a section
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user