diff --git a/src/web/Client/Features/Profile/ChildProfileCard.razor b/src/web/Client/Features/Profile/ChildProfileCard.razor index 0049c3d6..72f1f941 100644 --- a/src/web/Client/Features/Profile/ChildProfileCard.razor +++ b/src/web/Client/Features/Profile/ChildProfileCard.razor @@ -7,7 +7,7 @@ - @Child.GetAge() år + @Child.Age år @Child.DateOfBirth.Value.ToString("d") diff --git a/src/web/Client/Features/Profile/UserProfileCard.razor b/src/web/Client/Features/Profile/UserProfileCard.razor index 9e0f127a..817111de 100644 --- a/src/web/Client/Features/Profile/UserProfileCard.razor +++ b/src/web/Client/Features/Profile/UserProfileCard.razor @@ -9,7 +9,7 @@ - @Profile.GetAge() år + @Profile.Age år @Profile.DateOfBirth.Value.ToString("d") diff --git a/src/web/Client/Features/UserSearch/UserSearchResultComponent.razor b/src/web/Client/Features/UserSearch/UserSearchResultComponent.razor index f36276ef..0eaef020 100644 --- a/src/web/Client/Features/UserSearch/UserSearchResultComponent.razor +++ b/src/web/Client/Features/UserSearch/UserSearchResultComponent.razor @@ -67,8 +67,7 @@ else private string GetAgeString(ChildDto child) { - var age = child.DateOfBirth.GetAge(); - return age is not null ? $"{age} år" : "?"; + return child.Age is not null ? $"{child.Age} år" : "?"; } private async Task SaveScrollPosition(UserDto user) diff --git a/src/web/Server/Properties/launchSettings.json b/src/web/Server/Properties/launchSettings.json index bb0f9377..3aca5d9e 100644 --- a/src/web/Server/Properties/launchSettings.json +++ b/src/web/Server/Properties/launchSettings.json @@ -8,7 +8,7 @@ "applicationUrl": "https://localhost:7116;http://localhost:5235", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", - "ConnectionStrings_JordnaerDbContext": "Server=localhost,1433;Database=jordnaer;User ID=sa;Password=6efe173b-3e33-4d6c-8f50-3e5f7cadd54c;Persist Security Info=False;TrustServerCertificate=true;" + "ConnectionStrings_JordnaerDbContext": "Server=localhost,1433;Database=jordnaer;User ID=sa;Password=b1509e74-7cdf-4575-96c5-70ac47115acc;Persist Security Info=False;TrustServerCertificate=true;" } } } diff --git a/src/web/Shared/Extensions/ChildProfileExtensions.cs b/src/web/Shared/Extensions/ChildProfileExtensions.cs index bf630373..531f0fad 100644 --- a/src/web/Shared/Extensions/ChildProfileExtensions.cs +++ b/src/web/Shared/Extensions/ChildProfileExtensions.cs @@ -12,6 +12,7 @@ public static void LoadValuesFrom(this ChildProfile mapInto, ChildProfile mapFro mapInto.Gender = mapFrom.Gender; mapInto.PictureUrl = mapFrom.PictureUrl; mapInto.Id = mapFrom.Id; + mapInto.Age = mapFrom.Age; } public static ChildProfileDto ToChildProfileDto(this ChildProfile childProfile) => @@ -22,6 +23,7 @@ public static ChildProfileDto ToChildProfileDto(this ChildProfile childProfile) Gender = childProfile.Gender, PictureUrl = childProfile.PictureUrl, DateOfBirth = childProfile.DateOfBirth, - Description = childProfile.Description + Description = childProfile.Description, + Age = childProfile.Age }; } diff --git a/src/web/Shared/Extensions/DateOnlyExtensions.cs b/src/web/Shared/Extensions/DateOnlyExtensions.cs deleted file mode 100644 index f5e574e4..00000000 --- a/src/web/Shared/Extensions/DateOnlyExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Jordnaer.Shared; - -public static class DateOnlyExtensions -{ - public static int GetAge(this DateTime dateOfBirth) - { - int age = DateTime.Now.Year - dateOfBirth.Year; - - if (DateTime.Now.Month < dateOfBirth.Month || - DateTime.Now.Month == dateOfBirth.Month && DateTime.Now.Day < dateOfBirth.Day) - { - age--; - } - - return age; - } - - public static int? GetAge(this DateTime? dateOfBirth) => dateOfBirth?.GetAge(); -} diff --git a/src/web/Shared/Extensions/UserProfileExtensions.cs b/src/web/Shared/Extensions/UserProfileExtensions.cs index 4e12fd7f..2133c330 100644 --- a/src/web/Shared/Extensions/UserProfileExtensions.cs +++ b/src/web/Shared/Extensions/UserProfileExtensions.cs @@ -1,52 +1,53 @@ -namespace Jordnaer.Shared; - -public static class UserProfileExtensions -{ - public static UserProfile Map(this UserProfile dto) - => new() - { - Id = dto.Id, - UserName = dto.UserName, - FirstName = dto.FirstName, - LastName = dto.LastName, - Address = dto.Address, - ChildProfiles = dto.ChildProfiles, - City = dto.City, - DateOfBirth = dto.DateOfBirth, - Description = dto.Description, - LookingFor = dto.LookingFor, - PhoneNumber = dto.PhoneNumber, - ZipCode = dto.ZipCode, - ProfilePictureUrl = dto.ProfilePictureUrl, - Contacts = dto.Contacts, - CreatedUtc = dto.CreatedUtc - }; - - public static ProfileDto ToProfileDto(this UserProfile userProfile) - => new() +namespace Jordnaer.Shared; + +public static class UserProfileExtensions +{ + public static UserProfile Map(this UserProfile dto) + => new() { - Id = userProfile.Id, - FirstName = userProfile.FirstName, - LastName = userProfile.LastName, - Address = userProfile.Address, - ChildProfiles = userProfile.ChildProfiles - .Select(childProfile => childProfile.ToChildProfileDto()) - .ToList(), - City = userProfile.City, - DateOfBirth = userProfile.DateOfBirth, - Description = userProfile.Description, - LookingFor = userProfile.LookingFor, - PhoneNumber = userProfile.PhoneNumber, - ZipCode = userProfile.ZipCode, - ProfilePictureUrl = userProfile.ProfilePictureUrl, - CreatedUtc = userProfile.CreatedUtc - }; - - public static UserSlim ToUserSlim(this UserProfile userProfile) - => new() - { - DisplayName = $"{userProfile.FirstName} {userProfile.LastName}", - Id = userProfile.Id, - ProfilePictureUrl = userProfile.ProfilePictureUrl - }; -} + Id = dto.Id, + UserName = dto.UserName, + FirstName = dto.FirstName, + LastName = dto.LastName, + Address = dto.Address, + ChildProfiles = dto.ChildProfiles, + City = dto.City, + DateOfBirth = dto.DateOfBirth, + Description = dto.Description, + LookingFor = dto.LookingFor, + PhoneNumber = dto.PhoneNumber, + ZipCode = dto.ZipCode, + ProfilePictureUrl = dto.ProfilePictureUrl, + Contacts = dto.Contacts, + CreatedUtc = dto.CreatedUtc + }; + + public static ProfileDto ToProfileDto(this UserProfile userProfile) + => new() + { + Id = userProfile.Id, + FirstName = userProfile.FirstName, + LastName = userProfile.LastName, + Address = userProfile.Address, + ChildProfiles = userProfile.ChildProfiles + .Select(childProfile => childProfile.ToChildProfileDto()) + .ToList(), + City = userProfile.City, + DateOfBirth = userProfile.DateOfBirth, + Description = userProfile.Description, + LookingFor = userProfile.LookingFor, + PhoneNumber = userProfile.PhoneNumber, + ZipCode = userProfile.ZipCode, + ProfilePictureUrl = userProfile.ProfilePictureUrl, + CreatedUtc = userProfile.CreatedUtc, + Age = userProfile.Age + }; + + public static UserSlim ToUserSlim(this UserProfile userProfile) + => new() + { + DisplayName = $"{userProfile.FirstName} {userProfile.LastName}", + Id = userProfile.Id, + ProfilePictureUrl = userProfile.ProfilePictureUrl + }; +} diff --git a/src/web/Shared/Profile/DTO/ChildProfileDto.cs b/src/web/Shared/Profile/DTO/ChildProfileDto.cs index 29daea9b..caa6314f 100644 --- a/src/web/Shared/Profile/DTO/ChildProfileDto.cs +++ b/src/web/Shared/Profile/DTO/ChildProfileDto.cs @@ -14,5 +14,5 @@ public class ChildProfileDto public string PictureUrl { get; set; } = ProfileConstants.Default_Profile_Picture; - public int? GetAge() => DateOfBirth.GetAge(); + public int? Age { get; set; } } diff --git a/src/web/Shared/Profile/DTO/ProfileDto.cs b/src/web/Shared/Profile/DTO/ProfileDto.cs index dbabb128..0922670d 100644 --- a/src/web/Shared/Profile/DTO/ProfileDto.cs +++ b/src/web/Shared/Profile/DTO/ProfileDto.cs @@ -24,9 +24,9 @@ public class ProfileDto public DateTime? DateOfBirth { get; set; } - public string? ProfilePictureUrl { get; set; } + public string ProfilePictureUrl { get; set; } = null!; - public int? GetAge() => DateOfBirth.GetAge(); + public int? Age { get; set; } public DateTime CreatedUtc { get; set; } = DateTime.UtcNow; diff --git a/src/web/Shared/UserSearch/ChildDto.cs b/src/web/Shared/UserSearch/ChildDto.cs index cb4add02..39c62016 100644 --- a/src/web/Shared/UserSearch/ChildDto.cs +++ b/src/web/Shared/UserSearch/ChildDto.cs @@ -6,4 +6,5 @@ public class ChildDto public string? LastName { get; set; } public Gender? Gender { get; set; } public DateTime? DateOfBirth { get; set; } + public int? Age { get; set; } }