diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/AddressController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/AddressController.cs index 6a4d0eebef..85e9ba3b1b 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/AddressController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/AddressController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -52,12 +52,7 @@ public async Task GetAddresses() [ProducesResponseType(StatusCodes.Status401Unauthorized)] public async Task GetAddressById(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); return Ok(await addressService.GetById(id).ConfigureAwait(false)); } @@ -132,12 +127,7 @@ public async Task Update(AddressDto addressDto) [ProducesResponseType(StatusCodes.Status200OK)] public async Task Delete(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); await addressService.Delete(id).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/ApplicationController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/ApplicationController.cs index 9226ce3165..3f30ee6bbe 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/ApplicationController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/ApplicationController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -63,7 +64,7 @@ public async Task Get() [HttpGet("{id}")] public async Task GetById(long id) { - ValidateId(id); + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -104,7 +105,7 @@ public async Task GetByUserId(string id) [HttpGet("{id}")] public async Task GetByWorkshopId(long id) { - ValidateId(id); + this.ValidateId(id, localizer); try { @@ -182,21 +183,11 @@ public async Task Update(ApplicationDto applicationDto) [HttpDelete("{id}")] public async Task Delete(long id) { - ValidateId(id); + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); return NoContent(); } - - private void ValidateId(long id) - { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } - } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs index 94297b9af8..08853a6bd8 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -65,7 +66,7 @@ public async Task Get() [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetById(long id) { - IdValidation(id); + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -137,21 +138,11 @@ public async Task Update(CategoryDTO categoryDTO) [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task Delete(long id) { - IdValidation(id); + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); return NoContent(); } - - private void IdValidation(long id) - { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } - } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/ChildController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/ChildController.cs index 8d4cb89660..3609e3d3a5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/ChildController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/ChildController.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -63,12 +62,7 @@ public async Task Get() [HttpGet("{id}")] public async Task GetById(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -129,12 +123,7 @@ public async Task Update(ChildDTO dto) [HttpDelete("{id}")] public async Task Delete(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs index acf14dbb35..f1dcec9de8 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs @@ -66,12 +66,7 @@ public async Task Get() [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetById(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -144,12 +139,7 @@ public async Task Update(ParentDTO parentDTO) [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task Delete(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/ProviderController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/ProviderController.cs index 301ddc5c6e..bfe4c4176f 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/ProviderController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/ProviderController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -59,12 +60,7 @@ public async Task Get() [HttpGet("{id}")] public async Task GetById(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); return Ok(await providerService.GetById(id).ConfigureAwait(false)); } @@ -166,12 +162,7 @@ public async Task Update(ProviderDto dto) [HttpDelete("{id}")] public async Task Delete(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); await providerService.Delete(id).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs index 319165b1f8..81f34e7dc5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/SubcategoryController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -65,7 +66,7 @@ public async Task Get() [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetById(long id) { - IdValidation(id); + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -165,21 +166,11 @@ public async Task Update(SubcategoryDTO categoryDTO) [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task Delete(long id) { - IdValidation(id); + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); return NoContent(); } - - private void IdValidation(long id) - { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } - } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs index 9204ebcd03..9ac873cc04 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/SubsubcategoryController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -65,7 +66,7 @@ public async Task Get() [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task GetById(long id) { - IdValidation(id); + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -165,21 +166,11 @@ public async Task Update(SubsubcategoryDTO categoryDTO) [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task Delete(long id) { - IdValidation(id); + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); return NoContent(); } - - private void IdValidation(long id) - { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } - } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/TeacherController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/TeacherController.cs index ed3c0f4a02..4b2af28f3d 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/TeacherController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/TeacherController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -62,12 +63,7 @@ public async Task Get() [HttpGet("{id}")] public async Task GetById(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -131,12 +127,7 @@ public async Task Update(TeacherDTO dto) [HttpDelete("{id}")] public async Task Delete(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs index 4e11f874e3..81347ba516 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; +using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; @@ -62,12 +63,7 @@ public async Task Get() [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetById(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); return Ok(await service.GetById(id).ConfigureAwait(false)); } @@ -128,12 +124,7 @@ public async Task Update(WorkshopDTO dto) [HttpDelete("{id}")] public async Task Delete(long id) { - if (id < 1) - { - throw new ArgumentOutOfRangeException( - nameof(id), - localizer["The id cannot be less than 1."]); - } + this.ValidateId(id, localizer); await service.Delete(id).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Extensions/ControllerExtension.cs b/OutOfSchool/OutOfSchool.WebApi/Extensions/ControllerExtension.cs index fbbe2df86a..bc1300d5af 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Extensions/ControllerExtension.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Extensions/ControllerExtension.cs @@ -1,8 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Localization; namespace OutOfSchool.WebApi.Extensions { @@ -14,6 +13,14 @@ public static string GetJwtClaimByName(this ControllerBase controller, string cl return controller.User.Claims.FirstOrDefault(c => c.Type == claimName)?.Value; } + public static void ValidateId(this ControllerBase controller, long id, IStringLocalizer localizer) + { + if (id < 1) + { + throw new ArgumentOutOfRangeException(nameof(id), localizer["The id cannot be less than 1."]); + } + } + private static void ExtensionValidation(ControllerBase controller) { if (controller == null) diff --git a/OutOfSchool/OutOfSchool.WebApi/Extensions/ExceptionMiddlewareExtension.cs b/OutOfSchool/OutOfSchool.WebApi/Extensions/ExceptionMiddlewareExtension.cs index 0612a29843..566d3d4a77 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Extensions/ExceptionMiddlewareExtension.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Extensions/ExceptionMiddlewareExtension.cs @@ -1,12 +1,8 @@ using System; -using System.Net; using System.Text.Json; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using OutOfSchool.WebApi.Models; namespace OutOfSchool.WebApi.Extensions { @@ -18,6 +14,8 @@ public class ExceptionMiddlewareExtension /// /// Initializes a new instance of the class. /// + /// Next delegate. + /// Logger. public ExceptionMiddlewareExtension(RequestDelegate next, ILogger logger) { this.next = next; @@ -25,8 +23,10 @@ public ExceptionMiddlewareExtension(RequestDelegate next, ILogger - /// + /// Exception Handler. /// + /// HttpContext. + /// A representing the asynchronous operation. public async Task InvokeAsync(HttpContext context) { try @@ -35,7 +35,7 @@ public async Task InvokeAsync(HttpContext context) } catch (Exception ex) { - logger.LogError("Something went wrong:", ex.Message); + logger.LogError($"Something went wrong: {ex.Message}"); await HandleExceptionAsync(context, ex).ConfigureAwait(false); } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/AddressService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/AddressService.cs index 49f791ba98..c2244bad23 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/AddressService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/AddressService.cs @@ -46,13 +46,13 @@ public Task Create(AddressDto dto) /// public async Task> GetAll() { - logger.Information("Process of getting all Addresses started."); + logger.Information("Getting all Addresses started."); var addresses = await repository.GetAll().ConfigureAwait(false); logger.Information(!addresses.Any() ? "Address table is empty." - : "Successfully got all records from the Address table."); + : $"All {addresses.Count()} records were successfully received from the Address table"); return addresses.Select(address => address.ToModel()).ToList(); } @@ -60,7 +60,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Adress by id started."); + logger.Information($"Getting Address by Id started. Looking Id = {id}."); var address = await repository.GetById(id).ConfigureAwait(false); @@ -71,7 +71,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfully got an Address with id = {id}."); + logger.Information($"Successfully got an Address with Id = {id}."); return address.ToModel(); } @@ -79,19 +79,19 @@ public async Task GetById(long id) /// public async Task Update(AddressDto dto) { - logger.Information("Address updating was launched."); + logger.Information($"Updating Address with Id = {dto?.Id} started."); try { var address = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Address successfully updated."); + logger.Information($"Address with Id = {address?.Id} updated succesfully."); return address.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no Address in the Db with such an id."); + logger.Error($"Updating failed. Address with Id = {dto?.Id} doesn't exist in the system."); throw; } } @@ -99,7 +99,7 @@ public async Task Update(AddressDto dto) /// public async Task Delete(long id) { - logger.Information("Address deleting was launched."); + logger.Information($"Deleting Address with Id = {id} started."); var entity = new Address { Id = id }; @@ -107,11 +107,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Address successfully deleted."); + logger.Information($"Address with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed. There is no Address in the Db with such an id."); + logger.Error($"Deleting failed. Address with Id = {id} doesn't exist in the system."); throw; } } @@ -120,7 +120,7 @@ private async Task CreateInternal(Address address) { var newAddress = await repository.Create(address).ConfigureAwait(false); - logger.Information("Address created successfully."); + logger.Information($"Address with Id = {newAddress?.Id} created successfully."); return newAddress.ToModel(); } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ApplicationService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ApplicationService.cs index b54a32d9b5..57109dfba6 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ApplicationService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ApplicationService.cs @@ -38,7 +38,7 @@ public ApplicationService(IEntityRepository repository, ILogger log /// public async Task Create(ApplicationDto applicationDto) { - logger.Information("Application create started."); + logger.Information("Application creating was started."); ModelCreationValidation(applicationDto); @@ -46,7 +46,7 @@ public async Task Create(ApplicationDto applicationDto) var newApplication = await repository.Create(application).ConfigureAwait(false); - logger.Information("Application created succesfully."); + logger.Information($"Application with Id = {newApplication?.Id} created successfully."); return newApplication.ToModel(); } @@ -54,7 +54,7 @@ public async Task Create(ApplicationDto applicationDto) /// public async Task Delete(long id) { - logger.Information("Application delete started."); + logger.Information($"Deleting Application with Id = {id} started."); var application = new Application { Id = id }; @@ -62,11 +62,11 @@ public async Task Delete(long id) { await repository.Delete(application).ConfigureAwait(false); - logger.Information("Application deleted successfully."); + logger.Information($"Application with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed. There is no Application in the Db with such id."); + logger.Error($"Deleting failed. Application with Id = {id} doesn't exist in the system."); throw; } } @@ -74,13 +74,13 @@ public async Task Delete(long id) /// public async Task> GetAll() { - logger.Information("Process of getting all Applications started."); + logger.Information("Getting all Applications started."); var applications = await repository.GetAll().ConfigureAwait(false); logger.Information(!applications.Any() ? "Application table is empty." - : "Successfully got all records from the Application table."); + : $"All {applications.Count()} records were successfully received from the Application table"); return applications.Select(a => a.ToModel()).ToList(); } @@ -88,7 +88,7 @@ public async Task> GetAll() /// public async Task> GetAllByUser(string id) { - logger.Information("Process of getting Application by User Id started."); + logger.Information($"Getting Applications by User Id started. Looking User Id = {id}."); Expression> filter = a => a.UserId == id; @@ -99,7 +99,7 @@ public async Task> GetAllByUser(string id) throw new ArgumentException(localizer["There is no Application in the Db with such User id"], nameof(id)); } - logger.Information($"Successfully got Applications with User id = {id}."); + logger.Information($"Successfully got Applications with User Id = {id}."); return applications.Select(a => a.ToModel()).ToList(); } @@ -107,7 +107,7 @@ public async Task> GetAllByUser(string id) /// public async Task> GetAllByWorkshop(long id) { - logger.Information("Process of getting Application by Workshop Id started."); + logger.Information("Getting Applications by Workshop Id started. Looking Workshop Id = {id}."); Expression> filter = a => a.WorkshopId == id; @@ -118,7 +118,7 @@ public async Task> GetAllByWorkshop(long id) throw new ArgumentException(localizer["There is no Application in the Db with such User id"], nameof(id)); } - logger.Information($"Successfully got Applications with Workshop id = {id}."); + logger.Information($"Successfully got Applications with Workshop Id = {id}."); return applications.Select(a => a.ToModel()).ToList(); } @@ -126,7 +126,7 @@ public async Task> GetAllByWorkshop(long id) /// public async Task GetById(long id) { - logger.Information("Process of getting Application by Id started."); + logger.Information($"Getting Application by Id started. Looking Id = {id}."); var application = await repository.GetById(id).ConfigureAwait(false); @@ -137,7 +137,7 @@ public async Task GetById(long id) localizer["There is no Application in the Db with such id."]); } - logger.Information($"Successfully got an Application with id = { id}."); + logger.Information($"Successfully got an Application with Id = {id}."); return application.ToModel(); } @@ -145,7 +145,7 @@ public async Task GetById(long id) /// public async Task Update(ApplicationDto applicationDto) { - logger.Information("Application updating started."); + logger.Information($"Updating Application with Id = {applicationDto?.Id} started."); ModelNullValidation(applicationDto); @@ -153,13 +153,13 @@ public async Task Update(ApplicationDto applicationDto) { var application = await repository.Update(applicationDto.ToDomain()).ConfigureAwait(false); - logger.Information("Application updated successfully."); + logger.Information($"Application with Id = {applicationDto?.Id} updated succesfully."); return application.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no application in the Db with such id."); + logger.Error($"Updating failed. Application with Id = {applicationDto?.Id} doesn't exist in the system."); throw; } } @@ -168,8 +168,8 @@ private void ModelNullValidation(ApplicationDto applicationDto) { if (applicationDto is null) { - logger.Information("Operation failed. ApplicationDto was null"); - throw new ArgumentException(localizer["Application dto was null."], nameof(applicationDto)); + logger.Information("Operation failed. ApplicationDto is null"); + throw new ArgumentException(localizer["Application dto is null."], nameof(applicationDto)); } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs index 8e8b28573d..6fcc04efbe 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/CategoryService.cs @@ -37,7 +37,7 @@ public CategoryService(IEntityRepository entityRepository, ILogger log /// public async Task Create(CategoryDTO dto) { - logger.Information("Category creating was started"); + logger.Information("Category creating was started."); var category = dto.ToDomain(); @@ -45,7 +45,7 @@ public async Task Create(CategoryDTO dto) var newCategory = await repository.Create(category).ConfigureAwait(false); - logger.Information("Category created successfully."); + logger.Information($"Сategory with Id = {newCategory?.Id} created successfully."); return newCategory.ToModel(); } @@ -53,7 +53,7 @@ public async Task Create(CategoryDTO dto) /// public async Task Delete(long id) { - logger.Information("Categoty deleting was launched."); + logger.Information($"Deleting Сategory with Id = {id} started."); var entity = new Category() { Id = id }; @@ -61,11 +61,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Category succesfully deleted."); + logger.Information($"Category with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed.There is no category in the Db with such an id."); + logger.Error($"Deleting failed. Category with Id = {id} doesn't exist in the system."); throw; } } @@ -73,13 +73,13 @@ public async Task Delete(long id) /// public async Task> GetAll() { - logger.Information("Process of getting all Categories started."); + logger.Information("Getting all Categories started."); var categories = await this.repository.GetAll().ConfigureAwait(false); logger.Information(!categories.Any() ? "Category table is empty." - : "Successfully got all records from the Category table."); + : $"All {categories.Count()} records were successfully received from the Category table."); return categories.Select(parent => parent.ToModel()).ToList(); } @@ -87,7 +87,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Category by id started."); + logger.Information($"Getting Category by Id started. Looking Id = {id}."); var category = await repository.GetById((int)id).ConfigureAwait(false); @@ -98,7 +98,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfuly got a category with id = {id}."); + logger.Information($"Successfully got a category with Id = {id}."); return category.ToModel(); } @@ -106,19 +106,19 @@ public async Task GetById(long id) /// public async Task Update(CategoryDTO dto) { - logger.Information("Category updating was launched."); + logger.Information($"Updating Category with Id = {dto?.Id} started."); try { var category = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Category succesfully updated."); + logger.Information($"Category with Id = {category?.Id} updated succesfully."); return category.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no category in the Db with such an id."); + logger.Error($"Updating failed. Category with Id = {dto?.Id} doesn't exist in the system."); throw; } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs index 1987e6916e..95ce344d4c 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs @@ -46,7 +46,7 @@ public async Task Create(ChildDTO dto) var newChild = await repository.Create(child).ConfigureAwait(false); - logger.Information("Child created successfully."); + logger.Information($"Child with Id = {newChild?.Id} created successfully."); return newChild.ToModel(); } @@ -54,13 +54,13 @@ public async Task Create(ChildDTO dto) /// public async Task> GetAll() { - logger.Information("Process of getting all Children started."); + logger.Information("Getting all Children started."); var children = await repository.GetAll().ConfigureAwait(false); logger.Information(!children.Any() ? "Child table is empty." - : "Successfully got all records from the Child table."); + : $"All {children.Count()} records were successfully received from the Child table"); return children.Select(x => x.ToModel()).ToList(); } @@ -68,7 +68,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Child by id started."); + logger.Information($"Getting Child by Id started. Looking Id = {id}."); var child = await repository.GetById(id).ConfigureAwait(false); @@ -79,7 +79,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfully got a Child with id = {id}."); + logger.Information($"Successfully got a Child with Id = {id}."); return child.ToModel(); } @@ -87,14 +87,14 @@ public async Task GetById(long id) /// public async Task GetByIdWithDetails(long id) { - logger.Information("Process of getting child's details was launched."); + logger.Information($"Getting Child by Id with details started. Looking CategoryId = {id}."); Expression> filter = child => child.Id == id; var children = await this.repository.GetByFilter(filter, "Parent,SocialGroup").ConfigureAwait(false); - logger.Information("Child details successfully retrieved."); + logger.Information($"Successfully got Child details with Id = {id}."); return await Task.Run(() => children.FirstOrDefault().ToModel()).ConfigureAwait(false); } @@ -102,28 +102,34 @@ public async Task GetByIdWithDetails(long id) /// public async Task> GetAllByParent(long id) { + logger.Information($"Getting Child's by Parent started. Looking ParentId = {id}."); + var children = await repository.GetByFilter(x => x.ParentId == id).ConfigureAwait(false); + logger.Information(!children.Any() + ? $"There aren't Children for Parent with Id = {id}." + : $"All {children.Count()} records were successfully received from the Children table"); + return children.Select(x => x.ToModel()).ToList(); } /// public async Task Update(ChildDTO dto) { - logger.Information("Child updating was launched."); + logger.Information($"Updating Children with Id = {dto?.Id} started."); this.Check(dto); try { var child = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Child successfully updated."); + logger.Information($"Children with Id = {child?.Id} updated succesfully."); return child.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no Child in the Db with such an id."); + logger.Error($"Updating failed. Children with Id = {dto?.Id} doesn't exist in the system."); throw; } } @@ -131,7 +137,7 @@ public async Task Update(ChildDTO dto) /// public async Task Delete(long id) { - logger.Information("Child deleting was launched."); + logger.Information($"Deleting Children with Id = {id} started."); var entity = new Child { Id = id }; @@ -139,11 +145,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Child successfully deleted."); + logger.Information($"Children with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed. There is no Child in the Db with such an id."); + logger.Error($"Deleting failed. Children with Id = {id} doesn't exist in the system."); throw; } } @@ -152,32 +158,32 @@ private void Check(ChildDTO dto) { if (dto == null) { - logger.Information("Child creating failed. Child was null."); - throw new ArgumentNullException(nameof(dto), "Child was null."); + logger.Information("Child creating failed. Child is null."); + throw new ArgumentNullException(nameof(dto), localizer["Child is null."]); } if (dto.DateOfBirth > DateTime.Now) { - logger.Information("Child creating failed. Invalid Date of birth."); - throw new ArgumentException("Invalid Date of birth."); + logger.Information($"Child creating failed. Invalid Date of birth - {dto.DateOfBirth}."); + throw new ArgumentException(localizer["Invalid Date of birth."]); } if (dto.FirstName.Length == 0) { logger.Information("Updating failed. Empty firstname."); - throw new ArgumentException("Empty firstname.", nameof(dto)); + throw new ArgumentException(localizer["Empty firstname."], nameof(dto)); } if (dto.LastName.Length == 0) { logger.Information("Updating failed. Empty lastname."); - throw new ArgumentException("Empty lastname.", nameof(dto)); + throw new ArgumentException(localizer["Empty lastname."], nameof(dto)); } if (dto.MiddleName.Length == 0) { logger.Information("Updating failed. Empty patronymic."); - throw new ArgumentException("Empty patronymic.", nameof(dto)); + throw new ArgumentException(localizer["Empty patronymic."], nameof(dto)); } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs index 64790733f0..7d41ec602f 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs @@ -43,7 +43,7 @@ public async Task Create(ParentDTO dto) var newParent = await repository.Create(parent).ConfigureAwait(false); - logger.Information("Parent created successfully."); + logger.Information($"Parent with Id = {newParent?.Id} created successfully."); return newParent.ToModel(); } @@ -51,7 +51,7 @@ public async Task Create(ParentDTO dto) /// public async Task Delete(long id) { - logger.Information("Parent deleting was launched."); + logger.Information($"Deleting Parent with Id = {id} started."); var entity = new Parent() { Id = id }; @@ -59,11 +59,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Parent succesfully deleted."); + logger.Information($"Parent with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed.There is no parent in the Db with such an id."); + logger.Error($"Deleting failed. Parent with Id = {id} doesn't exist in the system."); throw; } } @@ -71,13 +71,13 @@ public async Task Delete(long id) /// public async Task> GetAll() { - logger.Information("Process of getting fll Parents started."); + logger.Information("Getting all Parents started."); var parents = await this.repository.GetAll().ConfigureAwait(false); logger.Information(!parents.Any() ? "Parent table is empty." - : "Successfully got all records from the Parent table."); + : $"All {parents.Count()} records were successfully received from the Parent table"); return parents.Select(parent => parent.ToModel()).ToList(); } @@ -85,7 +85,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Parent by id started."); + logger.Information($"Getting Parent by Id started. Looking Id = {id}."); var parent = await repository.GetById((int)id).ConfigureAwait(false); @@ -96,7 +96,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfuly got a parent with id = {id}."); + logger.Information($"Successfully got a Parent with Id = {id}."); return parent.ToModel(); } @@ -104,19 +104,19 @@ public async Task GetById(long id) /// public async Task Update(ParentDTO dto) { - logger.Information("Parent updating was launched."); + logger.Information($"Updating Parent with Id = {dto?.Id} started."); try { var parent = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Parent succesfully updated."); + logger.Information($"Parent with Id = {parent?.Id} updated succesfully."); return parent.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no parent in the Db with such an id."); + logger.Error($"Updating failed. Parent with Id = {dto?.Id} doesn't exist in the system."); throw; } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs index 32e4d646f8..74755cfa9f 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs @@ -48,20 +48,22 @@ public async Task Create(ProviderDto dto) Func> operation = async () => await providerRepository.Create(dto.ToDomain()).ConfigureAwait(false); var newProvider = await providerRepository.RunInTransaction(operation).ConfigureAwait(false); - + + logger.Information($"Provider with Id = {newProvider?.Id} created successfully."); + return newProvider.ToModel(); } /// public async Task> GetAll() { - logger.Information("Process of getting all Providers started."); + logger.Information("Getting all Providers started."); var providers = await providerRepository.GetAll().ConfigureAwait(false); logger.Information(!providers.Any() ? "Provider table is empty." - : "Successfully got all records from the Provider table."); + : $"All {providers.Count()} records were successfully received from the Provider table"); return providers.Select(provider => provider.ToModel()).ToList(); } @@ -69,7 +71,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Provider by id started."); + logger.Information($"Getting Provider by Id started. Looking Id = {id}."); var provider = await providerRepository.GetById(id).ConfigureAwait(false); @@ -80,7 +82,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfully got a Provider with id = {id}."); + logger.Information($"Successfully got a Provider with Id = {id}."); return provider.ToModel(); } @@ -88,17 +90,19 @@ public async Task GetById(long id) /// public async Task Update(ProviderDto dto) { + logger.Information($"Updating Provider with Id = {dto?.Id} started."); + try { var provider = await providerRepository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Provider successfully updated."); + logger.Information($"Provider with Id = {provider?.Id} updated succesfully."); return provider.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no Provider in the Db with such an id."); + logger.Error($"Updating failed. Provider with Id = {dto?.Id} doesn't exist in the system."); throw; } } @@ -106,7 +110,7 @@ public async Task Update(ProviderDto dto) /// public async Task Delete(long id) { - logger.Information("Provider deleting was launched."); + logger.Information($"Deleting Provider with Id = {id} started."); try { @@ -114,11 +118,11 @@ public async Task Delete(long id) await providerRepository.Delete(entity).ConfigureAwait(false); - logger.Information("Provider successfully deleted."); + logger.Information($"Provider with Id = {id} succesfully deleted."); } catch (ArgumentNullException) { - logger.Error("Deleting failed. There is no Provider in the Db with such an id."); + logger.Error($"Deleting failed. Provider with Id = {id} doesn't exist in the system."); throw; } } @@ -126,7 +130,7 @@ public async Task Delete(long id) /// public async Task GetByUserId(string id) { - logger.Information("Process of getting Provider by User Id started."); + logger.Information($"Getting Provider by UserId started. Looking UserId is {id}."); Expression> filter = p => p.UserId == id; @@ -137,7 +141,7 @@ public async Task GetByUserId(string id) throw new ArgumentException(localizer["There is no Provider in the Db with such User id"], nameof(id)); } - logger.Information($"Successfully got a Provider with User id = {id}."); + logger.Information($"Successfully got a Provider with UserId = {id}."); return providers.FirstOrDefault().ToModel(); } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs index d337447f99..ea87b921db 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/SubcategoryService.cs @@ -37,7 +37,7 @@ public SubcategoryService(ISubcategoryRepository entityRepository, ILogger logge /// public async Task Create(SubcategoryDTO dto) { - logger.Information("Subcategory creating was started"); + logger.Information("Subcategory creating was started."); var category = dto.ToDomain(); @@ -45,7 +45,7 @@ public async Task Create(SubcategoryDTO dto) var newCategory = await repository.Create(category).ConfigureAwait(false); - logger.Information("Subcategory created successfully."); + logger.Information($"Subcategory with Id = {newCategory?.Id} created successfully."); return newCategory.ToModel(); } @@ -53,7 +53,7 @@ public async Task Create(SubcategoryDTO dto) /// public async Task Delete(long id) { - logger.Information("Subcategoty deleting was launched."); + logger.Information($"Deleting Subcategory with Id = {id} started."); var entity = new Subcategory() { Id = id }; @@ -61,11 +61,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Subcategory succesfully deleted."); + logger.Information($"Subcategory with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed.There is no subcategory in the Db with such an id."); + logger.Error($"Deleting failed. Subcategory with Id = {id} doesn't exist in the system."); throw; } } @@ -73,13 +73,13 @@ public async Task Delete(long id) /// public async Task> GetAll() { - logger.Information("Process of getting all Subcategories started."); + logger.Information("Getting all Subcategories started."); var categories = await this.repository.GetAll().ConfigureAwait(false); logger.Information(!categories.Any() ? "Subcategory table is empty." - : "Successfully got all records from the Subcategory table."); + : $"All {categories.Count()} records were successfully received from the Subcategory table"); return categories.Select(parent => parent.ToModel()).ToList(); } @@ -87,7 +87,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Subcategory by id started."); + logger.Information($"Getting Subcategory by Id started. Looking Id = {id}."); var category = await repository.GetById((int)id).ConfigureAwait(false); @@ -98,7 +98,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfuly got a subcategory with id = {id}."); + logger.Information($"Successfully got a Subcategory with Id = {id}."); return category.ToModel(); } @@ -106,15 +106,15 @@ public async Task GetById(long id) /// public async Task> GetByCategoryId(long id) { - logger.Information("Process of getting all Subcategories started."); + logger.Information($"Getting Subcategory by CategoryId started. Looking CategoryId = {id}."); IdValidation(id); var categories = await this.repository.Get(where: x => x.CategoryId == id).ToListAsync().ConfigureAwait(false); logger.Information(!categories.Any() - ? "Subcategory table is empty." - : "Successfully got all records from the Subcategory table."); + ? $"There aren't Subcategories for Category with Id = {id}." + : $"All {categories.Count} records were successfully received from the Subcategory table"); return categories.Select(parent => parent.ToModel()).ToList(); } @@ -122,7 +122,7 @@ public async Task> GetByCategoryId(long id) /// public async Task Update(SubcategoryDTO dto) { - logger.Information("Subcategory updating was launched."); + logger.Information($"Updating Subcategory with Id = {dto?.Id} started."); ModelValidation(dto); @@ -130,13 +130,13 @@ public async Task Update(SubcategoryDTO dto) { var category = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Subcategory succesfully updated."); + logger.Information($"Subcategory with Id = {category?.Id} updated succesfully."); return category.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no subcategory in the Db with such an id."); + logger.Error($"Updating failed. Subcategory with Id = {dto?.Id} doesn't exist in the system."); throw; } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs index 02c2c282c2..b055e92fb8 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/SubsubcategoryService.cs @@ -37,7 +37,7 @@ public SubsubcategoryService(ISubsubcategoryRepository entityRepository, ILogger /// public async Task Create(SubsubcategoryDTO dto) { - logger.Information("Subsubategory creating was started"); + logger.Information("Subsubategory creating was started."); var category = dto.ToDomain(); @@ -45,7 +45,7 @@ public async Task Create(SubsubcategoryDTO dto) var newCategory = await repository.Create(category).ConfigureAwait(false); - logger.Information("Subsubcategory created successfully."); + logger.Information($"Subsubcategory with Id = {newCategory?.Id} created successfully."); return newCategory.ToModel(); } @@ -53,7 +53,7 @@ public async Task Create(SubsubcategoryDTO dto) /// public async Task Delete(long id) { - logger.Information("Subsubcategoty deleting was launched."); + logger.Information($"Deleting Subsubcategory with Id = {id} started."); var entity = new Subsubcategory() { Id = id }; @@ -61,11 +61,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Subsubcategory succesfully deleted."); + logger.Information($"Subsubcategory with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed.There is no subsubcategory in the Db with such an id."); + logger.Error($"Deleting failed. Subsubcategory with such Id = {id} doesn't exist in the system."); throw; } } @@ -73,13 +73,13 @@ public async Task Delete(long id) /// public async Task> GetAll() { - logger.Information("Process of getting all Subsubcategories started."); + logger.Information("Getting all Subsubcategories started."); var categories = await this.repository.GetAll().ConfigureAwait(false); logger.Information(!categories.Any() ? "Subsubcategory table is empty." - : "Successfully got all records from the Subsubcategory table."); + : $"All {categories.Count()} records were successfully received from the Subsubcategory table"); return categories.Select(parent => parent.ToModel()).ToList(); } @@ -87,7 +87,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Subsubcategory by id started."); + logger.Information($"Getting Subsubcategory by Id started. Looking Id = {id}."); var category = await repository.GetById((int)id).ConfigureAwait(false); @@ -98,7 +98,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfuly got a subsubcategory with id = {id}."); + logger.Information($"Successfully got a Subsubcategory with Id = {id}."); return category.ToModel(); } @@ -106,15 +106,15 @@ public async Task GetById(long id) /// public async Task> GetBySubcategoryId(long id) { - logger.Information("Process of getting all Subsubcategories started."); + logger.Information($"Getting Subsubcategory by SubcategoryId started. Looking SubcategoryId = {id}."); IdValidation(id); var categories = await this.repository.Get(where: x => x.SubcategoryId == id).ToListAsync().ConfigureAwait(false); logger.Information(!categories.Any() - ? "Subsubcategory table is empty." - : "Successfully got all records from the Subsubcategory table."); + ? $"There aren't Subsubcategories for Subcategory with Id = {id}." + : $"All {categories.Count} records were successfully received from the Subsubcategory table"); return categories.Select(parent => parent.ToModel()).ToList(); } @@ -122,19 +122,19 @@ public async Task> GetBySubcategoryId(long id) /// public async Task Update(SubsubcategoryDTO dto) { - logger.Information("Subsubcategory updating was launched."); + logger.Information($"Updating Subsubcategory with Id = {dto?.Id} started."); try { var category = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Subsubcategory succesfully updated."); + logger.Information($"Subsubcategory with Id = {category?.Id} updated succesfully."); return category.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no subsubcategory in the Db with such an id."); + logger.Error($"Updating failed. Subsubcategory with Id = {dto?.Id} doesn't exist in the system."); throw; } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/TeacherService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/TeacherService.cs index 497a3c091a..d15fa0b404 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/TeacherService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/TeacherService.cs @@ -43,19 +43,21 @@ public async Task Create(TeacherDTO dto) var newTeacher = await repository.Create(teacher).ConfigureAwait(false); + logger.Information($"Teacher with Id = {newTeacher?.Id} created successfully."); + return newTeacher.ToModel(); } /// public async Task> GetAll() { - logger.Information("Process of getting all Teachers started."); + logger.Information("Getting all Teachers started."); var teachers = await repository.GetAll().ConfigureAwait(false); logger.Information(!teachers.Any() ? "Teacher table is empty." - : "Successfully got all records from the Teacher table."); + : $"All {teachers.Count()} records were successfully received from the Teacher table"); return teachers.Select(teacher => teacher.ToModel()).ToList(); } @@ -63,7 +65,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Teacher by id started."); + logger.Information($"Getting Teacher by Id started. Looking Id = {id}."); var teacher = await repository.GetById(id).ConfigureAwait(false); @@ -74,7 +76,7 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfully got a Teacher with id = {id}."); + logger.Information($"Successfully got a Teacher with Id = {id}."); return teacher.ToModel(); } @@ -82,19 +84,19 @@ public async Task GetById(long id) /// public async Task Update(TeacherDTO dto) { - logger.Information("Teacher updating was launched."); + logger.Information($"Updating Teacher with Id = {dto?.Id} started."); try { var teacher = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Teacher successfully updated."); + logger.Information($"Teacher with Id = {teacher?.Id} updated succesfully."); return teacher.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no Teacher in the Db with such an id."); + logger.Error($"Updating failed. Teacher with Id = {dto?.Id} doesn't exist in the system."); throw; } } @@ -102,7 +104,7 @@ public async Task Update(TeacherDTO dto) /// public async Task Delete(long id) { - logger.Information("Teacher deleting was launched."); + logger.Information($"Deleting Teacher with Id = {id} started."); var entity = new Teacher() { Id = id }; @@ -110,11 +112,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Teacher successfully deleted."); + logger.Information($"Teacher with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed. There is no Teacher in the Db with such an id."); + logger.Error($"Deleting failed. Teacher with Id = {id} doesn't exist in the system."); throw; } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs index a249b9db45..3f17e801e5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Localization; using OutOfSchool.Services.Models; using OutOfSchool.Services.Repository; @@ -38,20 +37,20 @@ public UserService(IEntityRepository repository, ILogger logger, IStringLo public async Task> GetAll() { - logger.Information("Process of getting all Users started."); + logger.Information("Getting all Users started."); var users = await repository.GetAll().ConfigureAwait(false); logger.Information(!users.Any() ? "User table is empty." - : "Successfully got all records from the User table."); + : $"All {users.Count()} records were successfully received from the User table"); return users.Select(user => user.ToModel()).ToList(); } public async Task GetById(string id) { - logger.Information("Process of getting User by id started."); + logger.Information($"Getting User by Id started. Looking Id = {id}."); Expression> filter = p => p.Id == id; @@ -62,7 +61,7 @@ public async Task GetById(string id) throw new ArgumentException(localizer["There is no User in the Db with such an id"], nameof(id)); } - logger.Information($"Successfully got an User with id = {id}."); + logger.Information($"Successfully got an User with Id = {id}."); return users.FirstOrDefault().ToModel(); } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs index 6fb7f0a8a5..a62c6e9bc5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/WorkshopService.cs @@ -41,25 +41,27 @@ public WorkshopService(IWorkshopRepository repository, ILogger logger, IStringLo /// public async Task Create(WorkshopDTO dto) { - logger.Information("Teacher creating was started."); + logger.Information("Workshop creating was started."); var workshop = dto.ToDomain(); var newWorkshop = await repository.Create(workshop).ConfigureAwait(false); + logger.Information($"Workshop with Id = {newWorkshop?.Id} created successfully."); + return newWorkshop.ToModel(); } /// public async Task> GetAll() { - logger.Information("Process of getting all Workshops started."); + logger.Information("Getting all Workshops started."); var workshops = await repository.GetAll().ConfigureAwait(false); logger.Information(!workshops.Any() ? "Workshop table is empty." - : "Successfully got all records from the Workshop table."); + : $"All {workshops.Count()} records were successfully received from the Workshop table"); return workshops.Select(x => x.ToModel()).ToList(); } @@ -67,7 +69,7 @@ public async Task> GetAll() /// public async Task GetById(long id) { - logger.Information("Process of getting Teacher by id started."); + logger.Information($"Getting Workshop by Id started. Looking Id = {id}."); var teacher = await repository.GetById(id).ConfigureAwait(false); @@ -78,34 +80,40 @@ public async Task GetById(long id) localizer["The id cannot be greater than number of table entities."]); } - logger.Information($"Successfully got a Teacher with id = {id}."); + logger.Information($"Successfully got a Workshop with Id = {id}."); return teacher.ToModel(); } public async Task> GetWorkshopsByOrganization(long id) { + logger.Information($"Getting Workshop by organization started. Looking ProviderId = {id}."); + var workshops = await repository.GetByFilter(x => x.Provider.Id == id).ConfigureAwait(false); + logger.Information(!workshops.Any() + ? $"There aren't Workshops for Provider with Id = {id}." + : $"From Workshop table were successfully received {workshops.Count()} records."); + return workshops.Select(x => x.ToModel()).ToList(); } /// public async Task Update(WorkshopDTO dto) { - logger.Information("Workshop updating was launched."); + logger.Information($"Updating Workshop with Id = {dto?.Id} started."); try { var workshop = await repository.Update(dto.ToDomain()).ConfigureAwait(false); - logger.Information("Workshop successfully updated."); + logger.Information($"Workshop with Id = {workshop?.Id} updated succesfully."); return workshop.ToModel(); } catch (DbUpdateConcurrencyException) { - logger.Error("Updating failed. There is no Workshop in the Db with such an id."); + logger.Error($"Updating failed. Workshop with Id = {dto?.Id} doesn't exist in the system."); throw; } } @@ -113,7 +121,7 @@ public async Task Update(WorkshopDTO dto) /// public async Task Delete(long id) { - logger.Information("Workshop deleting was launched."); + logger.Information($"Deleting Workshop with Id = {id} started."); var entity = new Workshop() { Id = id }; @@ -121,11 +129,11 @@ public async Task Delete(long id) { await repository.Delete(entity).ConfigureAwait(false); - logger.Information("Workshop successfully deleted."); + logger.Information($"Workshop with Id = {id} succesfully deleted."); } catch (DbUpdateConcurrencyException) { - logger.Error("Deleting failed. There is no Teacher in the Db with such an id."); + logger.Error($"Deleting failed. Workshop with Id = {id} doesn't exist in the system."); throw; } }