diff --git a/Server/Controllers/AddressController.cs b/Server/Controllers/AddressController.cs index b794092..fc92b14 100644 --- a/Server/Controllers/AddressController.cs +++ b/Server/Controllers/AddressController.cs @@ -24,7 +24,7 @@ public class AddressController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetAddress), new {id = result.address.Id}, result.address); @@ -37,7 +37,7 @@ public class AddressController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class AddressController : ControllerBase [HttpGet("{id}")] public async Task GetAddress(int id, [FromQuery] string? fields) { - if (!await _addressManagementService.IsAddressExists(id)) - { - return NotFound(); - } - var result = await _addressManagementService.GetAddress(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.address); @@ -66,16 +61,11 @@ public class AddressController : ControllerBase [HttpPut("{id}")] public async Task UpdateAddress(int id, UpdateAddressDto address) { - if (id != address.Id) - { - return BadRequest(); - } - var result = await _addressManagementService.UpdateAddress(address); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.address); @@ -84,16 +74,11 @@ public class AddressController : ControllerBase [HttpDelete("{id}")] public async Task DeleteAddress(int id) { - if (!await _addressManagementService.IsAddressExists(id)) - { - return NotFound(); - } - var result = await _addressManagementService.DeleteAddress(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/CityController.cs b/Server/Controllers/CityController.cs index 8049176..0fb24fc 100644 --- a/Server/Controllers/CityController.cs +++ b/Server/Controllers/CityController.cs @@ -24,7 +24,7 @@ public class CityController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetCity), new {id = result.city.Id}, result.city); @@ -37,7 +37,7 @@ public class CityController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class CityController : ControllerBase [HttpGet("{id}")] public async Task GetCity(int id, [FromQuery] string? fields) { - if (!await _cityManagementService.IsCityExists(id)) - { - return NotFound(); - } - var result = await _cityManagementService.GetCity(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.city); @@ -75,7 +70,7 @@ public class CityController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.city); @@ -84,16 +79,11 @@ public class CityController : ControllerBase [HttpDelete("{id}")] public async Task DeleteCountry(int id) { - if (!await _cityManagementService.IsCityExists(id)) - { - return NotFound(); - } - var result = await _cityManagementService.DeleteCity(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/CompanyController.cs b/Server/Controllers/CompanyController.cs index 3cddc1d..a01e0a7 100644 --- a/Server/Controllers/CompanyController.cs +++ b/Server/Controllers/CompanyController.cs @@ -24,7 +24,7 @@ public class CompanyController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetCompany), new {id = result.company.Id}, result.company); @@ -37,7 +37,7 @@ public class CompanyController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class CompanyController : ControllerBase [HttpGet("{id}")] public async Task GetCompany(int id, [FromQuery] string? fields) { - if (!await _companyManagementService.IsCompanyExists(id)) - { - return NotFound(); - } - var result = await _companyManagementService.GetCompany(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.company); @@ -66,16 +61,11 @@ public class CompanyController : ControllerBase [HttpPut("{id}")] public async Task UpdateCompany(int id, UpdateCompanyDto company) { - if (id != company.Id) - { - return BadRequest(); - } - var result = await _companyManagementService.UpdateCompany(company); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.company); @@ -84,16 +74,11 @@ public class CompanyController : ControllerBase [HttpDelete("{id}")] public async Task DeleteCompany(int id) { - if (!await _companyManagementService.IsCompanyExists(id)) - { - return NotFound(); - } - var result = await _companyManagementService.DeleteCompany(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/CountryController.cs b/Server/Controllers/CountryController.cs index f985d35..d4d353b 100644 --- a/Server/Controllers/CountryController.cs +++ b/Server/Controllers/CountryController.cs @@ -24,7 +24,7 @@ public class CountryController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetCountry), new {id = result.country.Id}, result.country); @@ -37,7 +37,7 @@ public class CountryController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class CountryController : ControllerBase [HttpGet("{id}")] public async Task GetCountry(int id, [FromQuery] string? fields) { - if (!await _countryManagementService.IsCountryExists(id)) - { - return NotFound(); - } - var result = await _countryManagementService.GetCountry(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.country); @@ -66,16 +61,11 @@ public class CountryController : ControllerBase [HttpPut("{id}")] public async Task UpdateCountry(int id, UpdateCountryDto country) { - if (id != country.Id) - { - return BadRequest(); - } - var result = await _countryManagementService.UpdateCountry(country); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.country); @@ -84,16 +74,11 @@ public class CountryController : ControllerBase [HttpDelete("{id}")] public async Task DeleteCountry(int id) { - if (!await _countryManagementService.IsCountryExists(id)) - { - return NotFound(); - } - var result = await _countryManagementService.DeleteCountry(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/ReviewController.cs b/Server/Controllers/ReviewController.cs index 24cab2f..0dc0250 100644 --- a/Server/Controllers/ReviewController.cs +++ b/Server/Controllers/ReviewController.cs @@ -24,7 +24,7 @@ public class ReviewController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetReview), new {id = result.review.Id}, result.review); @@ -37,7 +37,7 @@ public class ReviewController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class ReviewController : ControllerBase [HttpGet("{id}")] public async Task GetReview(int id, [FromQuery] string? fields) { - if (!await _reviewManagementService.IsReviewExists(id)) - { - return NotFound(); - } - var result = await _reviewManagementService.GetReview(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.review); @@ -66,16 +61,11 @@ public class ReviewController : ControllerBase [HttpPut("{id}")] public async Task UpdateReview(int id, UpdateReviewDto review) { - if (id != review.Id) - { - return BadRequest(); - } - var result = await _reviewManagementService.UpdateReview(review); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.review); @@ -84,16 +74,11 @@ public class ReviewController : ControllerBase [HttpDelete("{id}")] public async Task DeleteReview(int id) { - if (!await _reviewManagementService.IsReviewExists(id)) - { - return NotFound(); - } - var result = await _reviewManagementService.DeleteReview(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/RouteAddressController.cs b/Server/Controllers/RouteAddressController.cs index 75a2afb..f4cac3e 100644 --- a/Server/Controllers/RouteAddressController.cs +++ b/Server/Controllers/RouteAddressController.cs @@ -24,7 +24,7 @@ public class RouteAddressController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetRouteAddress), new {id = result.routeAddress.Id}, result.routeAddress); @@ -37,7 +37,7 @@ public class RouteAddressController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class RouteAddressController : ControllerBase [HttpGet("{id}")] public async Task GetRouteAddress(int id, [FromQuery] string? fields) { - if (!await _routeAddressManagementService.IsRouteAddressExists(id)) - { - return NotFound(); - } - var result = await _routeAddressManagementService.GetRouteAddress(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.routeAddress); @@ -66,16 +61,11 @@ public class RouteAddressController : ControllerBase [HttpPut("{id}")] public async Task UpdateRouteAddress(int id, UpdateRouteAddressDto routeAddress) { - if (id != routeAddress.Id) - { - return BadRequest(); - } - var result = await _routeAddressManagementService.UpdateRouteAddress(routeAddress); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.routeAddress); @@ -84,16 +74,11 @@ public class RouteAddressController : ControllerBase [HttpDelete("{id}")] public async Task DeleteRouteAddress(int id) { - if (!await _routeAddressManagementService.IsRouteAddressExists(id)) - { - return NotFound(); - } - var result = await _routeAddressManagementService.DeleteRouteAddress(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/RouteController.cs b/Server/Controllers/RouteController.cs index c8db57e..c899e76 100644 --- a/Server/Controllers/RouteController.cs +++ b/Server/Controllers/RouteController.cs @@ -24,7 +24,7 @@ public class RouteController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetRoute), new {id = result.route.Id}, result.route); @@ -50,7 +50,7 @@ public class RouteController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -85,7 +85,7 @@ public class RouteController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.route); @@ -103,7 +103,7 @@ public class RouteController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.route); @@ -121,7 +121,7 @@ public class RouteController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.route); @@ -139,7 +139,7 @@ public class RouteController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/StateController.cs b/Server/Controllers/StateController.cs index bfa0be3..c624589 100644 --- a/Server/Controllers/StateController.cs +++ b/Server/Controllers/StateController.cs @@ -24,7 +24,7 @@ public class StateController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetState), new {id = result.state.Id}, result.state); @@ -37,7 +37,7 @@ public class StateController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class StateController : ControllerBase [HttpGet("{id}")] public async Task GetState(int id, [FromQuery] string? fields) { - if (!await _stateManagementService.IsStateExists(id)) - { - return NotFound(); - } - var result = await _stateManagementService.GetState(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.state); @@ -75,7 +70,7 @@ public class StateController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.state); @@ -84,16 +79,11 @@ public class StateController : ControllerBase [HttpDelete("{id}")] public async Task DeleteState(int id) { - if (!await _stateManagementService.IsStateExists(id)) - { - return NotFound(); - } - var result = await _stateManagementService.DeleteState(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/TicketController.cs b/Server/Controllers/TicketController.cs index e40a04a..b6a3822 100644 --- a/Server/Controllers/TicketController.cs +++ b/Server/Controllers/TicketController.cs @@ -24,7 +24,7 @@ public class TicketController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetTicket), new {id = result.ticket.Id}, result.ticket); @@ -37,7 +37,7 @@ public class TicketController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class TicketController : ControllerBase [HttpGet("{id}")] public async Task GetTicket(int id, [FromQuery] string? fields) { - if (!await _ticketManagementService.IsTicketExists(id)) - { - return NotFound(); - } - var result = await _ticketManagementService.GetTicket(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.ticket); @@ -66,16 +61,11 @@ public class TicketController : ControllerBase [HttpPut("{id}")] public async Task UpdateTicket(int id, UpdateTicketDto ticket) { - if (id != ticket.Id) - { - return BadRequest(); - } - var result = await _ticketManagementService.UpdateTicket(ticket); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.ticket); @@ -84,16 +74,11 @@ public class TicketController : ControllerBase [HttpDelete("{id}")] public async Task DeleteTicket(int id) { - if (!await _ticketManagementService.IsTicketExists(id)) - { - return NotFound(); - } - var result = await _ticketManagementService.DeleteTicket(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/VehicleController.cs b/Server/Controllers/VehicleController.cs index 01513bd..3e93887 100644 --- a/Server/Controllers/VehicleController.cs +++ b/Server/Controllers/VehicleController.cs @@ -24,7 +24,7 @@ public class VehicleController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetVehicle), new {id = result.vehicle.Id}, result.vehicle); @@ -37,7 +37,7 @@ public class VehicleController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -48,16 +48,11 @@ public class VehicleController : ControllerBase [HttpGet("{id}")] public async Task GetVehicle(int id, [FromQuery] string? fields) { - if (!await _vehicleManagementService.IsVehicleExists(id)) - { - return NotFound(); - } - var result = await _vehicleManagementService.GetVehicle(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.vehicle); @@ -66,16 +61,11 @@ public class VehicleController : ControllerBase [HttpPut("{id}")] public async Task UpdateVehicle(int id, UpdateVehicleDto vehicle) { - if (id != vehicle.Id) - { - return BadRequest(); - } - var result = await _vehicleManagementService.UpdateVehicle(vehicle); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.vehicle); @@ -84,16 +74,11 @@ public class VehicleController : ControllerBase [HttpDelete("{id}")] public async Task DeleteVehicle(int id) { - if (!await _vehicleManagementService.IsVehicleExists(id)) - { - return NotFound(); - } - var result = await _vehicleManagementService.DeleteVehicle(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Controllers/VehicleEnrollmentController.cs b/Server/Controllers/VehicleEnrollmentController.cs index c622d82..97929fd 100644 --- a/Server/Controllers/VehicleEnrollmentController.cs +++ b/Server/Controllers/VehicleEnrollmentController.cs @@ -25,7 +25,7 @@ public class VehicleEnrollmentController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return CreatedAtAction(nameof(GetEnrollment), new {id = result.enrollment.Id}, result.enrollment); @@ -38,7 +38,7 @@ public class VehicleEnrollmentController : ControllerBase if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(result.pagingMetadata)); @@ -49,16 +49,11 @@ public class VehicleEnrollmentController : ControllerBase [HttpGet("{id}")] public async Task GetEnrollment(int id, [FromQuery] string? fields) { - if (!await _vehicleEnrollmentManagementService.IsEnrollmentExists(id)) - { - return NotFound(); - } - var result = await _vehicleEnrollmentManagementService.GetEnrollment(id, fields); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.enrollment); @@ -67,16 +62,11 @@ public class VehicleEnrollmentController : ControllerBase [HttpPut("{id}")] public async Task UpdateVehicle(int id, UpdateVehicleEnrollmentDto enrollment) { - if (id != enrollment.Id) - { - return BadRequest(); - } - var result = await _vehicleEnrollmentManagementService.UpdateEnrollment(enrollment); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return Ok(result.enrollment); @@ -85,16 +75,11 @@ public class VehicleEnrollmentController : ControllerBase [HttpDelete("{id}")] public async Task DeleteEnrollment(int id) { - if (!await _vehicleEnrollmentManagementService.IsEnrollmentExists(id)) - { - return NotFound(); - } - var result = await _vehicleEnrollmentManagementService.DeleteEnrollment(id); if (!result.isSucceed) { - return BadRequest(result.message); + return result.actionResult; } return NoContent(); diff --git a/Server/Program.cs b/Server/Program.cs index a76ac41..07f9a26 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -105,41 +105,20 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper
>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, SortHelper>(); - -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper
>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); - builder.Services.AddScoped, SortHelper>(); -builder.Services.AddScoped, DataShaper>(); -builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); builder.Services.AddScoped, DataShaper>(); builder.Services.AddScoped, DataShaper>(); +builder.Services.AddScoped, DataShaper>(); builder.Services.AddScoped, Pager>(); diff --git a/Server/Services/AddressManagementService.cs b/Server/Services/AddressManagementService.cs index 7974d1d..915ba24 100644 --- a/Server/Services/AddressManagementService.cs +++ b/Server/Services/AddressManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,31 +15,33 @@ public class AddressManagementService : IAddressManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper
_addressSortHelper; - private readonly IDataShaper
_addressDataShaper; + private readonly ISortHelper _addressSortHelper; + private readonly IDataShaper _addressDataShaper; + private readonly IPager _pager; public AddressManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper
addressSortHelper, - IDataShaper
addressDataShaper) + IMapper mapper, ISortHelper addressSortHelper, + IDataShaper addressDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _addressSortHelper = addressSortHelper; _addressDataShaper = addressDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, AddressDto address)> AddAddress(CreateAddressDto createAddressDto) + public async Task<(bool isSucceed, IActionResult? actionResult, AddressDto address)> AddAddress(CreateAddressDto createAddressDto) { var address = _mapper.Map
(createAddressDto); await _dbContext.Addresses.AddAsync(address); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(address)); + return (true, null, _mapper.Map(address)); } - public async Task<(bool isSucceed, string message, IEnumerable addresses, - PagingMetadata
pagingMetadata)> GetAddresses(AddressParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable addresses, + PagingMetadata pagingMetadata)> GetAddresses(AddressParameters parameters) { var dbAddresses = _dbContext.Addresses.Include(a => a.City) .ThenInclude(c => c.State).ThenInclude(s => s.Country) @@ -47,26 +51,23 @@ public class AddressManagementService : IAddressManagementService FilterByAddressName(ref dbAddresses, parameters.Name); FilterByCityId(ref dbAddresses, parameters.CityId); + + var addressDtos = dbAddresses.ToList().ConvertAll(a => _mapper.Map(a)); + var shapedData = _addressDataShaper.ShapeData(addressDtos, parameters.Fields).AsQueryable(); + try { - dbAddresses = _addressSortHelper.ApplySort(dbAddresses, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbAddresses.Any(); + shapedData = _addressSortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null, null)!; } - - var pagingMetadata = ApplyPaging(ref dbAddresses, parameters.PageNumber, - parameters.PageSize); - - var shapedAddressesData = _addressDataShaper.ShapeData(dbAddresses, parameters.Fields); - var addressDtos = shapedAddressesData.ToList().ConvertAll(a => _mapper.Map(a)); - return (true, "", addressDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void SearchByAllAddressFields(ref IQueryable
addresses, string? search) @@ -102,45 +103,32 @@ public class AddressManagementService : IAddressManagementService addresses = addresses.Where(a => a.Name.ToLower().Contains(addressName.Trim().ToLower())); } - - PagingMetadata
ApplyPaging(ref IQueryable
addresses, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata
(addresses, - pageNumber, pageSize); - - addresses = addresses - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, AddressDto address)> GetAddress(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject address)> GetAddress(int id, string? fields) { + if (!await IsAddressExists(id)) + { + return (false, new NotFoundResult(), null!); + } + var dbAddress = await _dbContext.Addresses.Where(a => a.Id == id) .Include(a => a.City).ThenInclude(c => c.State) .ThenInclude(s => s.Country) - .FirstOrDefaultAsync(); + .FirstAsync(); - if (dbAddress == null) - { - return (false, $"Address doesn't exist", null)!; - } - if (String.IsNullOrWhiteSpace(fields)) { fields = AddressParameters.DefaultFields; } - var shapedAddressData = _addressDataShaper.ShapeData(dbAddress, fields); - var addressDto = _mapper.Map(shapedAddressData); + var addressDto = _mapper.Map(dbAddress); + var shapedData = _addressDataShaper.ShapeData(addressDto, fields); - return (true, "", addressDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateAddressDto address)> UpdateAddress(UpdateAddressDto updateAddressDto) + public async Task<(bool isSucceed, IActionResult? actionResult, AddressDto address)> UpdateAddress(UpdateAddressDto updateAddressDto) { var address = _mapper.Map
(updateAddressDto); _dbContext.Entry(address).State = EntityState.Modified; @@ -153,30 +141,28 @@ public class AddressManagementService : IAddressManagementService { if (!await IsAddressExists(updateAddressDto.Id)) { - return (false, $"Address with id:{updateAddressDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } - - throw; } - var dbAddress = await _dbContext.Addresses.FirstOrDefaultAsync(a => a.Id == address.Id); + var dbAddress = await _dbContext.Addresses.FirstAsync(a => a.Id == address.Id); - return (true, String.Empty, _mapper.Map(dbAddress)); + return (true, null, _mapper.Map(dbAddress)); } - public async Task<(bool isSucceed, string message)> DeleteAddress(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteAddress(int id) { var dbAddress = await _dbContext.Addresses.FirstOrDefaultAsync(a => a.Id == id); - + if (dbAddress == null) { - return (false, $"Address with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } - + _dbContext.Addresses.Remove(dbAddress); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsAddressExists(int id) diff --git a/Server/Services/CityManagementService.cs b/Server/Services/CityManagementService.cs index 6f0a7ea..ae73db2 100644 --- a/Server/Services/CityManagementService.cs +++ b/Server/Services/CityManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,31 +15,33 @@ public class CityManagementService : ICityManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _citySortHelper; - private readonly IDataShaper _cityDataShaper; + private readonly ISortHelper _citySortHelper; + private readonly IDataShaper _cityDataShaper; + private readonly IPager _pager; public CityManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper citySortHelper, - IDataShaper cityDataShaper) + IMapper mapper, ISortHelper citySortHelper, + IDataShaper cityDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _citySortHelper = citySortHelper; _cityDataShaper = cityDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, CityDto city)> AddCity(CreateCityDto createCityDto) + public async Task<(bool isSucceed, IActionResult? actionResult, CityDto city)> AddCity(CreateCityDto createCityDto) { var city = _mapper.Map(createCityDto); await _dbContext.Cities.AddAsync(city); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(city)); + return (true, null, _mapper.Map(city)); } - public async Task<(bool isSucceed, string message, IEnumerable cities, - PagingMetadata pagingMetadata)> GetCities(CityParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable cities, + PagingMetadata pagingMetadata)> GetCities(CityParameters parameters) { var dbCities = _dbContext.Cities.Include(c => c.State) .ThenInclude(s => s.Country).Include(c => c.Addresses) @@ -47,26 +51,22 @@ public class CityManagementService : ICityManagementService FilterByCityName(ref dbCities, parameters.Name); FilterByStateId(ref dbCities, parameters.StateId); + var cityDtos = _mapper.ProjectTo(dbCities); + var shapedData = _cityDataShaper.ShapeData(cityDtos, parameters.Fields).AsQueryable(); + try { - dbCities = _citySortHelper.ApplySort(dbCities, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbCities.Any(); + shapedData = _citySortHelper.ApplySort(shapedData, parameters.Sort); } catch (Exception e) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null, null)!; } - - var pagingMetadata = ApplyPaging(ref dbCities, parameters.PageNumber, - parameters.PageSize); - - var shapedCitiesData = _cityDataShaper.ShapeData(dbCities, parameters.Fields); - var cityDtos = shapedCitiesData.ToList().ConvertAll(s => _mapper.Map(s)); - return (true, "", cityDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void SearchByAllCityFields(ref IQueryable cities, string? search) @@ -102,45 +102,32 @@ public class CityManagementService : ICityManagementService cities = cities.Where(s => s.Name.ToLower().Contains(cityName.Trim().ToLower())); } - - PagingMetadata ApplyPaging(ref IQueryable cities, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(cities, - pageNumber, pageSize); - - cities = cities - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, CityDto city)> GetCity(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject city)> GetCity(int id, string? fields) { + if (!await IsCityExists(id)) + { + return (false, new NotFoundResult(), null!); + } + var dbCity = await _dbContext.Cities.Where(s => s.Id == id) .Include(c => c.State).ThenInclude(s => s.Country) .Include(c => c.Addresses) - .FirstOrDefaultAsync(); + .FirstAsync(); - if (dbCity == null) - { - return (false, $"City doesn't exist", null)!; - } - if (String.IsNullOrWhiteSpace(fields)) { fields = CityParameters.DefaultFields; } - var shapedCityData = _cityDataShaper.ShapeData(dbCity, fields); - var cityDto = _mapper.Map(shapedCityData); + var cityDto = _mapper.Map(dbCity); + var shapedData = _cityDataShaper.ShapeData(cityDto, fields); - return (true, "", cityDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateCityDto city)> UpdateCity(UpdateCityDto updateCityDto) + public async Task<(bool isSucceed, IActionResult? actionResult, CityDto city)> UpdateCity(UpdateCityDto updateCityDto) { var city = _mapper.Map(updateCityDto); _dbContext.Entry(city).State = EntityState.Modified; @@ -153,30 +140,28 @@ public class CityManagementService : ICityManagementService { if (!await IsCityExists(updateCityDto.Id)) { - return (false, $"City with id:{updateCityDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null)!; } - - throw; } - var dbCity = await _dbContext.Cities.FirstOrDefaultAsync(s => s.Id == city.Id); + var dbCity = await _dbContext.Cities.FirstAsync(s => s.Id == city.Id); - return (true, String.Empty, _mapper.Map(dbCity)); + return (true, null, _mapper.Map(dbCity)); } - public async Task<(bool isSucceed, string message)> DeleteCity(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteCity(int id) { var dbCity = await _dbContext.Cities.FirstOrDefaultAsync(s => s.Id == id); - + if (dbCity == null) { - return (false, $"City with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } - + _dbContext.Cities.Remove(dbCity); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsCityExists(int id) diff --git a/Server/Services/CompanyManagementService.cs b/Server/Services/CompanyManagementService.cs index 644ade4..a54e3a8 100644 --- a/Server/Services/CompanyManagementService.cs +++ b/Server/Services/CompanyManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,61 +15,57 @@ public class CompanyManagementService : ICompanyManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _companySortHelper; - private readonly IDataShaper _companyDataShaper; + private readonly ISortHelper _companySortHelper; + private readonly IDataShaper _companyDataShaper; + private readonly IPager _pager; public CompanyManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper companySortHelper, - IDataShaper companyDataShaper) + IMapper mapper, ISortHelper companySortHelper, + IDataShaper companyDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _companySortHelper = companySortHelper; _companyDataShaper = companyDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, CompanyDto company)> AddCompany(CreateCompanyDto createCompanyDto) + public async Task<(bool isSucceed, IActionResult? actionResult, CompanyDto company)> AddCompany(CreateCompanyDto createCompanyDto) { var company = _mapper.Map(createCompanyDto); await _dbContext.Companies.AddAsync(company); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(company)); + return (true, null, _mapper.Map(company)); } - public async Task<(bool isSucceed, string message, IEnumerable companies, - PagingMetadata pagingMetadata)> GetCompanies(CompanyParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable companies, + PagingMetadata pagingMetadata)> GetCompanies(CompanyParameters parameters) { var dbCompanies = _dbContext.Companies .AsQueryable(); - var v = dbCompanies.Any(); - SearchByAllCompanyFields(ref dbCompanies, parameters.Search); FilterByCompanyName(ref dbCompanies, parameters.Name); FilterByCompanyOwnerId(ref dbCompanies, parameters.OwnerId); + + var companyDtos = _mapper.ProjectTo(dbCompanies); + var shapedData = _companyDataShaper.ShapeData(companyDtos, parameters.Fields).AsQueryable(); try { - dbCompanies = _companySortHelper.ApplySort(dbCompanies, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbCompanies.Any(); + shapedData = _companySortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null!, null!); } - - var pagingMetadata = ApplyPaging(ref dbCompanies, parameters.PageNumber, - parameters.PageSize); - - var shapedCompaniesData = _companyDataShaper.ShapeData(dbCompanies, parameters.Fields); - var companyDtos = shapedCompaniesData.ToList().ConvertAll(c => _mapper.Map(c)); - return (true, "", companyDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void SearchByAllCompanyFields(ref IQueryable companies, string? search) @@ -102,43 +100,30 @@ public class CompanyManagementService : ICompanyManagementService companies = companies.Where(c => c.OwnerId == ownerId); } - - PagingMetadata ApplyPaging(ref IQueryable companies, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(companies, - pageNumber, pageSize); - - companies = companies - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, CompanyDto company)> GetCompany(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject company)> GetCompany(int id, string? fields) { - var dbCompany = await _dbContext.Companies.Where(c => c.Id == id) - .FirstOrDefaultAsync(); - - if (dbCompany == null) + if (!await IsCompanyExists(id)) { - return (false, $"Company doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } + var dbCompany = await _dbContext.Companies.Where(c => c.Id == id) + .FirstAsync(); + if (String.IsNullOrWhiteSpace(fields)) { fields = CompanyParameters.DefaultFields; } - var shapedCompanyData = _companyDataShaper.ShapeData(dbCompany, fields); - var companyDto = _mapper.Map(shapedCompanyData); + var companyDto = _mapper.Map(dbCompany); + var shapedData = _companyDataShaper.ShapeData(companyDto, fields); - return (true, "", companyDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateCompanyDto company)> UpdateCompany(UpdateCompanyDto updateCompanyDto) + public async Task<(bool isSucceed, IActionResult? actionResult, CompanyDto company)> UpdateCompany(UpdateCompanyDto updateCompanyDto) { var company = _mapper.Map(updateCompanyDto); _dbContext.Entry(company).State = EntityState.Modified; @@ -151,30 +136,28 @@ public class CompanyManagementService : ICompanyManagementService { if (!await IsCompanyExists(updateCompanyDto.Id)) { - return (false, $"Company with id:{updateCompanyDto.Id} doesn'c exist", null)!; + return (false, new BadRequestResult(), null!); } - - throw; } - var dbCompany = await _dbContext.Companies.FirstOrDefaultAsync(c => c.Id == company.Id); + var dbCompany = await _dbContext.Companies.FirstAsync(c => c.Id == company.Id); - return (true, String.Empty, _mapper.Map(dbCompany)); + return (true, null, _mapper.Map(dbCompany)); } - public async Task<(bool isSucceed, string message)> DeleteCompany(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteCompany(int id) { var dbCompany = await _dbContext.Companies.FirstOrDefaultAsync(c => c.Id == id); if (dbCompany == null) { - return (false, $"Company with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } _dbContext.Companies.Remove(dbCompany); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsCompanyExists(int id) diff --git a/Server/Services/CountryManagementService.cs b/Server/Services/CountryManagementService.cs index 6942300..4d7f5ba 100644 --- a/Server/Services/CountryManagementService.cs +++ b/Server/Services/CountryManagementService.cs @@ -1,5 +1,6 @@ using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -14,31 +15,33 @@ public class CountryManagementService : ICountryManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _countrySortHelper; - private readonly IDataShaper _countryDataShaper; + private readonly ISortHelper _countrySortHelper; + private readonly IDataShaper _countryDataShaper; + private readonly IPager _pager; public CountryManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper countrySortHelper, - IDataShaper countryDataShaper) + IMapper mapper, ISortHelper countrySortHelper, + IDataShaper countryDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _countrySortHelper = countrySortHelper; _countryDataShaper = countryDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, CountryDto country)> AddCountry(CreateCountryDto createCountryDto) + public async Task<(bool isSucceed, IActionResult? actionResult, CountryDto country)> AddCountry(CreateCountryDto createCountryDto) { var country = _mapper.Map(createCountryDto); await _dbContext.Countries.AddAsync(country); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(country)); + return (true, null, _mapper.Map(country)); } - public async Task<(bool isSucceed, string message, IEnumerable countries, - PagingMetadata pagingMetadata)> GetCountries(CountryParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable countries, + PagingMetadata pagingMetadata)> GetCountries(CountryParameters parameters) { var dbCountries = _dbContext.Countries.Include(c => c.States) .ThenInclude(s => s.Cities).ThenInclude(c => c.Addresses) @@ -48,26 +51,22 @@ public class CountryManagementService : ICountryManagementService FilterByCountryCode(ref dbCountries, parameters.Code); FilterByCountryName(ref dbCountries, parameters.Name); + var countryDtos = _mapper.ProjectTo(dbCountries); + var shapedData = _countryDataShaper.ShapeData(countryDtos, parameters.Fields).AsQueryable(); + try { - dbCountries = _countrySortHelper.ApplySort(dbCountries, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbCountries.Any(); + shapedData = _countrySortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null, null)!; } - - var pagingMetadata = ApplyPaging(ref dbCountries, parameters.PageNumber, - parameters.PageSize); - - var shapedCountiesData = _countryDataShaper.ShapeData(dbCountries, parameters.Fields); - var countryDtos = shapedCountiesData.ToList().ConvertAll(d => _mapper.Map(d)); - return (true, "", countryDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void SearchByAllCountryFields(ref IQueryable countries, string? search) @@ -105,45 +104,32 @@ public class CountryManagementService : ICountryManagementService countries = countries.Where(c => c.Name.ToLower().Contains(countryName.Trim().ToLower())); } - - PagingMetadata ApplyPaging(ref IQueryable countries, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(countries, - pageNumber, pageSize); - - countries = countries - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, CountryDto country)> GetCountry(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject country)> GetCountry(int id, string? fields) { + if (!await IsCountryExists(id)) + { + return (false, new NotFoundResult(), null!); + } + var dbCountry = await _dbContext.Countries.Where(c => c.Id == id) .Include(c => c.States).ThenInclude(s => s.Cities) .ThenInclude(c => c.Addresses) - .FirstOrDefaultAsync(); - - if (dbCountry == null) - { - return (false, $"Country doesn't exist", null)!; - } + .FirstAsync(); if (String.IsNullOrWhiteSpace(fields)) { fields = CountryParameters.DefaultFields; } - var shapedCountryData = _countryDataShaper.ShapeData(dbCountry, fields); - var countryDto = _mapper.Map(shapedCountryData); + var countryDto = _mapper.Map(dbCountry); + var shapedData = _countryDataShaper.ShapeData(countryDto, fields); - return (true, "", countryDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateCountryDto country)> UpdateCountry(UpdateCountryDto updateCountryDto) + public async Task<(bool isSucceed, IActionResult? actionResult, CountryDto country)> UpdateCountry(UpdateCountryDto updateCountryDto) { var country = _mapper.Map(updateCountryDto); _dbContext.Entry(country).State = EntityState.Modified; @@ -156,30 +142,28 @@ public class CountryManagementService : ICountryManagementService { if (!await IsCountryExists(updateCountryDto.Id)) { - return (false, $"Country with id:{updateCountryDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } - - throw; } - var dbCountry = await _dbContext.Countries.FirstOrDefaultAsync(c => c.Id == country.Id); + var dbCountry = await _dbContext.Countries.FirstAsync(c => c.Id == country.Id); - return (true, String.Empty, _mapper.Map(dbCountry)); + return (true, null, _mapper.Map(dbCountry)); } - public async Task<(bool isSucceed, string message)> DeleteCountry(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteCountry(int id) { var dbCountry = await _dbContext.Countries.FirstOrDefaultAsync(c => c.Id == id); if (dbCountry == null) { - return (false, $"Country with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } _dbContext.Countries.Remove(dbCountry); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsCountryExists(int id) diff --git a/Server/Services/IAddressManagementService.cs b/Server/Services/IAddressManagementService.cs index f833407..eef33d2 100644 --- a/Server/Services/IAddressManagementService.cs +++ b/Server/Services/IAddressManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface IAddressManagementService { - Task<(bool isSucceed, string message, AddressDto address)> AddAddress(CreateAddressDto createAddressDto); - Task<(bool isSucceed, string message, IEnumerable addresses, - PagingMetadata
pagingMetadata)> GetAddresses(AddressParameters parameters); - Task<(bool isSucceed, string message, AddressDto address)> GetAddress(int id, string? fields); - Task<(bool isSucceed, string message, UpdateAddressDto address)> UpdateAddress(UpdateAddressDto updateAddressDto); - Task<(bool isSucceed, string message)> DeleteAddress(int id); + Task<(bool isSucceed, IActionResult? actionResult, AddressDto address)> AddAddress(CreateAddressDto createAddressDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable addresses, + PagingMetadata pagingMetadata)> GetAddresses(AddressParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject address)> GetAddress(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, AddressDto address)> UpdateAddress(UpdateAddressDto updateAddressDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteAddress(int id); Task IsAddressExists(int id); } \ No newline at end of file diff --git a/Server/Services/ICityManagementService.cs b/Server/Services/ICityManagementService.cs index db1d3c4..ff20640 100644 --- a/Server/Services/ICityManagementService.cs +++ b/Server/Services/ICityManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface ICityManagementService { - Task<(bool isSucceed, string message, CityDto city)> AddCity(CreateCityDto createCityDto); - Task<(bool isSucceed, string message, IEnumerable cities, - PagingMetadata pagingMetadata)> GetCities(CityParameters parameters); - Task<(bool isSucceed, string message, CityDto city)> GetCity(int id, string? fields); - Task<(bool isSucceed, string message, UpdateCityDto city)> UpdateCity(UpdateCityDto updateCityDto); - Task<(bool isSucceed, string message)> DeleteCity(int id); + Task<(bool isSucceed, IActionResult? actionResult, CityDto city)> AddCity(CreateCityDto createCityDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable cities, + PagingMetadata pagingMetadata)> GetCities(CityParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject city)> GetCity(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, CityDto city)> UpdateCity(UpdateCityDto updateCityDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteCity(int id); Task IsCityExists(int id); } \ No newline at end of file diff --git a/Server/Services/ICompanyManagementService.cs b/Server/Services/ICompanyManagementService.cs index 5d267a2..5020592 100644 --- a/Server/Services/ICompanyManagementService.cs +++ b/Server/Services/ICompanyManagementService.cs @@ -1,3 +1,5 @@ +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using Server.Models; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; @@ -7,11 +9,11 @@ namespace Server.Services; public interface ICompanyManagementService { - Task<(bool isSucceed, string message, CompanyDto company)> AddCompany(CreateCompanyDto createCompanyDto); - Task<(bool isSucceed, string message, IEnumerable companies, - PagingMetadata pagingMetadata)> GetCompanies(CompanyParameters parameters); - Task<(bool isSucceed, string message, CompanyDto company)> GetCompany(int id, string? fields); - Task<(bool isSucceed, string message, UpdateCompanyDto company)> UpdateCompany(UpdateCompanyDto updateCompanyDto); - Task<(bool isSucceed, string message)> DeleteCompany(int id); + Task<(bool isSucceed, IActionResult? actionResult, CompanyDto company)> AddCompany(CreateCompanyDto createCompanyDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable companies, + PagingMetadata pagingMetadata)> GetCompanies(CompanyParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject company)> GetCompany(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, CompanyDto company)> UpdateCompany(UpdateCompanyDto updateCompanyDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteCompany(int id); Task IsCompanyExists(int id); } \ No newline at end of file diff --git a/Server/Services/ICountryManagementService.cs b/Server/Services/ICountryManagementService.cs index 90525a0..03d48b9 100644 --- a/Server/Services/ICountryManagementService.cs +++ b/Server/Services/ICountryManagementService.cs @@ -1,3 +1,5 @@ +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using Server.Models; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; @@ -7,11 +9,11 @@ namespace Server.Services; public interface ICountryManagementService { - Task<(bool isSucceed, string message, CountryDto country)> AddCountry(CreateCountryDto createCountryDto); - Task<(bool isSucceed, string message, IEnumerable countries, - PagingMetadata pagingMetadata)> GetCountries(CountryParameters parameters); - Task<(bool isSucceed, string message, CountryDto country)> GetCountry(int id, string? fields); - Task<(bool isSucceed, string message, UpdateCountryDto country)> UpdateCountry(UpdateCountryDto updateCountryDto); - Task<(bool isSucceed, string message)> DeleteCountry(int id); + Task<(bool isSucceed, IActionResult? actionResult, CountryDto country)> AddCountry(CreateCountryDto createCountryDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable countries, + PagingMetadata pagingMetadata)> GetCountries(CountryParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject country)> GetCountry(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, CountryDto country)> UpdateCountry(UpdateCountryDto updateCountryDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteCountry(int id); Task IsCountryExists(int id); } \ No newline at end of file diff --git a/Server/Services/IReviewManagementService.cs b/Server/Services/IReviewManagementService.cs index ae53c71..8a67969 100644 --- a/Server/Services/IReviewManagementService.cs +++ b/Server/Services/IReviewManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface IReviewManagementService { - Task<(bool isSucceed, string message, ReviewDto review)> AddReview(CreateReviewDto createReviewDto); - Task<(bool isSucceed, string message, IEnumerable reviews, - PagingMetadata pagingMetadata)> GetReviews(ReviewParameters parameters); - Task<(bool isSucceed, string message, ReviewDto review)> GetReview(int id, string? fields); - Task<(bool isSucceed, string message, UpdateReviewDto review)> UpdateReview(UpdateReviewDto updateReviewDto); - Task<(bool isSucceed, string message)> DeleteReview(int id); + Task<(bool isSucceed, IActionResult? actionResult, ReviewDto review)> AddReview(CreateReviewDto createReviewDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable reviews, + PagingMetadata pagingMetadata)> GetReviews(ReviewParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject review)> GetReview(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, ReviewDto review)> UpdateReview(UpdateReviewDto updateReviewDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteReview(int id); Task IsReviewExists(int id); } \ No newline at end of file diff --git a/Server/Services/IRouteAddressManagementService.cs b/Server/Services/IRouteAddressManagementService.cs index b063b8e..04170b6 100644 --- a/Server/Services/IRouteAddressManagementService.cs +++ b/Server/Services/IRouteAddressManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface IRouteAddressManagementService { - Task<(bool isSucceed, string message, RouteAddressDto routeAddress)> AddRouteAddress(CreateRouteAddressDto createRouteAddressDto); - Task<(bool isSucceed, string message, IEnumerable routeAddresses, - PagingMetadata pagingMetadata)> GetRouteAddresses(RouteAddressParameters parameters); - Task<(bool isSucceed, string message, RouteAddressDto routeAddress)> GetRouteAddress(int id, string? fields); - Task<(bool isSucceed, string message, UpdateRouteAddressDto routeAddress)> UpdateRouteAddress(UpdateRouteAddressDto updateRouteAddressDto); - Task<(bool isSucceed, string message)> DeleteRouteAddress(int id); + Task<(bool isSucceed, IActionResult? actionResult, RouteAddressDto routeAddress)> AddRouteAddress(CreateRouteAddressDto createRouteAddressDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable routeAddresses, + PagingMetadata pagingMetadata)> GetRouteAddresses(RouteAddressParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject routeAddress)> GetRouteAddress(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, RouteAddressDto routeAddress)> UpdateRouteAddress(UpdateRouteAddressDto updateRouteAddressDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteRouteAddress(int id); Task IsRouteAddressExists(int id); } \ No newline at end of file diff --git a/Server/Services/IRouteManagementService.cs b/Server/Services/IRouteManagementService.cs index 0c888c3..1d61320 100644 --- a/Server/Services/IRouteManagementService.cs +++ b/Server/Services/IRouteManagementService.cs @@ -9,15 +9,15 @@ namespace Server.Services; public interface IRouteManagementService { - Task<(bool isSucceed, string message, RouteDto route)> AddRoute(CreateRouteDto createRouteDto); + Task<(bool isSucceed, IActionResult? actionResult, RouteDto route)> AddRoute(CreateRouteDto createRouteDto); Task<(bool isSucceed, IActionResult? actionResult, RouteWithAddressesDto route)> AddRouteWithAddresses(CreateRouteWithAddressesDto createRouteWithAddressesDto); - Task<(bool isSucceed, string message, IEnumerable routes, + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable routes, PagingMetadata pagingMetadata)> GetRoutes(RouteParameters parameters); Task<(bool isSucceed, IActionResult? actionResult, IEnumerable routes, PagingMetadata pagingMetadata)> GetRoutesWithAddresses(RouteWithAddressesParameters parameters); - Task<(bool isSucceed, string message, ExpandoObject route)> GetRoute(int id, string? fields); - Task<(bool isSucceed, string message, ExpandoObject route)> GetRouteWithAddresses(int id, string? fields); - Task<(bool isSucceed, string message, UpdateRouteDto route)> UpdateRoute(UpdateRouteDto updateRouteDto); - Task<(bool isSucceed, string message)> DeleteRoute(int id); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject route)> GetRoute(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject route)> GetRouteWithAddresses(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, UpdateRouteDto route)> UpdateRoute(UpdateRouteDto updateRouteDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteRoute(int id); Task IsRouteExists(int id); } \ No newline at end of file diff --git a/Server/Services/IStateManagementService.cs b/Server/Services/IStateManagementService.cs index 066beb5..b1cacff 100644 --- a/Server/Services/IStateManagementService.cs +++ b/Server/Services/IStateManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface IStateManagementService { - Task<(bool isSucceed, string message, StateDto state)> AddState(CreateStateDto createStateDto); - Task<(bool isSucceed, string message, IEnumerable states, - PagingMetadata pagingMetadata)> GetStates(StateParameters parameters); - Task<(bool isSucceed, string message, StateDto state)> GetState(int id, string? fields); - Task<(bool isSucceed, string message, UpdateStateDto state)> UpdateState(UpdateStateDto updateStateDto); - Task<(bool isSucceed, string message)> DeleteState(int id); + Task<(bool isSucceed, IActionResult? actionResult, StateDto state)> AddState(CreateStateDto createStateDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable states, + PagingMetadata pagingMetadata)> GetStates(StateParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject state)> GetState(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, StateDto state)> UpdateState(UpdateStateDto updateStateDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteState(int id); Task IsStateExists(int id); } \ No newline at end of file diff --git a/Server/Services/ITicketManagementService.cs b/Server/Services/ITicketManagementService.cs index f0afa61..991bcdc 100644 --- a/Server/Services/ITicketManagementService.cs +++ b/Server/Services/ITicketManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface ITicketManagementService { - Task<(bool isSucceed, string message, TicketDto ticket)> AddTicket(CreateTicketDto createTicketDto); - Task<(bool isSucceed, string message, IEnumerable tickets, - PagingMetadata pagingMetadata)> GetTickets(TicketParameters parameters); - Task<(bool isSucceed, string message, TicketDto ticket)> GetTicket(int id, string? fields); - Task<(bool isSucceed, string message, UpdateTicketDto ticket)> UpdateTicket(UpdateTicketDto updateTicketDto); - Task<(bool isSucceed, string message)> DeleteTicket(int id); + Task<(bool isSucceed, IActionResult? actionResult, TicketDto ticket)> AddTicket(CreateTicketDto createTicketDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable tickets, + PagingMetadata pagingMetadata)> GetTickets(TicketParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject ticket)> GetTicket(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, TicketDto ticket)> UpdateTicket(UpdateTicketDto updateTicketDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteTicket(int id); Task IsTicketExists(int id); } \ No newline at end of file diff --git a/Server/Services/IVehicleEnrollmentManagementService.cs b/Server/Services/IVehicleEnrollmentManagementService.cs index 8afef39..4e2e4bf 100644 --- a/Server/Services/IVehicleEnrollmentManagementService.cs +++ b/Server/Services/IVehicleEnrollmentManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface IVehicleEnrollmentManagementService { - Task<(bool isSucceed, string message, VehicleEnrollmentDto enrollment)> AddEnrollment(CreateVehicleEnrollmentDto createEnrollmentDto); - Task<(bool isSucceed, string message, IEnumerable enrollments, - PagingMetadata pagingMetadata)> GetEnrollments(VehicleEnrollmentParameters parameters); - Task<(bool isSucceed, string message, VehicleEnrollmentDto enrollment)> GetEnrollment(int id, string? fields); - Task<(bool isSucceed, string message, UpdateVehicleEnrollmentDto enrollment)> UpdateEnrollment(UpdateVehicleEnrollmentDto updateEnrollmentDto); - Task<(bool isSucceed, string message)> DeleteEnrollment(int id); + Task<(bool isSucceed, IActionResult? actionResult, VehicleEnrollmentDto enrollment)> AddEnrollment(CreateVehicleEnrollmentDto createEnrollmentDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable enrollments, + PagingMetadata pagingMetadata)> GetEnrollments(VehicleEnrollmentParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject enrollment)> GetEnrollment(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, VehicleEnrollmentDto enrollment)> UpdateEnrollment(UpdateVehicleEnrollmentDto updateEnrollmentDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteEnrollment(int id); Task IsEnrollmentExists(int id); } \ No newline at end of file diff --git a/Server/Services/IVehicleManagementService.cs b/Server/Services/IVehicleManagementService.cs index 443772b..88da190 100644 --- a/Server/Services/IVehicleManagementService.cs +++ b/Server/Services/IVehicleManagementService.cs @@ -1,4 +1,5 @@ -using Server.Models; +using System.Dynamic; +using Microsoft.AspNetCore.Mvc; using SharedModels.DataTransferObjects; using SharedModels.QueryParameters; using SharedModels.QueryParameters.Objects; @@ -7,11 +8,11 @@ namespace Server.Services; public interface IVehicleManagementService { - Task<(bool isSucceed, string message, VehicleDto vehicle)> AddVehicle(CreateVehicleDto createVehicleDto); - Task<(bool isSucceed, string message, IEnumerable vehicles, - PagingMetadata pagingMetadata)> GetVehicles(VehicleParameters parameters); - Task<(bool isSucceed, string message, VehicleDto vehicle)> GetVehicle(int id, string? fields); - Task<(bool isSucceed, string message, UpdateVehicleDto vehicle)> UpdateVehicle(UpdateVehicleDto updateVehicleDto); - Task<(bool isSucceed, string message)> DeleteVehicle(int id); + Task<(bool isSucceed, IActionResult? actionResult, VehicleDto vehicle)> AddVehicle(CreateVehicleDto createVehicleDto); + Task<(bool isSucceed, IActionResult? actionResult, IEnumerable vehicles, + PagingMetadata pagingMetadata)> GetVehicles(VehicleParameters parameters); + Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject vehicle)> GetVehicle(int id, string? fields); + Task<(bool isSucceed, IActionResult? actionResult, VehicleDto vehicle)> UpdateVehicle(UpdateVehicleDto updateVehicleDto); + Task<(bool isSucceed, IActionResult? actionResult)> DeleteVehicle(int id); Task IsVehicleExists(int id); } \ No newline at end of file diff --git a/Server/Services/ReviewManagementService.cs b/Server/Services/ReviewManagementService.cs index 2716390..7e68ba6 100644 --- a/Server/Services/ReviewManagementService.cs +++ b/Server/Services/ReviewManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,31 +15,33 @@ public class ReviewManagementService : IReviewManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _reviewSortHelper; - private readonly IDataShaper _reviewDataShaper; + private readonly ISortHelper _reviewSortHelper; + private readonly IDataShaper _reviewDataShaper; + private readonly IPager _pager; public ReviewManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper reviewSortHelper, - IDataShaper reviewDataShaper) + IMapper mapper, ISortHelper reviewSortHelper, + IDataShaper reviewDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _reviewSortHelper = reviewSortHelper; _reviewDataShaper = reviewDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, ReviewDto review)> AddReview(CreateReviewDto createReviewDto) + public async Task<(bool isSucceed, IActionResult? actionResult, ReviewDto review)> AddReview(CreateReviewDto createReviewDto) { var review = _mapper.Map(createReviewDto); await _dbContext.Reviews.AddAsync(review); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(review)); + return (true, null, _mapper.Map(review)); } - public async Task<(bool isSucceed, string message, IEnumerable reviews, - PagingMetadata pagingMetadata)> GetReviews(ReviewParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable reviews, + PagingMetadata pagingMetadata)> GetReviews(ReviewParameters parameters) { var dbReviews = _dbContext.Reviews .AsQueryable(); @@ -46,26 +50,22 @@ public class ReviewManagementService : IReviewManagementService FilterByReviewComment(ref dbReviews, parameters.Comment); FilterByReviewUserId(ref dbReviews, parameters.UserId); + var reviewDtos = _mapper.ProjectTo(dbReviews); + var shapedData = _reviewDataShaper.ShapeData(reviewDtos, parameters.Fields).AsQueryable(); + try { - dbReviews = _reviewSortHelper.ApplySort(dbReviews, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbReviews.Any(); + shapedData = _reviewSortHelper.ApplySort(shapedData, parameters.Sort); } catch (Exception e) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null!, null!); } - - var pagingMetadata = ApplyPaging(ref dbReviews, parameters.PageNumber, - parameters.PageSize); - - var shapedReviewsData = _reviewDataShaper.ShapeData(dbReviews, parameters.Fields); - var reviewDtos = shapedReviewsData.ToList().ConvertAll(r => _mapper.Map(r)); - return (true, "", reviewDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void FilterByReviewRating(ref IQueryable reviews, int? fromRating, int? toRating) @@ -103,43 +103,30 @@ public class ReviewManagementService : IReviewManagementService reviews = reviews.Where(r => r.UserId.Contains(userId.ToLower())); } - - PagingMetadata ApplyPaging(ref IQueryable reviews, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(reviews, - pageNumber, pageSize); - - reviews = reviews - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, ReviewDto review)> GetReview(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject review)> GetReview(int id, string? fields) { - var dbReview = await _dbContext.Reviews.Where(r => r.Id == id) - .FirstOrDefaultAsync(); - - if (dbReview == null) + if (!await IsReviewExists(id)) { - return (false, $"Review doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } + var dbReview = await _dbContext.Reviews.Where(r => r.Id == id) + .FirstAsync(); + if (String.IsNullOrWhiteSpace(fields)) { fields = ReviewParameters.DefaultFields; } - var shapedReviewData = _reviewDataShaper.ShapeData(dbReview, fields); - var reviewDto = _mapper.Map(shapedReviewData); + var reviewDto = _mapper.Map(dbReview); + var shapedData = _reviewDataShaper.ShapeData(reviewDto, fields); - return (true, "", reviewDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateReviewDto review)> UpdateReview(UpdateReviewDto updateReviewDto) + public async Task<(bool isSucceed, IActionResult? actionResult, ReviewDto review)> UpdateReview(UpdateReviewDto updateReviewDto) { var review = _mapper.Map(updateReviewDto); _dbContext.Entry(review).State = EntityState.Modified; @@ -152,30 +139,28 @@ public class ReviewManagementService : IReviewManagementService { if (!await IsReviewExists(updateReviewDto.Id)) { - return (false, $"Review with id:{updateReviewDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } - - throw; } - var dbReview = await _dbContext.Reviews.FirstOrDefaultAsync(r => r.Id == review.Id); + var dbReview = await _dbContext.Reviews.FirstAsync(r => r.Id == review.Id); - return (true, String.Empty, _mapper.Map(dbReview)); + return (true, null, _mapper.Map(dbReview)); } - public async Task<(bool isSucceed, string message)> DeleteReview(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteReview(int id) { var dbReview = await _dbContext.Reviews.FirstOrDefaultAsync(r => r.Id == id); if (dbReview == null) { - return (false, $"Review with id:{id} doesn't exist"); + return (false,new NotFoundResult()); } _dbContext.Reviews.Remove(dbReview); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsReviewExists(int id) diff --git a/Server/Services/RouteAddressManagementService.cs b/Server/Services/RouteAddressManagementService.cs index ec362f2..67d0fbb 100644 --- a/Server/Services/RouteAddressManagementService.cs +++ b/Server/Services/RouteAddressManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,31 +15,33 @@ public class RouteAddressManagementService : IRouteAddressManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _routeAddressSortHelper; - private readonly IDataShaper _routeAddressDataShaper; + private readonly ISortHelper _routeAddressSortHelper; + private readonly IDataShaper _routeAddressDataShaper; + private readonly IPager _pager; public RouteAddressManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper routeAddressSortHelper, - IDataShaper routeAddressDataShaper) + IMapper mapper, ISortHelper routeAddressSortHelper, + IDataShaper routeAddressDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _routeAddressSortHelper = routeAddressSortHelper; _routeAddressDataShaper = routeAddressDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, RouteAddressDto routeAddress)> AddRouteAddress(CreateRouteAddressDto createRouteAddressDto) + public async Task<(bool isSucceed, IActionResult? actionResult, RouteAddressDto routeAddress)> AddRouteAddress(CreateRouteAddressDto createRouteAddressDto) { var routeAddress = _mapper.Map(createRouteAddressDto); await _dbContext.RouteAddresses.AddAsync(routeAddress); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(routeAddress)); + return (true, null, _mapper.Map(routeAddress)); } - public async Task<(bool isSucceed, string message, IEnumerable routeAddresses, - PagingMetadata pagingMetadata)> GetRouteAddresses(RouteAddressParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable routeAddresses, + PagingMetadata pagingMetadata)> GetRouteAddresses(RouteAddressParameters parameters) { var dbRouteAddresses = _dbContext.RouteAddresses .AsQueryable(); @@ -45,26 +49,22 @@ public class RouteAddressManagementService : IRouteAddressManagementService FilterByRouteAddressRouteId(ref dbRouteAddresses, parameters.RouteId); FilterByRouteAddressAddressId(ref dbRouteAddresses, parameters.AddressId); + var routeAddressDtos = _mapper.ProjectTo(dbRouteAddresses); + var shapedData = _routeAddressDataShaper.ShapeData(routeAddressDtos, parameters.Fields).AsQueryable(); + try { - dbRouteAddresses = _routeAddressSortHelper.ApplySort(dbRouteAddresses, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbRouteAddresses.Any(); + shapedData = _routeAddressSortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null!, null!); } - - var pagingMetadata = ApplyPaging(ref dbRouteAddresses, parameters.PageNumber, - parameters.PageSize); - - var shapedRouteAddressesData = _routeAddressDataShaper.ShapeData(dbRouteAddresses, parameters.Fields); - var routeAddressDtos = shapedRouteAddressesData.ToList().ConvertAll(ra => _mapper.Map(ra)); - return (true, "", routeAddressDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void FilterByRouteAddressRouteId(ref IQueryable routeAddresses, int? routeId) @@ -87,43 +87,30 @@ public class RouteAddressManagementService : IRouteAddressManagementService routeAddresses = routeAddresses.Where(ra => ra.AddressId == addressId); } - - PagingMetadata ApplyPaging(ref IQueryable routeAddresses, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(routeAddresses, - pageNumber, pageSize); - - routeAddresses = routeAddresses - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, RouteAddressDto routeAddress)> GetRouteAddress(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject routeAddress)> GetRouteAddress(int id, string? fields) { - var dbRouteAddress = await _dbContext.RouteAddresses.Where(ra => ra.Id == id) - .FirstOrDefaultAsync(); - - if (dbRouteAddress == null) + if (!await IsRouteAddressExists(id)) { - return (false, $"RouteAddress doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } + var dbRouteAddress = await _dbContext.RouteAddresses.Where(ra => ra.Id == id) + .FirstAsync(); + if (String.IsNullOrWhiteSpace(fields)) { fields = RouteAddressParameters.DefaultFields; } - var shapedRouteAddressData = _routeAddressDataShaper.ShapeData(dbRouteAddress, fields); - var routeAddressDto = _mapper.Map(shapedRouteAddressData); + var routeAddressDto = _mapper.Map(dbRouteAddress); + var shapedData = _routeAddressDataShaper.ShapeData(routeAddressDto, fields); - return (true, "", routeAddressDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateRouteAddressDto routeAddress)> UpdateRouteAddress(UpdateRouteAddressDto updateRouteAddressDto) + public async Task<(bool isSucceed, IActionResult? actionResult, RouteAddressDto routeAddress)> UpdateRouteAddress(UpdateRouteAddressDto updateRouteAddressDto) { var routeAddress = _mapper.Map(updateRouteAddressDto); _dbContext.Entry(routeAddress).State = EntityState.Modified; @@ -136,30 +123,30 @@ public class RouteAddressManagementService : IRouteAddressManagementService { if (!await IsRouteAddressExists(updateRouteAddressDto.Id)) { - return (false, $"RouteAddress with id:{updateRouteAddressDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } throw; } - var dbRouteAddress = await _dbContext.RouteAddresses.FirstOrDefaultAsync(ra => ra.Id == routeAddress.Id); + var dbRouteAddress = await _dbContext.RouteAddresses.FirstAsync(ra => ra.Id == routeAddress.Id); - return (true, String.Empty, _mapper.Map(dbRouteAddress)); + return (true, null, _mapper.Map(dbRouteAddress)); } - public async Task<(bool isSucceed, string message)> DeleteRouteAddress(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteRouteAddress(int id) { var dbRouteAddress = await _dbContext.RouteAddresses.FirstOrDefaultAsync(ra => ra.Id == id); if (dbRouteAddress == null) { - return (false, $"RouteAddress with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } _dbContext.RouteAddresses.Remove(dbRouteAddress); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsRouteAddressExists(int id) diff --git a/Server/Services/RouteManagementService.cs b/Server/Services/RouteManagementService.cs index 0f41a6d..95692b4 100644 --- a/Server/Services/RouteManagementService.cs +++ b/Server/Services/RouteManagementService.cs @@ -35,14 +35,14 @@ public class RouteManagementService : IRouteManagementService _pager = pager; } - public async Task<(bool isSucceed, string message, RouteDto route)> AddRoute(CreateRouteDto createRouteDto) + public async Task<(bool isSucceed, IActionResult? actionResult, RouteDto route)> AddRoute(CreateRouteDto createRouteDto) { var route = _mapper.Map(createRouteDto); await _dbContext.Routes.AddAsync(route); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(route)); + return (true, null, _mapper.Map(route)); } public async Task<(bool isSucceed, IActionResult? actionResult, RouteWithAddressesDto route)> AddRouteWithAddresses(CreateRouteWithAddressesDto createRouteWithAddressesDto) @@ -56,7 +56,7 @@ public class RouteManagementService : IRouteManagementService if (dbAddress == null) { - return (false, new BadRequestObjectResult($"Address with Id = {routeAddress.AddressId} doesn't exist"), null!); + return (false, new BadRequestObjectResult($"Address with Id {routeAddress.AddressId} doesn't exist"), null!); } routeAddress.Address = dbAddress; @@ -68,7 +68,7 @@ public class RouteManagementService : IRouteManagementService return (true, null, _mapper.Map(route)); } - public async Task<(bool isSucceed, string message, IEnumerable routes, + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable routes, PagingMetadata pagingMetadata)> GetRoutes(RouteParameters parameters) { var dbRoutes = _dbContext.Routes @@ -83,20 +83,16 @@ public class RouteManagementService : IRouteManagementService try { shapedData = _routeSortHelper.ApplySort(shapedData, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbRoutes.Any(); } catch (Exception e) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null, null)!; } var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, parameters.PageSize); - return (true, "", shapedData, pagingMetadata); + return (true, null, shapedData, pagingMetadata); void SearchByAllRouteFields(ref IQueryable route, string? search) @@ -213,16 +209,16 @@ public class RouteManagementService : IRouteManagementService } } - public async Task<(bool isSucceed, string message, ExpandoObject route)> GetRoute(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject route)> GetRoute(int id, string? fields) { - var dbRoute = await _dbContext.Routes.Where(r => r.Id == id) - .FirstOrDefaultAsync(); - - if (dbRoute == null) + if (!await IsRouteExists(id)) { - return (false, $"Route doesn't exist", null)!; + return (false, new NotFoundResult(), null)!; } + var dbRoute = await _dbContext.Routes.Where(r => r.Id == id) + .FirstAsync(); + if (String.IsNullOrWhiteSpace(fields)) { fields = RouteParameters.DefaultFields; @@ -231,33 +227,33 @@ public class RouteManagementService : IRouteManagementService var routeDto = _mapper.Map(dbRoute); var shapedRouteData = _routeDataShaper.ShapeData(routeDto, fields); - return (true, "", shapedRouteData); + return (true, null, shapedRouteData); } - public async Task<(bool isSucceed, string message, ExpandoObject route)> GetRouteWithAddresses(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject route)> GetRouteWithAddresses(int id, string? fields) { + if (!await IsRouteExists(id)) + { + return (false, new NotFoundResult(), null)!; + } + var dbRoute = await _dbContext.Routes.Where(r => r.Id == id) .Include(r => r.RouteAddresses).ThenInclude(ra => ra.Address) .ThenInclude(a => a.City).ThenInclude(c => c.State) - .ThenInclude(s => s.Country).FirstOrDefaultAsync(); + .ThenInclude(s => s.Country).FirstAsync(); - if (dbRoute == null) - { - return (false, $"Route doesn't exist", null)!; - } - if (String.IsNullOrWhiteSpace(fields)) { fields = RouteWithAddressesParameters.DefaultFields; } var routeDto = _mapper.Map(dbRoute); - var shapedRouteData = _routeDataShaper.ShapeData(routeDto, fields); + var shapedData = _routeDataShaper.ShapeData(routeDto, fields); - return (true, "", shapedRouteData); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateRouteDto route)> UpdateRoute(UpdateRouteDto updateRouteDto) + public async Task<(bool isSucceed, IActionResult? actionResult, UpdateRouteDto route)> UpdateRoute(UpdateRouteDto updateRouteDto) { var route = _mapper.Map(updateRouteDto); _dbContext.Entry(route).State = EntityState.Modified; @@ -270,30 +266,28 @@ public class RouteManagementService : IRouteManagementService { if (!await IsRouteExists(updateRouteDto.Id)) { - return (false, $"Route with id:{updateRouteDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null)!; } - - throw; } - var dbRoute = await _dbContext.Routes.FirstOrDefaultAsync(r => r.Id == route.Id); + var dbRoute = await _dbContext.Routes.FirstAsync(r => r.Id == route.Id); - return (true, String.Empty, _mapper.Map(dbRoute)); + return (true, null, _mapper.Map(dbRoute)); } - public async Task<(bool isSucceed, string message)> DeleteRoute(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteRoute(int id) { var dbRoute = await _dbContext.Routes.FirstOrDefaultAsync(r => r.Id == id); - + if (dbRoute == null) { - return (false, $"Route with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } - + _dbContext.Routes.Remove(dbRoute); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsRouteExists(int id) diff --git a/Server/Services/StateManagementService.cs b/Server/Services/StateManagementService.cs index 2ce3c34..2389e1c 100644 --- a/Server/Services/StateManagementService.cs +++ b/Server/Services/StateManagementService.cs @@ -1,5 +1,6 @@ using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -14,62 +15,58 @@ public class StateManagementService : IStateManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _stateSortHelper; - private readonly IDataShaper _stateDataShaper; + private readonly ISortHelper _stateSortHelper; + private readonly IDataShaper _stateDataShaper; + private readonly IPager _pager; public StateManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper stateSortHelper, - IDataShaper stateDataShaper) + IMapper mapper, ISortHelper stateSortHelper, + IDataShaper stateDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _stateSortHelper = stateSortHelper; _stateDataShaper = stateDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, StateDto state)> AddState(CreateStateDto createStateDto) + public async Task<(bool isSucceed, IActionResult? actionResult, StateDto state)> AddState(CreateStateDto createStateDto) { var state = _mapper.Map(createStateDto); await _dbContext.States.AddAsync(state); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(state)); + return (true, null, _mapper.Map(state)); } - public async Task<(bool isSucceed, string message, IEnumerable states, - PagingMetadata pagingMetadata)> GetStates(StateParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable states, + PagingMetadata pagingMetadata)> GetStates(StateParameters parameters) { var dbStates = _dbContext.States.Include(s => s.Country) .Include(s => s.Cities) .ThenInclude(c => c.Addresses).AsQueryable(); - - var s = dbStates.ToList().ConvertAll(s => _mapper.Map(s)); - + SearchByAllStateFields(ref dbStates, parameters.Search); FilterByStateName(ref dbStates, parameters.Name); FilterByCountryId(ref dbStates, parameters.CountryId); + var stateDtos = _mapper.ProjectTo(dbStates); + var shapedData = _stateDataShaper.ShapeData(stateDtos, parameters.Fields).AsQueryable(); + try { - dbStates = _stateSortHelper.ApplySort(dbStates, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbStates.Any(); + shapedData = _stateSortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null!, null!); } - - var pagingMetadata = ApplyPaging(ref dbStates, parameters.PageNumber, - parameters.PageSize); - - var shapedStatesData = _stateDataShaper.ShapeData(dbStates, parameters.Fields); - var stateDtos = shapedStatesData.ToList().ConvertAll(s => _mapper.Map(s)); - return (true, "", stateDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void SearchByAllStateFields(ref IQueryable states, string? search) @@ -105,45 +102,32 @@ public class StateManagementService : IStateManagementService states = states.Where(s => s.Name.ToLower().Contains(stateName.Trim().ToLower())); } - - PagingMetadata ApplyPaging(ref IQueryable states, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(states, - pageNumber, pageSize); - - states = states - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, StateDto state)> GetState(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject state)> GetState(int id, string? fields) { + if (!await IsStateExists(id)) + { + return (false, new NotFoundResult(), null!); + } + var dbState = await _dbContext.States.Where(s => s.Id == id) .Include(s => s.Country).Include(s => s.Cities) .ThenInclude(c => c.Addresses) - .FirstOrDefaultAsync(); + .FirstAsync(); - if (dbState == null) - { - return (false, $"State doesn't exist", null)!; - } - if (String.IsNullOrWhiteSpace(fields)) { fields = StateParameters.DefaultFields; } - var shapedStateData = _stateDataShaper.ShapeData(dbState, fields); - var stateDto = _mapper.Map(shapedStateData); + var stateDto = _mapper.Map(dbState); + var shapedData = _stateDataShaper.ShapeData(stateDto, fields); - return (true, "", stateDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateStateDto state)> UpdateState(UpdateStateDto updateStateDto) + public async Task<(bool isSucceed, IActionResult? actionResult, StateDto state)> UpdateState(UpdateStateDto updateStateDto) { var state = _mapper.Map(updateStateDto); _dbContext.Entry(state).State = EntityState.Modified; @@ -156,30 +140,28 @@ public class StateManagementService : IStateManagementService { if (!await IsStateExists(updateStateDto.Id)) { - return (false, $"State with id:{updateStateDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } - - throw; } - var dbState = await _dbContext.States.FirstOrDefaultAsync(s => s.Id == state.Id); + var dbState = await _dbContext.States.FirstAsync(s => s.Id == state.Id); - return (true, String.Empty, _mapper.Map(dbState)); + return (true, null, _mapper.Map(dbState)); } - public async Task<(bool isSucceed, string message)> DeleteState(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteState(int id) { var dbState = await _dbContext.States.FirstOrDefaultAsync(s => s.Id == id); if (dbState == null) { - return (false, $"State with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } _dbContext.States.Remove(dbState); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsStateExists(int id) diff --git a/Server/Services/TicketManagementService.cs b/Server/Services/TicketManagementService.cs index eb6ee7c..dc18c6f 100644 --- a/Server/Services/TicketManagementService.cs +++ b/Server/Services/TicketManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,31 +15,33 @@ public class TicketManagementService : ITicketManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _ticketSortHelper; - private readonly IDataShaper _ticketDataShaper; + private readonly ISortHelper _ticketSortHelper; + private readonly IDataShaper _ticketDataShaper; + private readonly IPager _pager; public TicketManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper ticketSortHelper, - IDataShaper ticketDataShaper) + IMapper mapper, ISortHelper ticketSortHelper, + IDataShaper ticketDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _ticketSortHelper = ticketSortHelper; _ticketDataShaper = ticketDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, TicketDto ticket)> AddTicket(CreateTicketDto createTicketDto) + public async Task<(bool isSucceed, IActionResult? actionResult, TicketDto ticket)> AddTicket(CreateTicketDto createTicketDto) { var ticket = _mapper.Map(createTicketDto); await _dbContext.Tickets.AddAsync(ticket); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(ticket)); + return (true, null, _mapper.Map(ticket)); } - public async Task<(bool isSucceed, string message, IEnumerable tickets, - PagingMetadata pagingMetadata)> GetTickets(TicketParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable tickets, + PagingMetadata pagingMetadata)> GetTickets(TicketParameters parameters) { var dbTickets = _dbContext.Tickets .AsQueryable(); @@ -46,27 +50,23 @@ public class TicketManagementService : ITicketManagementService parameters.ToPurchaseDateTimeUtc); FilterByTicketReturnedState(ref dbTickets, parameters.IsReturned); FilterByTicketUserId(ref dbTickets, parameters.UserId); - + + var ticketDtos = _mapper.ProjectTo(dbTickets); + var shapedData = _ticketDataShaper.ShapeData(ticketDtos, parameters.Fields).AsQueryable(); + try { - dbTickets = _ticketSortHelper.ApplySort(dbTickets, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbTickets.Any(); + shapedData = _ticketSortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null!, null!); } - - var pagingMetadata = ApplyPaging(ref dbTickets, parameters.PageNumber, - parameters.PageSize); - - var shapedTicketsData = _ticketDataShaper.ShapeData(dbTickets, parameters.Fields); - var ticketDtos = shapedTicketsData.ToList().ConvertAll(t => _mapper.Map(t)); - return (true, "", ticketDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void FilterByTicketPurchaseDateTime(ref IQueryable tickets, DateTime? fromDateTime, DateTime? toDateTime) @@ -104,43 +104,30 @@ public class TicketManagementService : ITicketManagementService // tickets = tickets.Where(t => // t.UserId.ToLower().Contains(userId.ToLower())); } - - PagingMetadata ApplyPaging(ref IQueryable tickets, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(tickets, - pageNumber, pageSize); - - tickets = tickets - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, TicketDto ticket)> GetTicket(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject ticket)> GetTicket(int id, string? fields) { - var dbTicket = await _dbContext.Tickets.Where(t => t.Id == id) - .FirstOrDefaultAsync(); - - if (dbTicket == null) + if (!await IsTicketExists(id)) { - return (false, $"Ticket doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } + var dbTicket = await _dbContext.Tickets.Where(t => t.Id == id) + .FirstAsync(); + if (String.IsNullOrWhiteSpace(fields)) { fields = TicketParameters.DefaultFields; } - var shapedTicketData = _ticketDataShaper.ShapeData(dbTicket, fields); - var ticketDto = _mapper.Map(shapedTicketData); + var ticketDto = _mapper.Map(dbTicket); + var shapedData = _ticketDataShaper.ShapeData(ticketDto, fields); - return (true, "", ticketDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateTicketDto ticket)> UpdateTicket(UpdateTicketDto updateTicketDto) + public async Task<(bool isSucceed, IActionResult? actionResult, TicketDto ticket)> UpdateTicket(UpdateTicketDto updateTicketDto) { var ticket = _mapper.Map(updateTicketDto); _dbContext.Entry(ticket).State = EntityState.Modified; @@ -153,30 +140,28 @@ public class TicketManagementService : ITicketManagementService { if (!await IsTicketExists(updateTicketDto.Id)) { - return (false, $"Ticket with id:{updateTicketDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } - - throw; } - var dbTicket = await _dbContext.Tickets.FirstOrDefaultAsync(t => t.Id == ticket.Id); + var dbTicket = await _dbContext.Tickets.FirstAsync(t => t.Id == ticket.Id); - return (true, String.Empty, _mapper.Map(dbTicket)); + return (true, null, _mapper.Map(dbTicket)); } - public async Task<(bool isSucceed, string message)> DeleteTicket(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteTicket(int id) { var dbTicket = await _dbContext.Tickets.FirstOrDefaultAsync(t => t.Id == id); if (dbTicket == null) { - return (false, $"Ticket with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } _dbContext.Tickets.Remove(dbTicket); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsTicketExists(int id) diff --git a/Server/Services/VehicleEnrollmentManagementService.cs b/Server/Services/VehicleEnrollmentManagementService.cs index 7205769..c2261df 100644 --- a/Server/Services/VehicleEnrollmentManagementService.cs +++ b/Server/Services/VehicleEnrollmentManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,31 +15,33 @@ public class VehicleEnrollmentManagementService : IVehicleEnrollmentManagementSe { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _enrollmentSortHelper; - private readonly IDataShaper _enrollmentDataShaper; + private readonly ISortHelper _enrollmentSortHelper; + private readonly IDataShaper _enrollmentDataShaper; + private readonly IPager _pager; public VehicleEnrollmentManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper enrollmentSortHelper, - IDataShaper enrollmentDataShaper) + IMapper mapper, ISortHelper enrollmentSortHelper, + IDataShaper enrollmentDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _enrollmentSortHelper = enrollmentSortHelper; _enrollmentDataShaper = enrollmentDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, VehicleEnrollmentDto enrollment)> AddEnrollment(CreateVehicleEnrollmentDto createEnrollmentDto) + public async Task<(bool isSucceed, IActionResult? actionResult, VehicleEnrollmentDto enrollment)> AddEnrollment(CreateVehicleEnrollmentDto createEnrollmentDto) { var enrollment = _mapper.Map(createEnrollmentDto); await _dbContext.VehicleEnrollments.AddAsync(enrollment); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(enrollment)); + return (true, null, _mapper.Map(enrollment)); } - public async Task<(bool isSucceed, string message, IEnumerable enrollments, - PagingMetadata pagingMetadata)> GetEnrollments(VehicleEnrollmentParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable enrollments, + PagingMetadata pagingMetadata)> GetEnrollments(VehicleEnrollmentParameters parameters) { var dbEnrollments = _dbContext.VehicleEnrollments .AsQueryable(); @@ -50,26 +54,22 @@ public class VehicleEnrollmentManagementService : IVehicleEnrollmentManagementSe FilterByEnrollmentDelayedValue(ref dbEnrollments, parameters.IsDelayed); FilterByEnrollmentCancelledValue(ref dbEnrollments, parameters.IsCanceled); + var enrollmentDtos = _mapper.ProjectTo(dbEnrollments); + var shapedData = _enrollmentDataShaper.ShapeData(enrollmentDtos, parameters.Fields).AsQueryable(); + try { - dbEnrollments = _enrollmentSortHelper.ApplySort(dbEnrollments, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbEnrollments.Any(); + shapedData = _enrollmentSortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null!, null!); } - - var pagingMetadata = ApplyPaging(ref dbEnrollments, parameters.PageNumber, - parameters.PageSize); - - var shapedEnrollmentsData = _enrollmentDataShaper.ShapeData(dbEnrollments, parameters.Fields); - var enrollmentDtos = shapedEnrollmentsData.ToList().ConvertAll(e => _mapper.Map(e)); - return (true, "", enrollmentDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void SearchByAllEnrollmentFields(ref IQueryable enrollment, string? search) @@ -141,43 +141,30 @@ public class VehicleEnrollmentManagementService : IVehicleEnrollmentManagementSe enrollments = enrollments.Where(e => e.IsCanceled == isCancelled); } - - PagingMetadata ApplyPaging(ref IQueryable enrollments, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(enrollments, - pageNumber, pageSize); - - enrollments = enrollments - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } } - public async Task<(bool isSucceed, string message, VehicleEnrollmentDto enrollment)> GetEnrollment(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject enrollment)> GetEnrollment(int id, string? fields) { - var dbEnrollment = await _dbContext.VehicleEnrollments.Where(e => e.Id == id) - .FirstOrDefaultAsync(); - - if (dbEnrollment == null) + if (!await IsEnrollmentExists(id)) { - return (false, $"Enrollment doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } + var dbEnrollment = await _dbContext.VehicleEnrollments.Where(e => e.Id == id) + .FirstAsync(); + if (String.IsNullOrWhiteSpace(fields)) { fields = VehicleEnrollmentParameters.DefaultFields; } - var shapedEnrollmentData = _enrollmentDataShaper.ShapeData(dbEnrollment, fields); - var enrollmentDto = _mapper.Map(shapedEnrollmentData); + var enrollmentDto = _mapper.Map(dbEnrollment); + var shapedData = _enrollmentDataShaper.ShapeData(enrollmentDto, fields); - return (true, "", enrollmentDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateVehicleEnrollmentDto enrollment)> UpdateEnrollment(UpdateVehicleEnrollmentDto updateEnrollmentDto) + public async Task<(bool isSucceed, IActionResult? actionResult, VehicleEnrollmentDto enrollment)> UpdateEnrollment(UpdateVehicleEnrollmentDto updateEnrollmentDto) { var enrollment = _mapper.Map(updateEnrollmentDto); _dbContext.Entry(enrollment).State = EntityState.Modified; @@ -190,30 +177,30 @@ public class VehicleEnrollmentManagementService : IVehicleEnrollmentManagementSe { if (!await IsEnrollmentExists(updateEnrollmentDto.Id)) { - return (false, $"Enrollment with id:{updateEnrollmentDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } throw; } - var dbEnrollment = await _dbContext.VehicleEnrollments.FirstOrDefaultAsync(e => e.Id == enrollment.Id); + var dbEnrollment = await _dbContext.VehicleEnrollments.FirstAsync(e => e.Id == enrollment.Id); - return (true, String.Empty, _mapper.Map(dbEnrollment)); + return (true, null, _mapper.Map(dbEnrollment)); } - public async Task<(bool isSucceed, string message)> DeleteEnrollment(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteEnrollment(int id) { var dbEnrollment = await _dbContext.VehicleEnrollments.FirstOrDefaultAsync(e => e.Id == id); if (dbEnrollment == null) { - return (false, $"Enrollment with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } _dbContext.VehicleEnrollments.Remove(dbEnrollment); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsEnrollmentExists(int id) diff --git a/Server/Services/VehicleManagementService.cs b/Server/Services/VehicleManagementService.cs index fb66b2e..f74bb47 100644 --- a/Server/Services/VehicleManagementService.cs +++ b/Server/Services/VehicleManagementService.cs @@ -1,4 +1,6 @@ +using System.Dynamic; using AutoMapper; +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; using Server.Helpers; @@ -13,83 +15,53 @@ public class VehicleManagementService : IVehicleManagementService { private readonly ApplicationDbContext _dbContext; private readonly IMapper _mapper; - private readonly ISortHelper _vehicleSortHelper; - private readonly IDataShaper _vehicleDataShaper; + private readonly ISortHelper _vehicleSortHelper; + private readonly IDataShaper _vehicleDataShaper; + private readonly IPager _pager; public VehicleManagementService(ApplicationDbContext dbContext, - IMapper mapper, ISortHelper vehicleSortHelper, - IDataShaper vehicleDataShaper) + IMapper mapper, ISortHelper vehicleSortHelper, + IDataShaper vehicleDataShaper, IPager pager) { _dbContext = dbContext; _mapper = mapper; _vehicleSortHelper = vehicleSortHelper; _vehicleDataShaper = vehicleDataShaper; + _pager = pager; } - public async Task<(bool isSucceed, string message, VehicleDto vehicle)> AddVehicle(CreateVehicleDto createVehicleDto) + public async Task<(bool isSucceed, IActionResult? actionResult, VehicleDto vehicle)> AddVehicle(CreateVehicleDto createVehicleDto) { var vehicle = _mapper.Map(createVehicleDto); await _dbContext.Vehicles.AddAsync(vehicle); await _dbContext.SaveChangesAsync(); - return (true, String.Empty, _mapper.Map(vehicle)); + return (true, null, _mapper.Map(vehicle)); } - public async Task<(bool isSucceed, string message, IEnumerable vehicles, - PagingMetadata pagingMetadata)> GetVehicles(VehicleParameters parameters) + public async Task<(bool isSucceed, IActionResult? actionResult, IEnumerable vehicles, + PagingMetadata pagingMetadata)> GetVehicles(VehicleParameters parameters) { var dbVehicles = _dbContext.Vehicles .AsQueryable(); - bool a = dbVehicles.Any(); - - SearchByAllVehicleFields(ref dbVehicles, parameters.Search); - a = dbVehicles.Any(); - FilterByVehicleNumber(ref dbVehicles, parameters.Number); - a = dbVehicles.Any(); - FilterByVehicleType(ref dbVehicles, parameters.Type); - a = dbVehicles.Any(); - FilterByVehicleCapacity(ref dbVehicles, parameters.FromCapacity, - parameters.ToCapacity); - a = dbVehicles.Any(); - FilterByVehicleClimateControlAvailability(ref dbVehicles, parameters.HasClimateControl); - a = dbVehicles.Any(); - FilterByVehicleWiFiAvailability(ref dbVehicles, parameters.HasWiFi); - a = dbVehicles.Any(); - FilterByVehicleWCAvailability(ref dbVehicles, parameters.HasWC); - a = dbVehicles.Any(); - FilterByStewardessAvailability(ref dbVehicles, parameters.HasStewardess); - a = dbVehicles.Any(); - FilterByVehicleTVAvailability(ref dbVehicles, parameters.HasTV); - a = dbVehicles.Any(); - FilterByVehicleOutletAvailability(ref dbVehicles, parameters.HasOutlet); - a = dbVehicles.Any(); - FilterByVehicleBeltsAvailability(ref dbVehicles, parameters.HasBelts); - a = dbVehicles.Any(); - FilterByVehicleCompanyId(ref dbVehicles, parameters.CompanyId); - a = dbVehicles.Any(); + var vehicleDtos = _mapper.ProjectTo(dbVehicles); + var shapedData = _vehicleDataShaper.ShapeData(vehicleDtos, parameters.Fields).AsQueryable(); try { - dbVehicles = _vehicleSortHelper.ApplySort(dbVehicles, parameters.Sort); - - // By calling Any() we will check if LINQ to Entities Query will be - // executed. If not it will throw an InvalidOperationException exception - var isExecuted = dbVehicles.Any(); + shapedData = _vehicleSortHelper.ApplySort(shapedData, parameters.Sort); } - catch (Exception e) + catch (Exception) { - return (false, "Invalid sorting string", null, null)!; + return (false, new BadRequestObjectResult("Invalid sorting string"), null!, null!); } - - var pagingMetadata = ApplyPaging(ref dbVehicles, parameters.PageNumber, - parameters.PageSize); - - var shapedVehiclesData = _vehicleDataShaper.ShapeData(dbVehicles, parameters.Fields); - var vehicleDtos = shapedVehiclesData.ToList().ConvertAll(v => _mapper.Map(v)); - return (true, "", vehicleDtos, pagingMetadata); + var pagingMetadata = _pager.ApplyPaging(ref shapedData, parameters.PageNumber, + parameters.PageSize); + + return (true, null, shapedData, pagingMetadata); void SearchByAllVehicleFields(ref IQueryable vehicle, string? search) @@ -225,43 +197,31 @@ public class VehicleManagementService : IVehicleManagementService vehicles = vehicles.Where(v => v.CompanyId == companyId); } - - PagingMetadata ApplyPaging(ref IQueryable vehicles, - int pageNumber, int pageSize) - { - var metadata = new PagingMetadata(vehicles, - pageNumber, pageSize); - - vehicles = vehicles - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize); - - return metadata; - } + } - public async Task<(bool isSucceed, string message, VehicleDto vehicle)> GetVehicle(int id, string? fields) + public async Task<(bool isSucceed, IActionResult? actionResult, ExpandoObject vehicle)> GetVehicle(int id, string? fields) { - var dbVehicle = await _dbContext.Vehicles.Where(v => v.Id == id) - .FirstOrDefaultAsync(); - - if (dbVehicle == null) + if (!await IsVehicleExists(id)) { - return (false, $"Vehicle doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } + var dbVehicle = await _dbContext.Vehicles.Where(v => v.Id == id) + .FirstAsync(); + if (String.IsNullOrWhiteSpace(fields)) { fields = VehicleParameters.DefaultFields; } - var shapedVehicleData = _vehicleDataShaper.ShapeData(dbVehicle, fields); - var vehicleDto = _mapper.Map(shapedVehicleData); + var vehicleDto = _mapper.Map(dbVehicle); + var shapedData = _vehicleDataShaper.ShapeData(vehicleDto, fields); - return (true, "", vehicleDto); + return (true, null, shapedData); } - public async Task<(bool isSucceed, string message, UpdateVehicleDto vehicle)> UpdateVehicle(UpdateVehicleDto updateVehicleDto) + public async Task<(bool isSucceed, IActionResult? actionResult, VehicleDto vehicle)> UpdateVehicle(UpdateVehicleDto updateVehicleDto) { var vehicle = _mapper.Map(updateVehicleDto); _dbContext.Entry(vehicle).State = EntityState.Modified; @@ -274,30 +234,30 @@ public class VehicleManagementService : IVehicleManagementService { if (!await IsVehicleExists(updateVehicleDto.Id)) { - return (false, $"Vehicle with id:{updateVehicleDto.Id} doesn't exist", null)!; + return (false, new NotFoundResult(), null!); } throw; } - var dbVehicle = await _dbContext.Vehicles.FirstOrDefaultAsync(v => v.Id == vehicle.Id); + var dbVehicle = await _dbContext.Vehicles.FirstAsync(v => v.Id == vehicle.Id); - return (true, String.Empty, _mapper.Map(dbVehicle)); + return (true, null, _mapper.Map(dbVehicle)); } - public async Task<(bool isSucceed, string message)> DeleteVehicle(int id) + public async Task<(bool isSucceed, IActionResult? actionResult)> DeleteVehicle(int id) { var dbVehicle = await _dbContext.Vehicles.FirstOrDefaultAsync(v => v.Id == id); if (dbVehicle == null) { - return (false, $"Vehicle with id:{id} doesn't exist"); + return (false, new NotFoundResult()); } _dbContext.Vehicles.Remove(dbVehicle); await _dbContext.SaveChangesAsync(); - return (true, String.Empty); + return (true, null); } public async Task IsVehicleExists(int id) diff --git a/SharedModels/QueryParameters/Objects/AddressParameters.cs b/SharedModels/QueryParameters/Objects/AddressParameters.cs index 5fef293..06e88cd 100644 --- a/SharedModels/QueryParameters/Objects/AddressParameters.cs +++ b/SharedModels/QueryParameters/Objects/AddressParameters.cs @@ -6,7 +6,6 @@ public class AddressParameters : ParametersBase public AddressParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/CityParameters.cs b/SharedModels/QueryParameters/Objects/CityParameters.cs index e78f12f..68def33 100644 --- a/SharedModels/QueryParameters/Objects/CityParameters.cs +++ b/SharedModels/QueryParameters/Objects/CityParameters.cs @@ -6,7 +6,6 @@ public class CityParameters : ParametersBase public CityParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/CompanyParameters.cs b/SharedModels/QueryParameters/Objects/CompanyParameters.cs index 43fe683..849734d 100644 --- a/SharedModels/QueryParameters/Objects/CompanyParameters.cs +++ b/SharedModels/QueryParameters/Objects/CompanyParameters.cs @@ -6,7 +6,6 @@ public class CompanyParameters : ParametersBase public CompanyParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/CountryParameters.cs b/SharedModels/QueryParameters/Objects/CountryParameters.cs index 00065ef..3068090 100644 --- a/SharedModels/QueryParameters/Objects/CountryParameters.cs +++ b/SharedModels/QueryParameters/Objects/CountryParameters.cs @@ -6,7 +6,6 @@ public class CountryParameters : ParametersBase public CountryParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/ReviewParameters.cs b/SharedModels/QueryParameters/Objects/ReviewParameters.cs index 9dbaff5..13c1f1c 100644 --- a/SharedModels/QueryParameters/Objects/ReviewParameters.cs +++ b/SharedModels/QueryParameters/Objects/ReviewParameters.cs @@ -6,7 +6,6 @@ public class ReviewParameters : ParametersBase public ReviewParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/RouteAddressParameters.cs b/SharedModels/QueryParameters/Objects/RouteAddressParameters.cs index e8793b0..5ab78e7 100644 --- a/SharedModels/QueryParameters/Objects/RouteAddressParameters.cs +++ b/SharedModels/QueryParameters/Objects/RouteAddressParameters.cs @@ -7,7 +7,6 @@ public class RouteAddressParameters : ParametersBase public RouteAddressParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/RouteParameters.cs b/SharedModels/QueryParameters/Objects/RouteParameters.cs index 258cd62..caea91d 100644 --- a/SharedModels/QueryParameters/Objects/RouteParameters.cs +++ b/SharedModels/QueryParameters/Objects/RouteParameters.cs @@ -6,7 +6,6 @@ public class RouteParameters : ParametersBase public RouteParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/StateParameters.cs b/SharedModels/QueryParameters/Objects/StateParameters.cs index 6023808..590d2be 100644 --- a/SharedModels/QueryParameters/Objects/StateParameters.cs +++ b/SharedModels/QueryParameters/Objects/StateParameters.cs @@ -6,7 +6,6 @@ public class StateParameters : ParametersBase public StateParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/TicketParameters.cs b/SharedModels/QueryParameters/Objects/TicketParameters.cs index 21d57f1..2696ba9 100644 --- a/SharedModels/QueryParameters/Objects/TicketParameters.cs +++ b/SharedModels/QueryParameters/Objects/TicketParameters.cs @@ -6,7 +6,6 @@ public class TicketParameters : ParametersBase public TicketParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/VehicleEnrollmentParameters.cs b/SharedModels/QueryParameters/Objects/VehicleEnrollmentParameters.cs index 96c0201..5c73dff 100644 --- a/SharedModels/QueryParameters/Objects/VehicleEnrollmentParameters.cs +++ b/SharedModels/QueryParameters/Objects/VehicleEnrollmentParameters.cs @@ -7,7 +7,6 @@ public class VehicleEnrollmentParameters : ParametersBase public VehicleEnrollmentParameters() { - Sort = "id"; Fields = DefaultFields; } diff --git a/SharedModels/QueryParameters/Objects/VehicleParameters.cs b/SharedModels/QueryParameters/Objects/VehicleParameters.cs index 665c655..0778202 100644 --- a/SharedModels/QueryParameters/Objects/VehicleParameters.cs +++ b/SharedModels/QueryParameters/Objects/VehicleParameters.cs @@ -7,7 +7,6 @@ public class VehicleParameters : ParametersBase public VehicleParameters() { - Sort = "id"; Fields = DefaultFields; }