BotSharp/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Users/UserViewModel.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2023-11-14 04:56:06 +00:00
using BotSharp.Abstraction.Users.Enums;
2023-11-14 14:13:54 +00:00
using System.Text.Json.Serialization;
2023-08-19 00:15:02 +00:00
namespace BotSharp.OpenAPI.ViewModels.Users;
public class UserViewModel
{
2024-05-31 03:24:34 +00:00
public string Id { get; set; } = null!;
2024-01-05 03:20:50 +00:00
[JsonPropertyName("user_name")]
2024-05-31 03:24:34 +00:00
public string UserName { get; set; } = null!;
2023-11-14 14:13:54 +00:00
[JsonPropertyName("first_name")]
2024-05-31 03:24:34 +00:00
public string FirstName { get; set; } = null!;
2023-11-14 14:13:54 +00:00
[JsonPropertyName("last_name")]
2024-05-31 03:24:34 +00:00
public string? LastName { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
2024-09-19 00:49:32 +00:00
public string Type { get; set; } = UserType.Client;
public string Role { get; set; } = UserRole.User;
2023-11-14 14:13:54 +00:00
[JsonPropertyName("full_name")]
2024-02-14 23:45:28 +00:00
public string FullName => $"{FirstName} {LastName}".Trim();
public string Source { get; set; }
2024-01-23 19:32:35 +00:00
[JsonPropertyName("external_id")]
public string? ExternalId { get; set; }
2024-05-22 04:33:31 +00:00
public string Avatar { get; set; } = "/user/avatar";
2024-01-23 19:32:35 +00:00
[JsonPropertyName("create_date")]
public DateTime CreateDate { get; set; }
[JsonPropertyName("update_date")]
public DateTime UpdateDate { get; set; }
2023-11-14 01:25:25 +00:00
2023-08-19 00:15:02 +00:00
public static UserViewModel FromUser(User user)
{
2023-11-15 13:33:46 +00:00
if (user == null)
{
return new UserViewModel
{
2024-01-31 19:57:54 +00:00
FirstName = "Unknown",
LastName = "Anonymous",
2024-09-19 00:49:32 +00:00
Type = UserType.Client,
2024-01-31 19:57:54 +00:00
Role = AgentRole.User
2023-11-15 13:33:46 +00:00
};
}
2023-08-19 00:15:02 +00:00
return new UserViewModel
{
Id = user.Id,
2024-01-05 03:20:50 +00:00
UserName = user.UserName,
2023-08-19 00:15:02 +00:00
FirstName = user.FirstName,
LastName = user.LastName,
2023-11-14 04:56:06 +00:00
Email = user.Email,
2024-05-31 03:24:34 +00:00
Phone = user.Phone,
2024-09-19 00:49:32 +00:00
Type = user.Type,
2024-01-23 19:32:35 +00:00
Role = user.Role,
2024-02-14 23:45:28 +00:00
Source = user.Source,
2024-01-23 19:32:35 +00:00
ExternalId = user.ExternalId,
CreateDate = user.CreatedTime,
2024-05-22 04:33:31 +00:00
UpdateDate = user.UpdatedTime,
Avatar = "/user/avatar"
2023-08-19 00:15:02 +00:00
};
}
}