Api/Netina.Domain/Mappers/ProductMapper.g.cs

738 lines
28 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Mapster.Models;
using Netina.Domain.Dtos.LargDtos;
using Netina.Domain.Dtos.ResponseDtos.Torob;
using Netina.Domain.Dtos.SmallDtos;
using Netina.Domain.Entities.Brands;
using Netina.Domain.Entities.ProductCategories;
using Netina.Domain.Entities.Products;
using Netina.Domain.Entities.Users;
namespace Netina.Domain.Mappers
{
public static partial class ProductMapper
{
public static Product AdaptToProduct(this ProductLDto p1)
{
return p1 == null ? null : new Product()
{
PersianName = p1.PersianName,
EnglishName = p1.EnglishName,
Slug = p1.Slug,
Summery = p1.Summery,
ExpertCheck = p1.ExpertCheck,
Tags = p1.Tags,
Warranty = p1.Warranty,
Cost = p1.Cost,
BeDisplayed = p1.BeDisplayed,
PackingCost = p1.PackingCost,
Stock = p1.Stock,
Rate = p1.Rate,
HasExpressDelivery = p1.HasExpressDelivery,
MaxOrderCount = p1.MaxOrderCount,
BrandId = p1.BrandId,
Brand = new Brand() {Id = p1.BrandId},
CategoryId = p1.CategoryId,
AuthorId = p1.AuthorId,
Author = new ApplicationUser() {Id = p1.AuthorId},
Category = new ProductCategory()
{
Name = p1.CategoryName,
Id = p1.CategoryId
},
Specifications = funcMain1(p1.Specifications),
Files = funcMain2(p1.Files),
Id = p1.Id,
CreatedAt = p1.CreatedAt
};
}
public static Product AdaptTo(this ProductLDto p4, Product p5)
{
if (p4 == null)
{
return null;
}
Product result = p5 ?? new Product();
result.PersianName = p4.PersianName;
result.EnglishName = p4.EnglishName;
result.Slug = p4.Slug;
result.Summery = p4.Summery;
result.ExpertCheck = p4.ExpertCheck;
result.Tags = p4.Tags;
result.Warranty = p4.Warranty;
result.Cost = p4.Cost;
result.BeDisplayed = p4.BeDisplayed;
result.PackingCost = p4.PackingCost;
result.Stock = p4.Stock;
result.Rate = p4.Rate;
result.HasExpressDelivery = p4.HasExpressDelivery;
result.MaxOrderCount = p4.MaxOrderCount;
result.BrandId = p4.BrandId;
result.Brand = funcMain3(new Never(), result.Brand, p4);
result.CategoryId = p4.CategoryId;
result.AuthorId = p4.AuthorId;
result.Author = funcMain4(new Never(), result.Author, p4);
result.Category = funcMain5(new Never(), result.Category, p4);
result.Specifications = funcMain6(p4.Specifications, result.Specifications);
result.Files = funcMain7(p4.Files, result.Files);
result.Id = p4.Id;
result.CreatedAt = p4.CreatedAt;
return result;
}
public static Expression<Func<ProductLDto, Product>> ProjectToProduct => p16 => new Product()
{
PersianName = p16.PersianName,
EnglishName = p16.EnglishName,
Slug = p16.Slug,
Summery = p16.Summery,
ExpertCheck = p16.ExpertCheck,
Tags = p16.Tags,
Warranty = p16.Warranty,
Cost = p16.Cost,
BeDisplayed = p16.BeDisplayed,
PackingCost = p16.PackingCost,
Stock = p16.Stock,
Rate = p16.Rate,
HasExpressDelivery = p16.HasExpressDelivery,
MaxOrderCount = p16.MaxOrderCount,
BrandId = p16.BrandId,
Brand = new Brand() {Id = p16.BrandId},
CategoryId = p16.CategoryId,
AuthorId = p16.AuthorId,
Author = new ApplicationUser() {Id = p16.AuthorId},
Category = new ProductCategory()
{
Name = p16.CategoryName,
Id = p16.CategoryId
},
Specifications = p16.Specifications.Select<SpecificationSDto, Specification>(p17 => new Specification()
{
Title = p17.Title,
Detail = p17.Detail,
Value = p17.Value,
IsFeature = p17.IsFeature,
ProductId = p17.ProductId,
ParentId = (Guid?)p17.ParentId,
Id = p17.Id,
CreatedAt = p17.CreatedAt
}).ToList<Specification>(),
Files = p16.Files.Select<StorageFileSDto, ProductStorageFile>(p18 => new ProductStorageFile()
{
Name = p18.Name,
FileLocation = p18.FileLocation,
FileName = p18.FileName,
IsHeader = p18.IsHeader,
IsPrimary = p18.IsPrimary,
FileType = p18.FileType,
Id = p18.Id,
CreatedAt = p18.CreatedAt
}).ToList<ProductStorageFile>(),
Id = p16.Id,
CreatedAt = p16.CreatedAt
};
public static ProductLDto AdaptToLDto(this Product p19)
{
return p19 == null ? null : new ProductLDto()
{
PersianName = p19.PersianName,
EnglishName = p19.EnglishName,
Summery = p19.Summery,
ExpertCheck = p19.ExpertCheck,
Tags = p19.Tags,
Slug = p19.Slug,
Warranty = p19.Warranty,
BeDisplayed = p19.BeDisplayed,
HasExpressDelivery = p19.HasExpressDelivery,
Cost = p19.Cost,
PackingCost = p19.PackingCost,
MaxOrderCount = p19.MaxOrderCount,
Stock = p19.Stock,
Rate = (float)(p19.Rate == 0f ? 4.5d : (double)p19.Rate),
CommentCount = p19.ReviewCount,
BrandId = p19.BrandId,
BrandName = p19.Brand == null ? null : p19.Brand.PersianName,
CategoryId = p19.CategoryId,
CategoryName = p19.Category == null ? null : p19.Category.Name,
Specifications = funcMain8(p19.Specifications),
Files = funcMain9(p19.Files),
AuthorId = p19.AuthorId,
AuthorFullName = p19.Author != null ? p19.Author.FirstName + " " + p19.Author.LastName : string.Empty,
Id = p19.Id,
CreatedAt = p19.CreatedAt
};
}
public static ProductLDto AdaptTo(this Product p22, ProductLDto p23)
{
if (p22 == null)
{
return null;
}
ProductLDto result = p23 ?? new ProductLDto();
result.PersianName = p22.PersianName;
result.EnglishName = p22.EnglishName;
result.Summery = p22.Summery;
result.ExpertCheck = p22.ExpertCheck;
result.Tags = p22.Tags;
result.Slug = p22.Slug;
result.Warranty = p22.Warranty;
result.BeDisplayed = p22.BeDisplayed;
result.HasExpressDelivery = p22.HasExpressDelivery;
result.Cost = p22.Cost;
result.PackingCost = p22.PackingCost;
result.MaxOrderCount = p22.MaxOrderCount;
result.Stock = p22.Stock;
result.Rate = (float)(p22.Rate == 0f ? 4.5d : (double)p22.Rate);
result.CommentCount = p22.ReviewCount;
result.BrandId = p22.BrandId;
result.BrandName = p22.Brand == null ? null : p22.Brand.PersianName;
result.CategoryId = p22.CategoryId;
result.CategoryName = p22.Category == null ? null : p22.Category.Name;
result.Specifications = funcMain10(p22.Specifications, result.Specifications);
result.Files = funcMain11(p22.Files, result.Files);
result.AuthorId = p22.AuthorId;
result.AuthorFullName = p22.Author != null ? p22.Author.FirstName + " " + p22.Author.LastName : string.Empty;
result.Id = p22.Id;
result.CreatedAt = p22.CreatedAt;
return result;
}
public static Expression<Func<Product, ProductLDto>> ProjectToLDto => p28 => new ProductLDto()
{
PersianName = p28.PersianName,
EnglishName = p28.EnglishName,
Summery = p28.Summery,
ExpertCheck = p28.ExpertCheck,
Tags = p28.Tags,
Slug = p28.Slug,
Warranty = p28.Warranty,
BeDisplayed = p28.BeDisplayed,
HasExpressDelivery = p28.HasExpressDelivery,
Cost = p28.Cost,
PackingCost = p28.PackingCost,
MaxOrderCount = p28.MaxOrderCount,
Stock = p28.Stock,
Rate = (float)(p28.Rate == 0f ? 4.5d : (double)p28.Rate),
CommentCount = p28.ReviewCount,
BrandId = p28.BrandId,
BrandName = p28.Brand == null ? null : p28.Brand.PersianName,
CategoryId = p28.CategoryId,
CategoryName = p28.Category == null ? null : p28.Category.Name,
Specifications = p28.Specifications.Select<Specification, SpecificationSDto>(p29 => new SpecificationSDto()
{
Title = p29.Title,
Detail = p29.Detail,
Value = p29.Value,
IsFeature = p29.IsFeature,
ProductId = p29.ProductId,
ParentId = p29.ParentId == null ? default(Guid) : (Guid)p29.ParentId,
Id = p29.Id,
CreatedAt = p29.CreatedAt
}).ToList<SpecificationSDto>(),
Files = p28.Files.Select<ProductStorageFile, StorageFileSDto>(p30 => new StorageFileSDto()
{
Name = p30.Name,
FileLocation = p30.FileLocation,
FileName = p30.FileName,
IsHeader = p30.IsHeader,
IsPrimary = p30.IsPrimary,
FileType = p30.FileType,
Id = p30.Id
}).ToList<StorageFileSDto>(),
AuthorId = p28.AuthorId,
AuthorFullName = p28.Author != null ? p28.Author.FirstName + " " + p28.Author.LastName : string.Empty,
Id = p28.Id,
CreatedAt = p28.CreatedAt
};
public static Product AdaptToProduct(this ProductSDto p31)
{
return p31 == null ? null : new Product()
{
PersianName = p31.PersianName,
EnglishName = p31.EnglishName,
Slug = p31.Slug,
Summery = p31.Summery,
ExpertCheck = p31.ExpertCheck,
Tags = p31.Tags,
Warranty = p31.Warranty,
Cost = p31.Cost,
IsEnable = p31.IsEnable,
BeDisplayed = p31.BeDisplayed,
PackingCost = p31.PackingCost,
Stock = p31.Stock,
Rate = p31.Rate,
Viewed = p31.Viewed,
MaxOrderCount = p31.MaxOrderCount,
BrandId = p31.BrandId,
Brand = new Brand() {Id = p31.BrandId},
CategoryId = p31.CategoryId,
AuthorId = p31.AuthorId,
Author = new ApplicationUser() {Id = p31.AuthorId},
Category = new ProductCategory()
{
Name = p31.CategoryName,
Id = p31.CategoryId
},
Id = p31.Id,
CreatedAt = p31.CreatedAt,
ModifiedAt = p31.ModifiedAt
};
}
public static Product AdaptTo(this ProductSDto p32, Product p33)
{
if (p32 == null)
{
return null;
}
Product result = p33 ?? new Product();
result.PersianName = p32.PersianName;
result.EnglishName = p32.EnglishName;
result.Slug = p32.Slug;
result.Summery = p32.Summery;
result.ExpertCheck = p32.ExpertCheck;
result.Tags = p32.Tags;
result.Warranty = p32.Warranty;
result.Cost = p32.Cost;
result.IsEnable = p32.IsEnable;
result.BeDisplayed = p32.BeDisplayed;
result.PackingCost = p32.PackingCost;
result.Stock = p32.Stock;
result.Rate = p32.Rate;
result.Viewed = p32.Viewed;
result.MaxOrderCount = p32.MaxOrderCount;
result.BrandId = p32.BrandId;
result.Brand = funcMain12(new Never(), result.Brand, p32);
result.CategoryId = p32.CategoryId;
result.AuthorId = p32.AuthorId;
result.Author = funcMain13(new Never(), result.Author, p32);
result.Category = funcMain14(new Never(), result.Category, p32);
result.Id = p32.Id;
result.CreatedAt = p32.CreatedAt;
result.ModifiedAt = p32.ModifiedAt;
return result;
}
public static ProductSDto AdaptToSDto(this Product p40)
{
return p40 == null ? null : new ProductSDto()
{
PersianName = p40.PersianName,
Slug = p40.Slug,
EnglishName = p40.EnglishName,
Summery = p40.Summery,
ExpertCheck = p40.ExpertCheck,
Tags = p40.Tags,
Warranty = p40.Warranty,
Cost = p40.Cost,
IsEnable = p40.IsEnable,
Stock = p40.Stock,
MaxOrderCount = p40.MaxOrderCount,
BeDisplayed = p40.BeDisplayed,
PackingCost = p40.PackingCost,
Rate = (float)(p40.Rate == 0f ? 4.5d : (double)p40.Rate),
CommentCount = p40.ReviewCount,
Viewed = p40.Viewed,
MainImage = p40.Files.FirstOrDefault<ProductStorageFile>(funcMain15) != null ? p40.Files.FirstOrDefault<ProductStorageFile>(funcMain16).FileLocation : (p40.Files.Count > 0 ? p40.Files.FirstOrDefault<ProductStorageFile>().FileLocation : string.Empty),
CategoryId = p40.CategoryId,
BrandId = p40.BrandId,
BrandName = p40.Brand == null ? null : p40.Brand.PersianName,
CategoryName = p40.Category == null ? null : p40.Category.Name,
ModifiedAt = p40.ModifiedAt,
AuthorId = p40.AuthorId,
AuthorFullName = p40.Author != null ? p40.Author.FirstName + " " + p40.Author.LastName : string.Empty,
Id = p40.Id,
CreatedAt = p40.CreatedAt
};
}
public static ProductSDto AdaptTo(this Product p41, ProductSDto p42)
{
if (p41 == null)
{
return null;
}
ProductSDto result = p42 ?? new ProductSDto();
result.PersianName = p41.PersianName;
result.Slug = p41.Slug;
result.EnglishName = p41.EnglishName;
result.Summery = p41.Summery;
result.ExpertCheck = p41.ExpertCheck;
result.Tags = p41.Tags;
result.Warranty = p41.Warranty;
result.Cost = p41.Cost;
result.IsEnable = p41.IsEnable;
result.Stock = p41.Stock;
result.MaxOrderCount = p41.MaxOrderCount;
result.BeDisplayed = p41.BeDisplayed;
result.PackingCost = p41.PackingCost;
result.Rate = (float)(p41.Rate == 0f ? 4.5d : (double)p41.Rate);
result.CommentCount = p41.ReviewCount;
result.Viewed = p41.Viewed;
result.MainImage = p41.Files.FirstOrDefault<ProductStorageFile>(funcMain15) != null ? p41.Files.FirstOrDefault<ProductStorageFile>(funcMain16).FileLocation : (p41.Files.Count > 0 ? p41.Files.FirstOrDefault<ProductStorageFile>().FileLocation : string.Empty);
result.CategoryId = p41.CategoryId;
result.BrandId = p41.BrandId;
result.BrandName = p41.Brand == null ? null : p41.Brand.PersianName;
result.CategoryName = p41.Category == null ? null : p41.Category.Name;
result.ModifiedAt = p41.ModifiedAt;
result.AuthorId = p41.AuthorId;
result.AuthorFullName = p41.Author != null ? p41.Author.FirstName + " " + p41.Author.LastName : string.Empty;
result.Id = p41.Id;
result.CreatedAt = p41.CreatedAt;
return result;
}
public static Expression<Func<Product, ProductSDto>> ProjectToSDto => p43 => new ProductSDto()
{
PersianName = p43.PersianName,
Slug = p43.Slug,
EnglishName = p43.EnglishName,
Summery = p43.Summery,
ExpertCheck = p43.ExpertCheck,
Tags = p43.Tags,
Warranty = p43.Warranty,
Cost = p43.Cost,
IsEnable = p43.IsEnable,
Stock = p43.Stock,
MaxOrderCount = p43.MaxOrderCount,
BeDisplayed = p43.BeDisplayed,
PackingCost = p43.PackingCost,
Rate = (float)(p43.Rate == 0f ? 4.5d : (double)p43.Rate),
CommentCount = p43.ReviewCount,
Viewed = p43.Viewed,
MainImage = p43.Files.FirstOrDefault<ProductStorageFile>(f => f.IsPrimary) != null ? p43.Files.FirstOrDefault<ProductStorageFile>(f => f.IsPrimary).FileLocation : (p43.Files.Count > 0 ? p43.Files.FirstOrDefault<ProductStorageFile>().FileLocation : string.Empty),
CategoryId = p43.CategoryId,
BrandId = p43.BrandId,
BrandName = p43.Brand == null ? null : p43.Brand.PersianName,
CategoryName = p43.Category == null ? null : p43.Category.Name,
ModifiedAt = p43.ModifiedAt,
AuthorId = p43.AuthorId,
AuthorFullName = p43.Author != null ? p43.Author.FirstName + " " + p43.Author.LastName : string.Empty,
Id = p43.Id,
CreatedAt = p43.CreatedAt
};
public static Expression<Func<Product, TorobProductResponseDto>> ProjectToTorobResponseDto => p44 => new TorobProductResponseDto()
{
product_id = p44.Id.ToString(),
price = p44.Cost,
availibility = p44.IsEnable
};
private static List<Specification> funcMain1(List<SpecificationSDto> p2)
{
if (p2 == null)
{
return null;
}
List<Specification> result = new List<Specification>(p2.Count);
int i = 0;
int len = p2.Count;
while (i < len)
{
SpecificationSDto item = p2[i];
result.Add(item == null ? null : new Specification()
{
Title = item.Title,
Detail = item.Detail,
Value = item.Value,
IsFeature = item.IsFeature,
ProductId = item.ProductId,
ParentId = (Guid?)item.ParentId,
Id = item.Id,
CreatedAt = item.CreatedAt
});
i++;
}
return result;
}
private static List<ProductStorageFile> funcMain2(List<StorageFileSDto> p3)
{
if (p3 == null)
{
return null;
}
List<ProductStorageFile> result = new List<ProductStorageFile>(p3.Count);
int i = 0;
int len = p3.Count;
while (i < len)
{
StorageFileSDto item = p3[i];
result.Add(item == null ? null : new ProductStorageFile()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id,
CreatedAt = item.CreatedAt
});
i++;
}
return result;
}
private static Brand funcMain3(Never p6, Brand p7, ProductLDto p4)
{
Brand result = p7 ?? new Brand();
result.Id = p4.BrandId;
return result;
}
private static ApplicationUser funcMain4(Never p8, ApplicationUser p9, ProductLDto p4)
{
ApplicationUser result = p9 ?? new ApplicationUser();
result.Id = p4.AuthorId;
return result;
}
private static ProductCategory funcMain5(Never p10, ProductCategory p11, ProductLDto p4)
{
ProductCategory result = p11 ?? new ProductCategory();
result.Name = p4.CategoryName;
result.Id = p4.CategoryId;
return result;
}
private static List<Specification> funcMain6(List<SpecificationSDto> p12, List<Specification> p13)
{
if (p12 == null)
{
return null;
}
List<Specification> result = new List<Specification>(p12.Count);
int i = 0;
int len = p12.Count;
while (i < len)
{
SpecificationSDto item = p12[i];
result.Add(item == null ? null : new Specification()
{
Title = item.Title,
Detail = item.Detail,
Value = item.Value,
IsFeature = item.IsFeature,
ProductId = item.ProductId,
ParentId = (Guid?)item.ParentId,
Id = item.Id,
CreatedAt = item.CreatedAt
});
i++;
}
return result;
}
private static List<ProductStorageFile> funcMain7(List<StorageFileSDto> p14, List<ProductStorageFile> p15)
{
if (p14 == null)
{
return null;
}
List<ProductStorageFile> result = new List<ProductStorageFile>(p14.Count);
int i = 0;
int len = p14.Count;
while (i < len)
{
StorageFileSDto item = p14[i];
result.Add(item == null ? null : new ProductStorageFile()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id,
CreatedAt = item.CreatedAt
});
i++;
}
return result;
}
private static List<SpecificationSDto> funcMain8(List<Specification> p20)
{
if (p20 == null)
{
return null;
}
List<SpecificationSDto> result = new List<SpecificationSDto>(p20.Count);
int i = 0;
int len = p20.Count;
while (i < len)
{
Specification item = p20[i];
result.Add(item == null ? null : new SpecificationSDto()
{
Title = item.Title,
Detail = item.Detail,
Value = item.Value,
IsFeature = item.IsFeature,
ProductId = item.ProductId,
ParentId = item.ParentId == null ? default(Guid) : (Guid)item.ParentId,
Id = item.Id,
CreatedAt = item.CreatedAt
});
i++;
}
return result;
}
private static List<StorageFileSDto> funcMain9(List<ProductStorageFile> p21)
{
if (p21 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p21.Count);
int i = 0;
int len = p21.Count;
while (i < len)
{
ProductStorageFile item = p21[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static List<SpecificationSDto> funcMain10(List<Specification> p24, List<SpecificationSDto> p25)
{
if (p24 == null)
{
return null;
}
List<SpecificationSDto> result = new List<SpecificationSDto>(p24.Count);
int i = 0;
int len = p24.Count;
while (i < len)
{
Specification item = p24[i];
result.Add(item == null ? null : new SpecificationSDto()
{
Title = item.Title,
Detail = item.Detail,
Value = item.Value,
IsFeature = item.IsFeature,
ProductId = item.ProductId,
ParentId = item.ParentId == null ? default(Guid) : (Guid)item.ParentId,
Id = item.Id,
CreatedAt = item.CreatedAt
});
i++;
}
return result;
}
private static List<StorageFileSDto> funcMain11(List<ProductStorageFile> p26, List<StorageFileSDto> p27)
{
if (p26 == null)
{
return null;
}
List<StorageFileSDto> result = new List<StorageFileSDto>(p26.Count);
int i = 0;
int len = p26.Count;
while (i < len)
{
ProductStorageFile item = p26[i];
result.Add(item == null ? null : new StorageFileSDto()
{
Name = item.Name,
FileLocation = item.FileLocation,
FileName = item.FileName,
IsHeader = item.IsHeader,
IsPrimary = item.IsPrimary,
FileType = item.FileType,
Id = item.Id
});
i++;
}
return result;
}
private static Brand funcMain12(Never p34, Brand p35, ProductSDto p32)
{
Brand result = p35 ?? new Brand();
result.Id = p32.BrandId;
return result;
}
private static ApplicationUser funcMain13(Never p36, ApplicationUser p37, ProductSDto p32)
{
ApplicationUser result = p37 ?? new ApplicationUser();
result.Id = p32.AuthorId;
return result;
}
private static ProductCategory funcMain14(Never p38, ProductCategory p39, ProductSDto p32)
{
ProductCategory result = p39 ?? new ProductCategory();
result.Name = p32.CategoryName;
result.Id = p32.CategoryId;
return result;
}
private static bool funcMain15(ProductStorageFile f)
{
return f.IsPrimary;
}
private static bool funcMain16(ProductStorageFile f)
{
return f.IsPrimary;
}
}
}