AyCode.Core/AyCode.Entities/Profiles/AcProfile.cs

75 lines
2.2 KiB
C#

using AyCode.Interfaces.Profiles;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using AyCode.Core.Extensions;
using AyCode.Entities.Addresses;
using AyCode.Interfaces.Addresses;
using AyCode.Utils.Extensions;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace AyCode.Entities.Profiles
{
[Table("Profile")]
public abstract class AcProfile<TAddress> : IAcProfile<TAddress> where TAddress : class, IAcAddress
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public Guid? UserMediaId { get; set; }
[Required]
public Guid AddressId { get; set; }
[ForeignKey(nameof(AddressId))]
public virtual TAddress Address { get; set; }
[Required]
public string Name { get; set; }
public string? FullName => GetFullName("ENG");
public string? FirstName { get; set; }
public string? LastName { get; set; }
//public string NickName { get; set; }
public string? EmailAddress { get; set; }
public string? Description { get; set; }
public string? ThumbnailUrl { get ; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
protected AcProfile() { }
protected AcProfile(Guid id) : this()
{
Id = id;
}
protected AcProfile(Guid id, string name) : this(id)
{
Name = name;
}
public void SetAddress(TAddress address)
{
if (address.Id.IsNullOrEmpty()) address.Id = Guid.NewGuid();
Address = address;
AddressId = address.Id;
}
public string? GetFullName(string lang = "ENG") => GetFullName(FirstName, LastName, lang);
public static string? GetFullName(string? firstName, string? lastName, string? lang = "ENG")
{
if (firstName.IsNullOrWhiteSpace()) return lastName;
if(lastName.IsNullOrWhiteSpace()) return firstName;
if (lang == "ENG") return firstName + " " + lastName;
return lastName + " " + firstName;
}
}
}