Api/Netina.Domain/MapsterRegister.cs

173 lines
9.0 KiB
C#
Raw Normal View History

using Netina.Domain.Dtos.ResponseDtos.Torob;
using Netina.Domain.Entities.Accounting;
2024-09-25 17:08:35 +03:30
using Netina.Domain.Entities.Comments;
2024-04-16 20:01:34 +03:30
namespace Netina.Domain;
public class MapsterRegister : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig<Blog, BlogSDto>()
.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<Blog, BlogLDto>()
2024-09-11 19:59:27 +03:30
.Map(o=>o.AuthorFullName , d=>d.Author!=null ? d.Author.FirstName + " " + d.Author.LastName : string.Empty)
.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<BlogCategory, BlogCategorySDto>()
.Map("BlogCount", o => o.Blogs.Count)
.TwoWays();
config.NewConfig<Brand, BrandSDto>()
2024-04-12 18:30:10 +03:30
.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<OrderDelivery, OrderDeliverySDto>()
.Map("ShippingMethod", o => o.Shipping != null ? o.Shipping.Name : string.Empty)
.TwoWays();
2024-09-25 17:08:35 +03:30
config.NewConfig<Comment, CommentSDto>()
.Map(d => d.UserFullName, o => o.User != null ? o.User.FirstName + " " + o.User.LastName : string.Empty)
.TwoWays();
config.NewConfig<Comment, CommentLDto>()
.Map(d => d.UserFullName, o => o.User != null ? o.User.FirstName + " " + o.User.LastName : string.Empty)
.TwoWays();
ConfigProductMappers(config);
ConfigOrderMappers(config);
ConfigUserMappers(config);
}
private void ConfigProductMappers(TypeAdapterConfig config)
{
2024-02-07 01:12:05 +03:30
config.NewConfig<ProductCategory, ProductCategorySDto>()
.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<ProductCategory, ProductCategoryLDto>()
.Map("ParentName", o => o.Parent != null ? o.Parent.Name : string.Empty)
.TwoWays();
2024-02-07 01:12:05 +03:30
config.NewConfig<Product, ProductSDto>()
2024-09-11 19:59:27 +03:30
.Map(o => o.AuthorFullName, d => d.Author != null ? d.Author.FirstName + " " + d.Author.LastName : string.Empty)
.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)
.Map(d=>d.Rate , o=>o.Rate == 0 ? 4.5 : o.Rate)
.Map(d => d.CommentCount, o => o.ReviewCount)
.IgnoreNullValues(false)
.TwoWays();
config.NewConfig<Payment, PaymentSDto>()
.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<Product, ProductLDto>()
2024-09-11 19:59:27 +03:30
.Map(o => o.AuthorFullName, d => d.Author != null ? d.Author.FirstName + " " + d.Author.LastName : string.Empty)
.Map("CategoryName", o => o.Category == null ? null : o.Category.Name)
.Map("BrandName", o => o.Brand == null ? null : o.Brand.PersianName)
.Map(d => d.Rate, o => o.Rate == 0 ? 4.5 : o.Rate)
.Map(d => d.CommentCount, o => o.ReviewCount)
.IgnoreNullValues(false)
.TwoWays();
2024-09-11 19:59:27 +03:30
config.NewConfig<Product, TorobProductResponseDto>()
2024-09-25 17:08:35 +03:30
.Map(s => s.availibility, o => o.IsEnable)
.Map(s => s.price, o => o.Cost)
.Map(s => s.product_id, o => o.Id.ToString())
.IgnoreNullValues(false)
.TwoWays();
}
private void ConfigOrderMappers(TypeAdapterConfig config)
{
config.NewConfig<Order, OrderSDto>()
.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)
Refactor and enhance product and order handling - Updated `DiscountActionDialogBoxViewModel` and `FastProductCreateDialogBoxViewModel` to create command objects directly from properties and improved error handling. - Added meta tag management UI and logic in `ProductActionDialogBox.razor` and `ProductActionDialogBoxViewModel`. - Increased max file read stream size to 8 MB in `StorageDialogBoxViewModel`. - Incremented `AssemblyVersion` and `FileVersion` to `1.7.20.34` in `Netina.AdminPanel.PWA.csproj`. - Updated `BrandsPage.razor` and `BrandsPageViewModel` for pagination and service injection. - Updated `CategoriesPageViewModel` to create command objects directly from properties. - Updated `ProductsPage.razor` for service injection and added a button for product details. - Updated `ICrudApiRest` and `ICrudDtoApiRest` interfaces to use generic `Create` methods. - Updated `appsettings.Development.json` for `StorageBaseUrl` and commented out `IsShop`. - Added new project `AppHost.csproj` targeting .NET 8.0 with Aspire hosting. - Added new `appsettings.Development.json` and `appsettings.json` for logging. - Added new `Program.cs` to create and run a distributed application. - Added new `launchSettings.json` for application launch settings. - Added `Extensions.cs` for common .NET Aspire services. - Added new project `ServiceDefaults.csproj` for shared service defaults. - Introduced `ProductMetaTag` class and related migration for meta tag handling. - Updated `OrderController.cs` for additional authorization requirements. - Updated target frameworks to `net8.0` in various projects. - Enhanced `SiteMapService.cs` to include brand site maps. - Added new properties to DTOs for customer and meta tag handling. - Enhanced `Product` class with meta tag management methods. - Refactored `OrderMapper.g.cs` and `ProductMapper.g.cs` for improved mapping logic. - Enhanced command handlers to manage meta tags. - Added `ICurrentUserService` for user permissions in query handlers. - Refactored `StorageService.cs` for paginated storage file fetching.
2024-12-06 17:37:41 +03:30
.Map(d=>d.DeliveryTrackingCode,o=>o.OrderDelivery!=null ? o.OrderDelivery.TrackingCode : string.Empty)
.IgnoreNullValues(false)
.TwoWays();
config.NewConfig<Order, OrderLDto>()
.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<OrderProduct, OrderProductSDto>()
.Map("ProductName", o => o.Product != null ? o.Product.PersianName : string.Empty)
.IgnoreNullValues(false)
.TwoWays();
2024-03-01 16:07:11 +03:30
config.NewConfig<OrderDelivery, OrderDeliverySDto>()
.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<ApplicationUser, ApplicationUserSDto>()
.Map("IsMarketer", o => o.Marketer != null)
.Map("IsManager", o => o.Manager != null)
.TwoWays();
config.NewConfig<Manager, ManagerSDto>()
.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<Marketer, MarketerSDto>()
.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<Customer, CustomerSDto>()
.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();
}
}