diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs index 3942ef2022..f9c938ec8d 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Provider.cs @@ -57,7 +57,7 @@ public class Provider [DataType(DataType.PhoneNumber)] [RegularExpression( @"([\d]{10})", - ErrorMessage = "Phone number format is incorrect. Example: 380 50-123-45-67")] + ErrorMessage = "Phone number format is incorrect. Example: 0501234567")] [DisplayFormat(DataFormatString = "{0:+38 XXX-XXX-XX-XX}")] public string PhoneNumber { get; set; } = string.Empty; diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/User.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/User.cs index 75beee1e6b..68132e4005 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/User.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/User.cs @@ -19,5 +19,7 @@ public class User : IdentityUser public string FirstName { get; set; } public string Role { get; set; } + + public bool IsRegistered { get; set; } } } \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs index 787b1e5626..809e7a440f 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Workshop.cs @@ -18,8 +18,8 @@ public class Workshop [DataType(DataType.PhoneNumber)] [Required(ErrorMessage = "Phone number is required")] [RegularExpression( - @"([\d]{9})", - ErrorMessage = "Phone number format is incorrect. Example: 380 50-123-45-67")] + @"([\d]{10})", + ErrorMessage = "Phone number format is incorrect. Example: 0501234567")] [DisplayFormat(DataFormatString = "{0:+38 XXX-XXX-XX-XX}")] public string Phone { get; set; } = string.Empty; @@ -37,11 +37,11 @@ public class Workshop public string Instagram { get; set; } = string.Empty; [Required(ErrorMessage = "Children's min age is required")] - [Range(0, 16, ErrorMessage = "Min age should be a number from 0 to 16")] + [Range(0, 18, ErrorMessage = "Min age should be a number from 0 to 18")] public int MinAge { get; set; } [Required(ErrorMessage = "Children's max age is required")] - [Range(0, 16, ErrorMessage = "Max age should be a number from 0 to 16")] + [Range(0, 18, ErrorMessage = "Max age should be a number from 0 to 18")] public int MaxAge { get; set; } [Required(ErrorMessage = "Specify how many times per week lessons will be held")] diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs index bf825d3f01..9ff6ed52f1 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IProviderRepository.cs @@ -5,5 +5,7 @@ namespace OutOfSchool.Services.Repository public interface IProviderRepository : IEntityRepository { bool Exists(Provider entity); + + bool ExistsUserId(string id); } } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs index 2900c39633..1dcb7d538a 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/ProviderRepository.cs @@ -22,6 +22,13 @@ public ProviderRepository(OutOfSchoolDbContext dbContext) /// Bool. public bool Exists(Provider entity) => db.Providers.Any(x => x.EdrpouIpn == entity.EdrpouIpn || x.Email == entity.Email); + /// + /// Checks if the user is trying to create second account. + /// + /// User id. + /// Bool. + public bool ExistsUserId(string id) => db.Providers.Any(x => x.UserId == id); + /// /// Add new element. /// diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AuthController.cs b/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AuthController.cs index d9226d0d6c..013c83a9f4 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AuthController.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Controllers/AuthController.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; +using OutOfSchool.IdentityServer.Enums; using OutOfSchool.IdentityServer.ViewModels; using OutOfSchool.Services.Models; @@ -136,14 +137,14 @@ public async Task Register(RegisterViewModel model) return View(model); } - if (Request.Form["Provider"].Count == 1) + if (Request.Form[Role.Provider.ToString()].Count == 1) { - model.Role = "provider"; + model.Role = Role.Provider.ToString().ToLower(); } else - if (Request.Form["Parent"].Count == 1) + if (Request.Form[Role.Parent.ToString()].Count == 1) { - model.Role = "parent"; + model.Role = Role.Parent.ToString().ToLower(); } else { @@ -160,6 +161,7 @@ public async Task Register(RegisterViewModel model) PhoneNumber = model.PhoneNumber, CreatingTime = DateTime.Now, Role = model.Role, + IsRegistered = false, }; var result = await userManager.CreateAsync(user, model.Password); diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs index 7c83f44e5c..897afbb6be 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs @@ -590,6 +590,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("FirstName") .HasColumnType("nvarchar(max)"); + b.Property("IsRegistered") + .HasColumnType("bit"); + b.Property("LastLogin") .HasColumnType("datetime2"); diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Enums/Role.cs b/OutOfSchool/OutOfSchool.IdentityServer/Enums/Role.cs new file mode 100644 index 0000000000..44a8e00728 --- /dev/null +++ b/OutOfSchool/OutOfSchool.IdentityServer/Enums/Role.cs @@ -0,0 +1,8 @@ +namespace OutOfSchool.IdentityServer.Enums +{ + public enum Role + { + Provider, + Parent, + } +} diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Views/Auth/Register.cshtml b/OutOfSchool/OutOfSchool.IdentityServer/Views/Auth/Register.cshtml index cb7e046322..b73fc67911 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Views/Auth/Register.cshtml +++ b/OutOfSchool/OutOfSchool.IdentityServer/Views/Auth/Register.cshtml @@ -78,7 +78,7 @@
+38
- +
@@ -95,7 +95,7 @@
-
+
eye
@@ -112,7 +112,7 @@
-
+
eye
diff --git a/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/css/site.css b/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/css/site.css index 38bf57334b..97f47e2030 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/css/site.css +++ b/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/css/site.css @@ -381,20 +381,22 @@ a { color: #ffffff; cursor: pointer; } -.registration_privacy { - border: none; - outline: none; - background: inherit; - position: absolute; - bottom: 0; - right: 8px; - width: 30px; - height: 30px; - display: flex !important; - align-items: center !important; - justify-content: center !important; -} -.registration_privacy img { +.registration_privacy_password, +.registration_privacy_confirm_password { + border: none; + outline: none; + background: inherit; + position: absolute; + bottom: 0; + right: 8px; + width: 30px; + height: 30px; + display: flex !important; + align-items: center !important; + justify-content: center !important; +} +.registration_privacy_password img, +.registration_privacy_confirm_password img { height: 16px; width: auto; } diff --git a/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/js/site.js b/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/js/site.js index 5bfc8bbca8..705a646c82 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/js/site.js +++ b/OutOfSchool/OutOfSchool.IdentityServer/wwwroot/js/site.js @@ -11,13 +11,27 @@ let check_confirmPasswordEye = false; let password = document.getElementById('password'); let repeatPassword = document.getElementById('repeat_password'); +if (sessionStorage.getItem("Button") && sessionStorage.getItem("Role")) { + btn_provider.className = "registration_type"; + btn_parent.className = "registration_type"; + btn_register.setAttribute("name", sessionStorage.getItem("Role")); + document.getElementById(sessionStorage.getItem("Button")).className = "registration_type registration_type-active"; +} + if (password.className.includes('input-validation-error')) { - let elements = document.getElementsByClassName('registration_privacy'); + let elements = document.getElementsByClassName('registration_privacy_password'); for (let element of elements) { element.style.height = "65px"; } } +if (repeatPassword.className.includes('input-validation-error')) { + let elements = document.getElementsByClassName('registration_privacy_confirm_password'); + for (let element of elements) { + element.style.height = "65px"; + } +} + if (document.getElementsByClassName('validation-summary-errors').length > 0) { document.getElementById("user_mail").className += ' input-validation-error'; } @@ -25,13 +39,17 @@ if (document.getElementsByClassName('validation-summary-errors').length > 0) { btn_parent.addEventListener('click', function () { btn_parent.className = "registration_type registration_type-active"; btn_provider.className = "registration_type"; - btn_register.setAttribute("name", "Parent"); + btn_register.setAttribute("name", "Parent"); + sessionStorage.setItem("Role", "Parent"); + sessionStorage.setItem("Button", "btn_parent"); }) btn_provider.addEventListener('click', function () { btn_provider.className = "registration_type registration_type-active"; btn_parent.className = "registration_type"; - btn_register.setAttribute("name", "Provider"); + btn_register.setAttribute("name", "Provider"); + sessionStorage.setItem("Role", "Provider"); + sessionStorage.setItem("Button", "btn_provider"); }) passwordEye.addEventListener('click', function () { diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ProviderServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ProviderServiceTests.cs index 17c01390ff..bc70c3c3b6 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ProviderServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ProviderServiceTests.cs @@ -127,6 +127,59 @@ public async Task Create_WhenEntityIsValid_ReturnsCreatedEntity() [Test] [Order(2)] + public void Create_WhenUserIdExists_ReturnsArgumentException() + { + // Arrange + var expected = new Provider() + { + FullTitle = "Title", + ShortTitle = "ShortTitle", + Website = "Website", + Facebook = "Facebook", + Email = "user167@example.com", + Instagram = "Instagram1", + Description = "Description1", + DirectorBirthDay = new DateTime(1975, month: 10, 5), + EdrpouIpn = "55545000", + PhoneNumber = "1111111111", + Founder = "Founder", + Ownership = OwnershipType.Private, + Type = ProviderType.TOV, + Status = false, + LegalAddressId = 166, + ActualAddressId = 125, + UserId = "de909VV5-5eb7-4b7a-bda8-40a5bfda96a6", + LegalAddress = new Address + { + Id = 166, + Region = "Region166", + District = "District166", + City = "City166", + Street = "Street166", + BuildingNumber = "BuildingNumber166", + Latitude = 0, + Longitude = 0, + }, + ActualAddress = new Address + { + Id = 125, + Region = "Region125", + District = "District125", + City = "City125", + Street = "Street125", + BuildingNumber = "BuildingNumber125", + Latitude = 0, + Longitude = 0, + }, + }; + + // Act and Assert + Assert.ThrowsAsync( + async () => await service.Create(expected.ToModel()).ConfigureAwait(false)); + } + + [Test] + [Order(3)] public void Create_NotUniqueEntity_ReturnsArgumentException() { // Arrange @@ -175,7 +228,7 @@ public void Create_NotUniqueEntity_ReturnsArgumentException() } [Test] - [Order(3)] + [Order(4)] public async Task GetAll_WhenCalled_ReturnsAllEntities() { // Arrange @@ -189,7 +242,7 @@ public async Task GetAll_WhenCalled_ReturnsAllEntities() } [Test] - [Order(4)] + [Order(5)] [TestCase(1)] public async Task GetById_WhenIdIsValid_ReturnsEntity(long id) { @@ -204,7 +257,7 @@ public async Task GetById_WhenIdIsValid_ReturnsEntity(long id) } [Test] - [Order(5)] + [Order(6)] [TestCase(10)] public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) { @@ -214,7 +267,7 @@ public void GetById_WhenIdIsInvalid_ThrowsArgumentOutOfRangeException(long id) } [Test] - [Order(6)] + [Order(7)] public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() { // Arrange @@ -232,7 +285,7 @@ public async Task Update_WhenEntityIsValid_UpdatesExistedEntity() } [Test] - [Order(7)] + [Order(8)] public void Update_WhenEntityIsInvalid_ThrowsDbUpdateConcurrencyException() { // Arrange @@ -247,7 +300,7 @@ public void Update_WhenEntityIsInvalid_ThrowsDbUpdateConcurrencyException() } [Test] - [Order(8)] + [Order(9)] [TestCase(1)] public async Task Delete_WhenIdIsValid_DeletesEntity(long id) { @@ -263,7 +316,7 @@ public async Task Delete_WhenIdIsValid_DeletesEntity(long id) } [Test] - [Order(9)] + [Order(10)] [TestCase(10)] public void Delete_WhenIdIsInvalid_ThrowsArgumentNullException(long id) { diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs index f1dcec9de8..c3502a48de 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs @@ -70,7 +70,7 @@ public async Task GetById(long id) return Ok(await service.GetById(id).ConfigureAwait(false)); } - + /// /// To create new Parent and add to the DB. /// diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/UserController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/UserController.cs index 15acb29e82..b330043d10 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/UserController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/UserController.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Services; namespace OutOfSchool.WebApi.Controllers @@ -59,5 +60,27 @@ public async Task GetUserById(string id) return BadRequest(ex.Message); } } + + /// + /// Update info about the User. + /// + /// Entity to update. + /// Updated Provider. + [Authorize(AuthenticationSchemes = "Bearer")] + [Authorize(Roles = "parent,provider,admin")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + [HttpPut] + public async Task Update(UserDto dto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + return Ok(await userService.Update(dto).ConfigureAwait(false)); + } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/ProviderDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/ProviderDTO.cs index 1c4e627b2d..64cc274cbf 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/ProviderDTO.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/ProviderDTO.cs @@ -58,7 +58,7 @@ public class ProviderDto [DataType(DataType.PhoneNumber)] [RegularExpression( @"([\d]{10})", - ErrorMessage = "Phone number format is incorrect. Example: 380 50-123-45-67")] + ErrorMessage = "Phone number format is incorrect. Example: 0501234567")] [DisplayFormat(DataFormatString = "{0:+38 XXX-XXX-XX-XX}")] public string PhoneNumber { get; set; } = string.Empty; diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/UserDto.cs b/OutOfSchool/OutOfSchool.WebApi/Models/UserDto.cs index b34041d607..3764002232 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/UserDto.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/UserDto.cs @@ -19,5 +19,7 @@ public class UserDto : IdentityUser public string FirstName { get; set; } public string Role { get; set; } + + public bool IsRegistered { get; set; } } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs index 3c01ad69f2..da5ff4309d 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/WorkshopDTO.cs @@ -17,8 +17,8 @@ public class WorkshopDTO [DataType(DataType.PhoneNumber)] [Required(ErrorMessage = "Phone number is required")] [RegularExpression( - @"([\d]{9})", - ErrorMessage = "Phone number format is incorrect. Example: 380 50-123-45-67")] + @"([\d]{10})", + ErrorMessage = "Phone number format is incorrect. Example: 0501234567")] [DisplayFormat(DataFormatString = "{0:+38 XXX-XXX-XX-XX}")] public string Phone { get; set; } = string.Empty; @@ -36,11 +36,11 @@ public class WorkshopDTO public string Instagram { get; set; } = string.Empty; [Required(ErrorMessage = "Children's min age is required")] - [Range(0, 16, ErrorMessage = "Min age should be a number from 0 to 16")] + [Range(0, 18, ErrorMessage = "Min age should be a number from 0 to 18")] public int MinAge { get; set; } [Required(ErrorMessage = "Children's max age is required")] - [Range(0, 16, ErrorMessage = "Max age should be a number from 0 to 16")] + [Range(0, 18, ErrorMessage = "Max age should be a number from 0 to 18")] public int MaxAge { get; set; } [Required(ErrorMessage = "Specify how many times per week lessons will be held")] diff --git a/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.en.resx b/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.en.resx index fcab82b279..b92d85feb5 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.en.resx +++ b/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.en.resx @@ -137,4 +137,8 @@ There is already a provider with such a data ProviderService + + You can not create more than one account. + ProviderService + \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.uk.resx b/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.uk.resx index c507fa0117..c22e264e50 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.uk.resx +++ b/OutOfSchool/OutOfSchool.WebApi/Resources/SharedResource.uk.resx @@ -132,4 +132,7 @@ Вже існує провайдер із подібною інформацією. + + Ви не можете створити більше одного облікового запису. + \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/IParentService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/IParentService.cs index f3c81346de..4c09c9f6f6 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/IParentService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/IParentService.cs @@ -30,7 +30,7 @@ public interface IParentService /// Key in the table. /// Parent object. Task GetById(long id); - + /// /// To Update our object in DB. /// diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/IUserService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/IUserService.cs index 0ce36742d4..7a8fab39c3 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/IUserService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/IUserService.cs @@ -18,5 +18,12 @@ public interface IUserService /// Key in the table. /// User. Task GetById(string id); + + /// + /// Update entity. + /// + /// User entity to add. + /// A representing the result of the asynchronous operation. + Task Update(UserDto dto); } } diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs index 7d41ec602f..bdb1b6ee7b 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ParentService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Localization; @@ -119,6 +120,6 @@ public async Task Update(ParentDTO dto) 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 312278700a..ec09f45882 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs @@ -53,6 +53,11 @@ public async Task Create(ProviderDto dto) throw new ArgumentException(localizer["There is already a provider with such a data."]); } + if (providerRepository.ExistsUserId(dto.UserId)) + { + throw new ArgumentException(localizer["You can not create more than one account."]); + } + Func> operation = async () => await providerRepository.Create(dto.ToDomain()).ConfigureAwait(false); var newProvider = await providerRepository.RunInTransaction(operation).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs index 3f17e801e5..01a3657fc0 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/UserService.cs @@ -4,6 +4,7 @@ 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; @@ -65,5 +66,24 @@ public async Task GetById(string id) return users.FirstOrDefault().ToModel(); } + + public async Task Update(UserDto dto) + { + logger.Information($"Updating User with Id = {dto?.Id} started."); + + try + { + var user = await repository.Update(dto.ToDomain()).ConfigureAwait(false); + + logger.Information($"User with Id = {user?.Id} updated succesfully."); + + return user.ToModel(); + } + catch (DbUpdateConcurrencyException) + { + logger.Error($"Updating failed. User with Id = {dto?.Id} doesn't exist in the system."); + throw; + } + } } }