diff --git a/Extensions/xIdentityModelsExtensions.cs b/Extensions/xIdentityModelsExtensions.cs
index 12fbbf9..2f1282f 100644
--- a/Extensions/xIdentityModelsExtensions.cs
+++ b/Extensions/xIdentityModelsExtensions.cs
@@ -1,3 +1,151 @@
-namespace xIdentityModels.Extensions {
- public static class xIdentityModelsExtensions { }
+using System.Collections.Generic;
+using System.Linq;
+using xCommons.Extensions;
+using xIdentityModels.Configurations;
+using xIdentityModels.Constants;
+using xIdentityModels.Dtos;
+
+namespace xIdentityModels.Extensions
+{
+ public static class xIdentityModelsExtensions
+ {
+ ///
+ /// Converts a User Entity to Profile Dto ...
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static XUserProfileDto ToXProfileDto(
+ this XUser source,
+ bool isAdmin = false,
+ bool isSameUser = false,
+ IEnumerable roles = null,
+ XFriendshipInfoDto friendship = null,
+ XIdentityProfile profileConfig = null
+ )
+ {
+ //
+ XUserProfileDto result = null;
+
+ //
+ if (roles == null)
+ {
+ roles = new List();
+ }
+
+ //
+ // 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();
+ }
+
+ //
+ return result;
+ }
+ }
}
\ No newline at end of file
diff --git a/Models/XProfileUpdateRequest.cs b/Models/XProfileUpdateRequest.cs
index 12edc71..f451873 100644
--- a/Models/XProfileUpdateRequest.cs
+++ b/Models/XProfileUpdateRequest.cs
@@ -18,5 +18,8 @@ namespace xIdentityModels.Models {
public ICollection Roles { get; set; } = new HashSet ();
public bool? IsEnable { get; set; }
public bool? IsBanned { get; set; }
+ public string Bio { get; set; }
+ public string CoverImage { get; set; }
+ public bool OpenToSearch { get; set; }
}
}
\ No newline at end of file