Skip to content

Commit

Permalink
fixes regarding age
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Sep 16, 2023
1 parent 43381d7 commit 2f07bd3
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/web/Client/Features/Profile/ChildProfileCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<MudTextFieldExtended Label="Alder" ReadOnly T="string">
<AdornmentStart>
<MudIcon Color="Color.Default" Icon="@Icons.Material.Filled.Cake" Class="mr-2" />
<MudText Color="Color.Default">@Child.GetAge() år</MudText>
<MudText Color="Color.Default">@Child.Age år</MudText>
</AdornmentStart>
<AdornmentEnd>
<MudText Color="Color.Default">@Child.DateOfBirth.Value.ToString("d")</MudText>
Expand Down
2 changes: 1 addition & 1 deletion src/web/Client/Features/Profile/UserProfileCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<MudTextFieldExtended Label="Alder" ReadOnly T="string">
<AdornmentStart>
<MudIcon Color="Color.Default" Icon="@Icons.Material.Filled.Cake" Class="mr-2" />
<MudText Color="Color.Default">@Profile.GetAge() år</MudText>
<MudText Color="Color.Default">@Profile.Age år</MudText>
</AdornmentStart>
<AdornmentEnd>
<MudText Color="Color.Default">@Profile.DateOfBirth.Value.ToString("d")</MudText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/web/Server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/web/Shared/Extensions/ChildProfileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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
};
}
19 changes: 0 additions & 19 deletions src/web/Shared/Extensions/DateOnlyExtensions.cs

This file was deleted.

103 changes: 52 additions & 51 deletions src/web/Shared/Extensions/UserProfileExtensions.cs
Original file line number Diff line number Diff line change
@@ -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
};
}
2 changes: 1 addition & 1 deletion src/web/Shared/Profile/DTO/ChildProfileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
4 changes: 2 additions & 2 deletions src/web/Shared/Profile/DTO/ProfileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/web/Shared/UserSearch/ChildDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

0 comments on commit 2f07bd3

Please sign in to comment.