Files
2026-06-02 23:44:45 +02:00

259 lines
8.3 KiB
C#

using LiteCharms.Features.MidrandBooks.AuthorBooks.Models;
using LiteCharms.Features.MidrandBooks.Authors.Models;
using LiteCharms.Features.MidrandBooks.Categories.Models;
using LiteCharms.Features.MidrandBooks.Customers.Models;
using LiteCharms.Features.MidrandBooks.Orders.Models;
using LiteCharms.Features.MidrandBooks.Pages.Models;
using LiteCharms.Features.MidrandBooks.Payments.Models;
using LiteCharms.Features.MidrandBooks.Products.Models;
namespace LiteCharms.Features.MidrandBooks.Extensions;
public static class Mappers
{
public static PaymentGatewayLedger ToModel(this Payments.Entities.PaymentGatewayLedger entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
CustomerEmail = entity.CustomerEmail,
OrderId = entity.OrderId,
PaymentId = entity.PaymentId,
MerchantPaymentId = entity.MerchantPaymentId,
PayfastPaymentId = entity.PayfastPaymentId,
PaymentStatus = entity.PaymentStatus,
AmountGross = entity.AmountGross,
AmountFee = entity.AmountFee,
AmountNet = entity.AmountNet
};
public static Refund ToModel(this Payments.Entities.Refund entity) => new()
{
CreatedAt = entity.CreatedAt,
Amount = entity.Amount,
Id = entity.Id,
OrderId = entity.OrderId,
Reason = entity.Reason,
Status = entity.Status,
Type = entity.Type,
UpdatedAt = entity.UpdatedAt,
};
public static PaymentLedger ToModel(this Payments.Entities.PaymentLedger entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
CustomerId = entity.CustomerId,
OrderId = entity.OrderId,
PaymentId = entity.PaymentId,
Status = entity.Status,
MerchantPaymentId = entity.MerchantPaymentId,
};
public static PaymentGateway ToModel(this Payments.Entities.PaymentGateway entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
Enabled = entity.Enabled,
IsSandbox = entity.IsSandbox,
MerchantId = entity.MerchantId,
MerchantKey = entity.MerchantKey,
Name = entity.Name,
Website = entity.Website,
};
public static Payment ToModel(this Payments.Entities.Payment entity) => new()
{
Id = entity.Id,
Amount = entity.Amount,
CreatedAt = entity.CreatedAt,
OrderId = entity.OrderId,
Reference = entity.Reference,
Status = entity.Status,
UpdatedAt = entity.UpdatedAt,
};
public static ProductInventory ToModel(this Products.Entities.ProductInventory entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
ProductId = entity.ProductId,
ProductPriceId = entity.ProductPriceId,
Status = entity.Status,
TotalAllocated = entity.TotalAllocated,
TotalReserved = entity.TotalReserved,
};
public static Category ToModel(this Categories.Entities.Category entity) => new()
{
Id = entity.Id,
Name = entity.Name,
IsMain = entity.IsMain,
Enabled = entity.Enabled,
};
public static ShippingProvider ToModel(this Orders.Entities.ShippingProvider entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
Name = entity.Name,
Type = entity.Type,
Price = entity.Price,
Enabled = entity.Enabled,
TrackingUrl = entity.TrackingUrl,
};
public static Shipping ToModel(this Orders.Entities.Shipping entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
OrderId = entity.OrderId,
AddressId = entity.AddressId,
Status = entity.Status,
TrackingNumber = entity.TrackingNumber
};
public static OrderItem ToModel(this Orders.Entities.OrderItem entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
OrderId = entity.OrderId,
Quantity = entity.Quantity,
AuthorBookId = entity.AuthorBookId,
ProductPriceId = entity.ProductPriceId
};
public static Order ToModel(this Orders.Entities.Order entity) => new()
{
Id = entity.Id,
CustomerId = entity.CustomerId,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
Status = entity.Status,
Total = entity.Total,
InvoiceUrl = entity.InvoiceUrl,
Notes = entity.Notes
};
public static Customer ToModel(this Customers.Entities.Customer entiry) => new()
{
Id = entiry.Id,
Company = entiry.Company,
CreatedAt = entiry.CreatedAt,
Email = entiry.Email,
Enabled = entiry.Enabled,
Phone = entiry.Phone,
SocialMedia = entiry.SocialMedia,
UpdatedAt = entiry.UpdatedAt,
VatNumber = entiry.VatNumber,
Website = entiry.Website
};
public static Address ToModel(this Customers.Entities.Address entity) => new()
{
Id = entity.Id,
BuildingType = entity.BuildingType,
CreatedAt = entity.CreatedAt,
CustomerId = entity.CustomerId,
Enabled = entity.Enabled,
IsPrimary = entity.IsPrimary,
Name = entity.Name,
PostalCode = entity.PostalCode,
Type = entity.Type,
UpdatedAt = entity.UpdatedAt,
Street = entity.Street,
City = entity.City,
State = entity.State,
Country = entity.Country
};
public static Contact ToModel(this Customers.Entities.Contact entity) => new()
{
Id = entity.Id,
Type = entity.Type,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
CustomerId = entity.CustomerId,
Email = entity.Email,
Enabled = entity.Enabled,
LastName = entity.LastName,
Name = entity.Name,
Phone = entity.Phone
};
public static BookPage ToModel(this Pages.Entities.BookPage entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
AuthorBookId = entity.AuthorBookId,
Content = entity.Content,
ContentType = entity.ContentType,
Number = entity.Number,
Enabled = entity.Enabled,
Notes = entity.Notes,
References = entity.References,
Type = entity.Type
};
public static AuthorBook ToModel(this AuthorBooks.Entities.AuthorBook entity) => new()
{
Id = entity.Id,
ProductId = entity.ProductId,
CreatedAt = entity.CreatedAt,
AuthorId = entity.AuthorId,
Ranking = entity.Ranking,
Rating = entity.Rating,
Enabled = entity.Enabled,
Product = entity.Product?.ToModel(),
};
public static ProductPrice ToModel(this Products.Entities.ProductPrice entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
ProductId = entity.ProductId,
Amount = entity.Amount,
Discount = entity.Discount,
Enabled = entity.Enabled
};
public static Product ToModel(this Products.Entities.Product entity) => new Product
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
Name = entity.Name,
Summary = entity.Summary,
Description = entity.Description,
Type = entity.Type,
ImageUrl = entity.ImageUrl,
ThumbnailUrls = entity.ThumbnailUrls,
Metadata = entity.Metadata,
Enabled = entity.Enabled,
Price = entity.Prices?.FirstOrDefault(p => p.Enabled)?.ToModel() ?? null,
};
public static Author ToModel(this Authors.Entities.Author entity) => new()
{
Id = entity.Id,
CreatedAt = entity.CreatedAt,
UpdatedAt = entity.UpdatedAt,
Name = entity.Name,
LastName = entity.LastName,
Biography = entity.Biography,
Email = entity.Email,
Website = entity.Website,
ImageUrl = entity.ImageUrl,
ThumbnailImageUrl = entity.ThumbnailImageUrl,
SocialMedia = entity.SocialMedia,
Enabled = entity.Enabled,
Company = entity.Company,
PublisherType = entity.PublisherType,
VatNumber = entity.VatNumber
};
}