using Netina.Domain.Entities.Accounting; namespace Netina.Domain; public class MapsterRegister : IRegister { public void Register(TypeAdapterConfig config) { config.NewConfig() .Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f=>f.IsPrimary) ? o.Files.FirstOrDefault(f=>f.IsPrimary)!.FileName : string.Empty) .TwoWays(); config.NewConfig() .Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f => f.IsPrimary) ? o.Files.FirstOrDefault(f => f.IsPrimary)!.FileName : string.Empty) .TwoWays(); config.NewConfig() .Map("BlogCount", o => o.Blogs.Count) .TwoWays(); config.NewConfig() .Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f => f.IsHeader) ? o.Files.FirstOrDefault(f => f.IsHeader)!.FileName : string.Empty) .TwoWays(); config.NewConfig() .Map("ShippingMethod", o => o.Shipping != null ? o.Shipping.Name : string.Empty) .TwoWays(); config.NewConfig() .Map("MainImage", o => o.Files.FirstOrDefault(f => f.IsPrimary) != null ? o.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : o.Files.Count > 0 ? o.Files.FirstOrDefault().FileLocation : string.Empty) .Map("ParentName", o => o.Parent != null ? o.Parent.Name : string.Empty) .TwoWays(); config.NewConfig() .Map("ParentName", o => o.Parent != null ? o.Parent.Name : string.Empty) .TwoWays(); config.NewConfig() .Map("MainImage",o=>o.Files.FirstOrDefault(f=>f.IsPrimary) != null ? o.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : o.Files.Count>0 ? o.Files.FirstOrDefault().FileLocation : string.Empty) .Map("CategoryName", o => o.Category == null ? null : o.Category.Name) .Map("BrandName", o => o.Brand == null ? null : o.Brand.PersianName) .IgnoreNullValues(false) .TwoWays(); config.NewConfig() .Map("CustomerFullName", o => o.Customer != null && o.Customer.User != null ? o.Customer.User.FirstName + " " + o.Customer.User.LastName : string.Empty) .Map("CustomerPhoneNumber", o => o.Customer != null && o.Customer.User != null ? o.Customer.User.PhoneNumber : string.Empty) .IgnoreNullValues(false) .TwoWays(); config.NewConfig() .Map("CategoryName", o => o.Category == null ? null : o.Category.Name) .Map("BrandName", o => o.Brand == null ? null : o.Brand.PersianName) .IgnoreNullValues(false) .TwoWays(); ConfigOrderMappers(config); ConfigUserMappers(config); } private void ConfigOrderMappers(TypeAdapterConfig config) { config.NewConfig() .Map("CustomerFullName", o => o.Customer != null && o.Customer.User != null ? o.Customer.User.FirstName + " " + o.Customer.User.LastName : string.Empty) .Map("CustomerPhoneNumber", o => o.Customer != null && o.Customer.User != null ? o.Customer.User.PhoneNumber : string.Empty) .IgnoreNullValues(false) .TwoWays(); config.NewConfig() .Map("CustomerFullName", o => o.Customer != null && o.Customer.User != null ? o.Customer.User.FirstName + " " + o.Customer.User.LastName : string.Empty) .Map("CustomerPhoneNumber", o => o.Customer != null && o.Customer.User != null ? o.Customer.User.PhoneNumber : string.Empty) .IgnoreNullValues(false) .TwoWays(); config.NewConfig() .Map("ProductName", o => o.Product != null ? o.Product.PersianName : string.Empty) .IgnoreNullValues(false) .TwoWays(); config.NewConfig() .Map("Province", o => o.Address != null ? o.Address.Province : string.Empty) .Map("City", o => o.Address != null ? o.Address.City : string.Empty) .Map("Plaque", o => o.Address != null ? o.Address.Plaque : string.Empty) .Map("LocationLat", o => o.Address != null ? o.Address.LocationLat : 0) .Map("LocationLong", o => o.Address != null ? o.Address.LocationLong : 0) .Map("PostalCode", o => o.Address != null ? o.Address.PostalCode : string.Empty) .Map("ReceiverPhoneNumber", o => o.Address != null ? o.Address.ReceiverPhoneNumber : string.Empty) .Map("ReceiverFullName", o => o.Address != null ? o.Address.ReceiverFullName : string.Empty) .Map("Address", o => o.Address != null ? o.Address.Address : string.Empty) .Map("ShippingMethod", o => o.Shipping != null ? o.Shipping.Name : string.Empty) .IgnoreNullValues(false) .TwoWays(); } private void ConfigUserMappers(TypeAdapterConfig config) { config.NewConfig() .Map("PhoneNumber", o => o.User != null ? o.User.PhoneNumber : string.Empty) .Map("FirstName", o => o.User != null ? o.User.FirstName : string.Empty) .Map("LastName", o => o.User != null ? o.User.LastName : string.Empty) .Map("BirthDate", o => o.User != null ? o.User.BirthDate : DateTime.MinValue) .Map("Gender", o => o.User != null ? o.User.Gender : 0) .Map("SignUpStatus", o => o.User != null ? o.User.SignUpStatus : 0) .Map("NationalId", o => o.User != null ? o.User.NationalId : string.Empty) .Map("Email", o => o.User != null ? o.User.Email : string.Empty) .TwoWays(); config.NewConfig() .Map("PhoneNumber", o => o.User != null ? o.User.PhoneNumber : string.Empty) .Map("FirstName", o => o.User != null ? o.User.FirstName : string.Empty) .Map("LastName", o => o.User != null ? o.User.LastName : string.Empty) .Map("BirthDate", o => o.User != null ? o.User.BirthDate : DateTime.MinValue) .Map("Gender", o => o.User != null ? o.User.Gender : 0) .Map("SignUpStatus", o => o.User != null ? o.User.SignUpStatus : 0) .Map("NationalId", o => o.User != null ? o.User.NationalId : string.Empty) .Map("Email", o => o.User != null ? o.User.Email : string.Empty) .TwoWays(); config.NewConfig() .Map("PhoneNumber", o => o.User != null ? o.User.PhoneNumber : string.Empty) .Map("FirstName", o => o.User != null ? o.User.FirstName : string.Empty) .Map("LastName", o => o.User != null ? o.User.LastName : string.Empty) .Map("BirthDate", o => o.User != null ? o.User.BirthDate : DateTime.MinValue) .Map("Gender", o => o.User != null ? o.User.Gender : 0) .Map("SignUpStatus", o => o.User != null ? o.User.SignUpStatus : 0) .Map("NationalId", o => o.User != null ? o.User.NationalId : string.Empty) .Map("Email", o => o.User != null ? o.User.Email : string.Empty) .TwoWays(); } }