64 lines
2.1 KiB
C#
64 lines
2.1 KiB
C#
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Text.Json.Serialization;
|
|
using AyCode.Core.Interfaces;
|
|
using AyCode.Interfaces;
|
|
using AyCode.Models.Users;
|
|
using TIAM.Entities.Products;
|
|
using TIAM.Entities.Profiles;
|
|
using TIAM.Entities.ServiceProviders;
|
|
using TIAM.Entities.Users;
|
|
|
|
namespace TIAM.Models.Dtos.Users;
|
|
|
|
public class UserModelDto : AcUserModelDtoBase<UserDto, Profile, Company, UserToCompany>, IProductsRelation, IUserModelDtoMinBase, IAcModelDtoBase<User>, IProfileForeignKey
|
|
{
|
|
public List<UserProductMapping> UserProductMappings { get; set; }
|
|
public List<Product> Products { get; set; }
|
|
|
|
[NotMapped]
|
|
[JsonIgnore]
|
|
[Newtonsoft.Json.JsonIgnore]
|
|
public Guid ProfileId
|
|
{
|
|
get => ProfileDto.Id;
|
|
set => ProfileDto.Id = value;
|
|
}
|
|
|
|
public UserModelDto(){}
|
|
public UserModelDto(User user) : base(user)
|
|
{
|
|
if (user.Products.Count == 0) return;
|
|
|
|
//így proxy error lesz... - J.
|
|
//Products = new List<Product>(user.Products);
|
|
//UserProductMappings = new List<UserProductMapping>(user.UserProductMappings);
|
|
|
|
Products = new List<Product>(user.Products.Count);
|
|
UserProductMappings = new List<UserProductMapping>(user.UserProductMappings.Count);
|
|
|
|
foreach (var product in user.Products)
|
|
{
|
|
Products.Add(new Product(product.Id, product.ServiceProviderId, product.ProductType, product.Name, product.Description, product.Price, product.JsonDetails));
|
|
}
|
|
|
|
foreach (var userProduct in user.UserProductMappings)
|
|
{
|
|
UserProductMappings.Add(new UserProductMapping(userProduct.Id, userProduct.UserId, userProduct.ProductId));
|
|
}
|
|
}
|
|
|
|
public virtual User CreateMainEntity()
|
|
{
|
|
//TODO: Models... - J.
|
|
throw new NotImplementedException("CreateMainEntity");
|
|
|
|
return new User
|
|
{
|
|
Id = Id,
|
|
ProfileId = UserDto.ProfileId,
|
|
AffiliateId = UserDto.AffiliateId,
|
|
ServiceProviders = ServiceProviders.ToList(),
|
|
UserToServiceProviders = UserToServiceProviders.ToList()
|
|
};
|
|
}
|
|
} |