adding bio, coverImage and openToSearch Fields Support for User/UserProfile and Update User ...

This commit is contained in:
2025-12-23 16:34:57 +03:30
parent 23e68de1ef
commit 6a2618a3c4
2 changed files with 153 additions and 2 deletions
+150 -2
View File
@@ -1,3 +1,151 @@
namespace xIdentityModels.Extensions { using System.Collections.Generic;
public static class xIdentityModelsExtensions { } using System.Linq;
using xCommons.Extensions;
using xIdentityModels.Configurations;
using xIdentityModels.Constants;
using xIdentityModels.Dtos;
namespace xIdentityModels.Extensions
{
public static class xIdentityModelsExtensions
{
/// <summary>
/// Converts a User Entity to Profile Dto ...
/// </summary>
/// <param name="source"></param>
/// <param name="isAdmin"></param>
/// <param name="isSameUser"></param>
/// <param name="roles"></param>
/// <param name="friendship"></param>
/// <param name="profileConfig"></param>
/// <returns></returns>
public static XUserProfileDto ToXProfileDto(
this XUser source,
bool isAdmin = false,
bool isSameUser = false,
IEnumerable<string> roles = null,
XFriendshipInfoDto friendship = null,
XIdentityProfile profileConfig = null
)
{
//
XUserProfileDto result = null;
//
if (roles == null)
{
roles = new List<string>();
}
//
// Prepare Dto ...
if (!source.IsNullOrDefault())
{
//
result = new XUserProfileDto
{
Bio = source.Bio,
UserId = source.Id,
Email = source.Email,
Roles = roles.ToList(),
Avatar = source.Avatar,
IsEnable = source.IsEnable,
IsBanned = source.IsBanned,
UserName = source.UserName,
LastName = source.LastName,
FriendshipInfo = friendship,
FirstName = source.FirstName,
LastLogin = source.LastLogin,
CoverImage = source.CoverImage,
PhoneNumber = source.PhoneNumber,
DateOfBirth = source.DateOfBirth,
CreationDate = source.CreationDate,
OpenToSearch = source.OpenToSearch,
Gender = (XGender)(int)source.Gender,
EmailConfirmed = source.EmailConfirmed,
PhoneNumberConfirmed = source.PhoneNumberConfirmed,
Avatars = source.Avatars.Select(pfi =>
{
//
return new XProfileImageDto
{
Id = pfi.Id,
Name = pfi.Name,
Path = pfi.Path,
Thumb = pfi.Thumb,
ThumbPath = pfi.ThumbPath,
CreationDate = pfi.CreationDate
};
}).ToList(),
};
}
//
// Apply Profiling Configuration ...
//
bool isPassed = false;
//
// Handle Friendship ...
isPassed = !isSameUser;
if (!isPassed)
{
result.FriendshipInfo = null;
}
//
// Handle Email Info ...
isPassed = isAdmin || isSameUser || (!profileConfig.IsNullOrDefault() && profileConfig.ContainsEmail);
if (!isPassed)
{
result.Email = string.Empty;
result.EmailConfirmed = false;
}
//
// Handle PhoneNumber Info ...
isPassed = isAdmin || isSameUser || (!profileConfig.IsNullOrDefault() && profileConfig.ContainsPhoneNumber);
if (!isPassed)
{
source.PhoneNumber = string.Empty;
source.PhoneNumberConfirmed = false;
}
//
// Handle Last Login ...
isPassed = isAdmin || isSameUser || (!profileConfig.IsNullOrDefault() && profileConfig.ContainsLastLogin);
if (!isPassed)
{
result.LastLogin = null;
}
//
// Handle Date Of Birth ...
isPassed = isAdmin || isSameUser || (!profileConfig.IsNullOrDefault() && profileConfig.ContainsDateOfBirth);
if (!isPassed)
{
result.DateOfBirth = null;
}
//
// Handle Creation Date ...
isPassed = isAdmin || isSameUser || (!profileConfig.IsNullOrDefault() && profileConfig.ContainsCreationDate);
if (!isPassed)
{
result.CreationDate = null;
}
//
// Handle Roles ...
isPassed = isAdmin || isSameUser || (!profileConfig.IsNullOrDefault() && profileConfig.ContainsRoles);
if (!isPassed)
{
result.Roles = new List<string>();
}
//
return result;
}
}
} }
+3
View File
@@ -18,5 +18,8 @@ namespace xIdentityModels.Models {
public ICollection<string> Roles { get; set; } = new HashSet<string> (); public ICollection<string> Roles { get; set; } = new HashSet<string> ();
public bool? IsEnable { get; set; } public bool? IsEnable { get; set; }
public bool? IsBanned { get; set; } public bool? IsBanned { get; set; }
public string Bio { get; set; }
public string CoverImage { get; set; }
public bool OpenToSearch { get; set; }
} }
} }