add order deliver at

release
Amir Hossein Khademi 2024-03-01 16:07:11 +03:30
parent 72e3e072ff
commit 9dc05cc8bc
18 changed files with 2106 additions and 114 deletions

View File

@ -24,6 +24,9 @@ public class OrderController : ICarterModule
group.MapDelete("{id}", DeleteAsync)
.WithDisplayName("DeleteOneOrder")
.HasApiVersion(1.0);
group.MapGet("{id}/invoice", GetOrderInvoiceAsync)
.WithDisplayName("GetOrderInvoice")
.HasApiVersion(1.0);
}
@ -39,6 +42,15 @@ public class OrderController : ICarterModule
return TypedResults.Ok(order);
}
public async Task<IResult> DeleteAsync(IMediator mediator, Guid id, CancellationToken cancellationToken = default)
=> TypedResults.Ok(await mediator.Send(new DeleteOrderCommand(id), cancellationToken));
private async Task<IResult> GetOrderInvoiceAsync([FromRoute] Guid id, [FromServices] IMediator mediator, CancellationToken cancellationToken)
{
var file = await mediator.Send(new GetOrderInvoiceCommand(id), cancellationToken);
string fileName = $"Invoice_{id}.pdf";
return TypedResults.File(file, "application/pdf", fileName);
}
}

View File

@ -2,6 +2,7 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
@ -19,6 +20,11 @@ ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./NetinaShop.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
RUN apt-get update
RUN apt-get install-y libgdiplus
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "NetinaShop.Api.dll"]

View File

@ -134,6 +134,7 @@
<ItemGroup>
<Folder Include="wwwroot\assets\vendor\bootstrap\css\" />
<Folder Include="wwwroot\fonts\" />
</ItemGroup>
</Project>

View File

@ -1,4 +1,8 @@
using Autofac.Core;
using DinkToPdf.Contracts;
using DinkToPdf;
using NetinaShop.Repository.Behaviors;
using QuestPDF.Infrastructure;
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
@ -40,6 +44,8 @@ builder.Services.AddCustomIdentity();
builder.Services.AddCustomDbContext(configuration);
builder.Services.AddMarten(configuration,builder.Environment);
builder.Services.AddCarter();
builder.Services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
QuestPDF.Settings.License = LicenseType.Community;
builder.Host.ConfigureContainer<ContainerBuilder>(builder =>

View File

@ -0,0 +1,5 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,128 @@
using DinkToPdf;
using DinkToPdf.Contracts;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
using Unit = QuestPDF.Infrastructure.Unit;
namespace NetinaShop.Core.EntityServices.OrderHandlers;
public class GetOrderInvoiceCommandHandler : IRequestHandler<GetOrderInvoiceCommand, byte[]>
{
private readonly IRepositoryWrapper _repositoryWrapper;
private readonly IMediator _mediator;
private readonly IConverter _converter;
public GetOrderInvoiceCommandHandler(IRepositoryWrapper repositoryWrapper,IMediator mediator,IConverter converter)
{
_repositoryWrapper = repositoryWrapper;
_mediator = mediator;
_converter = converter;
}
public async Task<byte[]> Handle(GetOrderInvoiceCommand request, CancellationToken cancellationToken)
{
var orderLDto = await _mediator.Send(new GetOrderLDtoQuery(request.OrderId), cancellationToken);
//var textStyleWithFallback = TextStyle
// .Default
// .FontSize(18)
// .Fallback(y => y
// .FontFamily(Fonts.Arial)
// .SemiBold()
// .Underline(false)
// .BackgroundColor(Colors.Red.Lighten4));
//var pdf = Document.Create(container =>
//{
// container.Page(page =>
// {
// page.Size(PageSizes.A4);
// page.Margin(2,Unit.Centimetre);
// page.PageColor(Colors.White);
// page.DefaultTextStyle(x=>x.FontSize(14));
// page.Header()
// .Text(text =>
// {
// text.DefaultTextStyle(textStyleWithFallback);
// text.Line("This is normal text.");
// text.EmptyLine();
// text.Line("Following line should use font fallback:");
// text.Line("中文文本");
// text.EmptyLine();
// text.Line("The following line contains a mix of known and unknown characters.");
// text.Line("Mixed line: This 中文 is 文文 a mixed 本 本 line 本 中文文本!");
// text.EmptyLine();
// text.Span("Emojis work out of the box because of font fallback: 😊😅🥳👍❤😍👌");
// });
// page.Content()
// .ContentFromRightToLeft()
// .Column(x =>
// {
// x.Spacing(20);
// x.Item().Text("فاکتور فروش ");
// });
// });
//}).GeneratePdf();
var sb = new StringBuilder();
sb.Append(@"
<html>
<head>
</head>
<body>
<div class='header'><h1>فاکتور فروش</h1></div>
<table align='center'>
<tr>
<th>Name</th>
<th>LastName</th>
<th>Age</th>
<th>Gender</th>
</tr>");
foreach (var emp in orderLDto.OrderProducts)
{
sb.AppendFormat(@"<tr>
<td>{0}</td>
<td>{1}</td>
<td>{2}</td>
<td>{3}</td>
</tr>", emp.ProductName, emp.Count, emp.ProductFee, emp.ProductCost);
}
sb.Append(@"
</table>
</body>
</html>");
var globalSettings = new GlobalSettings
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings { Top = 10 },
DocumentTitle = "PDF Report",
Out = @"D:\PDFCreator\Employee_Report.pdf"
};
var objectSettings = new ObjectSettings
{
PagesCount = true,
HtmlContent = sb.ToString(),
WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
};
var pdf = new HtmlToPdfDocument()
{
GlobalSettings = globalSettings,
Objects = { objectSettings }
};
var file = _converter.Convert(pdf);
return file;
}
}

View File

@ -11,9 +11,13 @@
<PackageReference Include="AspNetCoreRateLimit" Version="5.0.0" />
<PackageReference Include="AspNetCoreRateLimit.Redis" Version="2.0.0" />
<PackageReference Include="Autofac.Extras.Quartz" Version="9.0.0" />
<PackageReference Include="DinkToPdf" Version="1.0.8" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="QuestPDF" Version="2023.12.6" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="Quartz" Version="3.8.0" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.7" />
</ItemGroup>

View File

@ -5,4 +5,5 @@ public sealed record CreateBaseOrderCommand(Guid UserId) : IRequest<Order>;
public sealed record CalculateOrderCommand(Guid OrderId , bool NamoosiCalculate = false) : IRequest<Order>;
public sealed record ConfirmOrderStepCommand(Guid OrderId , OrderStatus NextOrderStatus) : IRequest<bool>;
public sealed record GetOrderInvoiceCommand(Guid OrderId) : IRequest<byte[]>;
public sealed record DeleteOrderCommand(Guid OrderId) : IRequest<bool>;

View File

@ -27,6 +27,6 @@ public class OrderLDto : BaseDto<OrderLDto,Order>
public List<PaymentSDto> Payments { get; set; } = new();
public OrderDeliverySDto? OrderDelivery { get; internal set; }
public OrderDeliverySDto OrderDelivery { get; set; } = new();
}

View File

@ -189,7 +189,15 @@ namespace NetinaShop.Domain.Mappers
Payments = funcMain10(p21.Payments),
OrderDelivery = p21.OrderDelivery == null ? null : new OrderDeliverySDto()
{
Address = p21.OrderDelivery.Address == null ? null : p21.OrderDelivery.Address.ToString(),
Province = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.Province : string.Empty,
City = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.City : string.Empty,
Plaque = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.Plaque : string.Empty,
LocationLat = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.LocationLat : 0f,
LocationLong = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.LocationLong : 0f,
Address = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.Address : string.Empty,
PostalCode = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.PostalCode : string.Empty,
ReceiverPhoneNumber = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.ReceiverPhoneNumber : string.Empty,
ReceiverFullName = p21.OrderDelivery.Address != null ? p21.OrderDelivery.Address.ReceiverFullName : string.Empty,
ShippingMethod = p21.OrderDelivery.Shipping != null ? p21.OrderDelivery.Shipping.Name : string.Empty,
DeliveryCost = p21.OrderDelivery.DeliveryCost,
AddressId = p21.OrderDelivery.AddressId,
@ -291,7 +299,15 @@ namespace NetinaShop.Domain.Mappers
}).ToList<PaymentSDto>(),
OrderDelivery = p32.OrderDelivery == null ? null : new OrderDeliverySDto()
{
Address = p32.OrderDelivery.Address == null ? null : p32.OrderDelivery.Address.ToString(),
Province = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.Province : string.Empty,
City = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.City : string.Empty,
Plaque = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.Plaque : string.Empty,
LocationLat = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.LocationLat : 0f,
LocationLong = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.LocationLong : 0f,
Address = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.Address : string.Empty,
PostalCode = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.PostalCode : string.Empty,
ReceiverPhoneNumber = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.ReceiverPhoneNumber : string.Empty,
ReceiverFullName = p32.OrderDelivery.Address != null ? p32.OrderDelivery.Address.ReceiverFullName : string.Empty,
ShippingMethod = p32.OrderDelivery.Shipping != null ? p32.OrderDelivery.Shipping.Name : string.Empty,
DeliveryCost = p32.OrderDelivery.DeliveryCost,
AddressId = p32.OrderDelivery.AddressId,
@ -801,7 +817,15 @@ namespace NetinaShop.Domain.Mappers
}
OrderDeliverySDto result = p31 ?? new OrderDeliverySDto();
result.Address = p30.Address == null ? null : p30.Address.ToString();
result.Province = p30.Address != null ? p30.Address.Province : string.Empty;
result.City = p30.Address != null ? p30.Address.City : string.Empty;
result.Plaque = p30.Address != null ? p30.Address.Plaque : string.Empty;
result.LocationLat = p30.Address != null ? p30.Address.LocationLat : 0f;
result.LocationLong = p30.Address != null ? p30.Address.LocationLong : 0f;
result.Address = p30.Address != null ? p30.Address.Address : string.Empty;
result.PostalCode = p30.Address != null ? p30.Address.PostalCode : string.Empty;
result.ReceiverPhoneNumber = p30.Address != null ? p30.Address.ReceiverPhoneNumber : string.Empty;
result.ReceiverFullName = p30.Address != null ? p30.Address.ReceiverFullName : string.Empty;
result.ShippingMethod = p30.Shipping != null ? p30.Shipping.Name : string.Empty;
result.DeliveryCost = p30.DeliveryCost;
result.AddressId = p30.AddressId;

View File

@ -51,6 +51,20 @@ public class MapsterRegister : IRegister
.IgnoreNullValues(false)
.TwoWays();
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();
config.NewConfig<Payment, PaymentSDto>()
.Map("UserFullName", o => o.User != null ? o.User.FirstName + " " + o.User.LastName : string.Empty)
.Map("UserPhoneNumber", o => o.User != null ? o.User.PhoneNumber : string.Empty)

View File

@ -16,8 +16,7 @@ public class GetOrdersQueryHandler : IRequestHandler<GetOrdersQuery,List<OrderSD
IQueryable<Order> orders = _repositoryWrapper
.SetRepository<Order>()
.TableNoTracking
.Where(o=>o.OrderStatus != OrderStatus.OrderBag);
.TableNoTracking;
if (request.DateFilter != null)
{

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,32 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace NetinaShop.Repository.Migrations
{
/// <inheritdoc />
public partial class EditOrderAddDeliverAt : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "DeliveredAt",
schema: "public",
table: "Orders",
type: "timestamp without time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DeliveredAt",
schema: "public",
table: "Orders");
}
}
}

View File

@ -463,6 +463,9 @@ namespace NetinaShop.Repository.Migrations
b.Property<string>("CreatedBy")
.HasColumnType("text");
b.Property<DateTime>("DeliveredAt")
.HasColumnType("timestamp without time zone");
b.Property<double>("DeliveryPrice")
.HasColumnType("double precision");

View File

@ -9,124 +9,126 @@ using Newtonsoft.Json;
Console.ReadKey();
try
{
var termReader = new StreamReader("F:\\wp_terms.json");
var termJson = termReader.ReadToEnd();
Console.WriteLine("Terms File Read Success !");
var terms = JsonConvert.DeserializeObject<List<WordPressTermDto>>(termJson);
if (terms == null)
throw new Exception("Terms is null");
var termTaxonomyReader = new StreamReader("F:\\wp_term_taxonomy.json");
var termTaxonomyJson = termTaxonomyReader.ReadToEnd();
Console.WriteLine("Term Taxonomy File Read Success !");
var termTaxonomies = JsonConvert.DeserializeObject<List<WordPressTermTaxonomyDto>>(termTaxonomyJson);
if (termTaxonomies == null)
throw new Exception("Term Taxonomies is null");
var termRelationshipsReader = new StreamReader("F:\\wp_term_relationships.json");
var termRelationshipsJson = termRelationshipsReader.ReadToEnd();
Console.WriteLine("Term Relationships File Read Success !");
var termRelationships = JsonConvert.DeserializeObject<List<WordPressTermRelationDto>>(termRelationshipsJson);
if (termRelationships == null)
throw new Exception("Term Relationships is null");
//try
//{
// var termReader = new StreamReader("F:\\wp_terms.json");
// var termJson = termReader.ReadToEnd();
// Console.WriteLine("Terms File Read Success !");
// var terms = JsonConvert.DeserializeObject<List<WordPressTermDto>>(termJson);
// if (terms == null)
// throw new Exception("Terms is null");
var postReader = new StreamReader("F:\\wp_posts.json");
var json = postReader.ReadToEnd();
Console.WriteLine("Post File Read Success !");
var posts = JsonConvert.DeserializeObject<List<WordPressPostDto>>(json);
if (posts == null)
throw new Exception("Posts is null");
// var termTaxonomyReader = new StreamReader("F:\\wp_term_taxonomy.json");
// var termTaxonomyJson = termTaxonomyReader.ReadToEnd();
// Console.WriteLine("Term Taxonomy File Read Success !");
// var termTaxonomies = JsonConvert.DeserializeObject<List<WordPressTermTaxonomyDto>>(termTaxonomyJson);
// if (termTaxonomies == null)
// throw new Exception("Term Taxonomies is null");
var metaReader = new StreamReader("F:\\wp_postmeta.json");
var metaJson = metaReader.ReadToEnd();
Console.WriteLine("Post Metas File Read Success !");
var postMetas = JsonConvert.DeserializeObject<List<WordPressPostMetaDto>>(metaJson);
if (postMetas == null)
throw new Exception("Post Metas is null");
// var termRelationshipsReader = new StreamReader("F:\\wp_term_relationships.json");
// var termRelationshipsJson = termRelationshipsReader.ReadToEnd();
// Console.WriteLine("Term Relationships File Read Success !");
// var termRelationships = JsonConvert.DeserializeObject<List<WordPressTermRelationDto>>(termRelationshipsJson);
// if (termRelationships == null)
// throw new Exception("Term Relationships is null");
//CREATE CATEGORY PART
List<SeedCategoryRequestDto> categories = new List<SeedCategoryRequestDto>();
foreach (var taxonomy in termTaxonomies)
{
if (taxonomy.taxonomy == "product_cat")
{
var term = terms.FirstOrDefault(t => t.term_id == taxonomy.term_id);
if (term != null)
categories.Add(new SeedCategoryRequestDto
{ BaseCategoryId = term.term_id.ToInt(), Description = taxonomy.description, Name = term.name });
}
}
// var postReader = new StreamReader("F:\\wp_posts.json");
// var json = postReader.ReadToEnd();
// Console.WriteLine("Post File Read Success !");
// var posts = JsonConvert.DeserializeObject<List<WordPressPostDto>>(json);
// if (posts == null)
// throw new Exception("Posts is null");
var categoriesRest = await RestWrapper.Instance.SeedRestApi.SeedCategoriesAsync(categories,"kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
Console.WriteLine($"{categories.Count} ProductCategory Added Success !");
//CREATE BRAND PART
List<SeedBrandRequestDto> brands = new List<SeedBrandRequestDto>();
foreach (var taxonomy in termTaxonomies)
{
if (taxonomy.taxonomy == "pa_brand")
{
var term = terms.FirstOrDefault(t => t.term_id == taxonomy.term_id);
if (term != null)
brands.Add(new SeedBrandRequestDto{BaseBrandId = term.term_id.ToInt(),Description = taxonomy.description,Name = term.name});
}
}
var brandsRest = await RestWrapper.Instance.SeedRestApi.SeedBrandsAsync(brands, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
// var metaReader = new StreamReader("F:\\wp_postmeta.json");
// var metaJson = metaReader.ReadToEnd();
// Console.WriteLine("Post Metas File Read Success !");
// var postMetas = JsonConvert.DeserializeObject<List<WordPressPostMetaDto>>(metaJson);
// if (postMetas == null)
// throw new Exception("Post Metas is null");
Console.WriteLine($"{brands.Count} Brand Added Success !");
//CREATE PRODUCT PART
List<CreateProductCommand> products = new List<CreateProductCommand>();
foreach (var wordPressPostDto in posts.Where(p => p.post_type == "product"))
{
CreateProductCommand product;
Guid brandId = default;
Guid categoryId = default;
var postTermRelations = termRelationships.Where(p => p.object_id == wordPressPostDto.ID);
foreach (var postTermRelation in postTermRelations)
{
var taxanomy = termTaxonomies.FirstOrDefault(f => f.term_taxonomy_id == postTermRelation.term_taxonomy_id);
if (taxanomy != null)
{
if (taxanomy.taxonomy == "pa_brand")
brandId = brandsRest.FirstOrDefault(f => f.Key == taxanomy.term_id.ToInt()).Value;
if (taxanomy.taxonomy == "product_cat")
categoryId = categoriesRest.FirstOrDefault(c => c.Key == taxanomy.term_id.ToInt()).Value;
}
}
////CREATE CATEGORY PART
// List<SeedCategoryRequestDto> categories = new List<SeedCategoryRequestDto>();
// foreach (var taxonomy in termTaxonomies)
// {
// if (taxonomy.taxonomy == "product_cat")
// {
// var term = terms.FirstOrDefault(t => t.term_id == taxonomy.term_id);
// if (term != null)
// categories.Add(new SeedCategoryRequestDto
// { BaseCategoryId = term.term_id.ToInt(), Description = taxonomy.description, Name = term.name });
// }
// }
if (brandId == default)
brandId = brandsRest.FirstOrDefault(f => f.Key == 0).Value;
if (categoryId == default)
categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
var price = postMetas.FirstOrDefault(pm => pm.post_id == wordPressPostDto.ID && pm.meta_key == "_price");
if (price != null && double.TryParse(price.meta_value, out double dPrice))
product = new CreateProductCommand(wordPressPostDto.post_title, string.Empty, wordPressPostDto.post_content,
wordPressPostDto.post_excerpt, string.Empty, string.Empty, true, dPrice, 0,10,
false,10,false,brandId, categoryId,
new DiscountSDto(),new List<SpecificationSDto>(), new List<StorageFileSDto>());
else
product = new CreateProductCommand(wordPressPostDto.post_title, string.Empty, wordPressPostDto.post_content,
wordPressPostDto.post_excerpt, string.Empty, string.Empty, true, 0, 0,10,false,10,
false,brandId,categoryId,
new DiscountSDto(),new List<SpecificationSDto>(), new List<StorageFileSDto>());
// var categoriesRest = await RestWrapper.Instance.SeedRestApi.SeedCategoriesAsync(categories,"kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
// Console.WriteLine($"{categories.Count} ProductCategory Added Success !");
products.Add(product);
}
// //CREATE BRAND PART
// List<SeedBrandRequestDto> brands = new List<SeedBrandRequestDto>();
// foreach (var taxonomy in termTaxonomies)
// {
// if (taxonomy.taxonomy == "pa_brand")
// {
// var term = terms.FirstOrDefault(t => t.term_id == taxonomy.term_id);
// if (term != null)
// brands.Add(new SeedBrandRequestDto{BaseBrandId = term.term_id.ToInt(),Description = taxonomy.description,Name = term.name});
// }
// }
// var brandsRest = await RestWrapper.Instance.SeedRestApi.SeedBrandsAsync(brands, "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
for (int i = 0; i < products.Count / 50 ; i++)
{
await RestWrapper.Instance.SeedRestApi.SeedProductsAsync(products.Skip(i * 50).Take(50).ToList(),
"kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
// Console.WriteLine($"{brands.Count} Brand Added Success !");
// //CREATE PRODUCT PART
// List<CreateProductCommand> products = new List<CreateProductCommand>();
// foreach (var wordPressPostDto in posts.Where(p => p.post_type == "product"))
// {
// CreateProductCommand product;
// Guid brandId = default;
// Guid categoryId = default;
// var postTermRelations = termRelationships.Where(p => p.object_id == wordPressPostDto.ID);
// foreach (var postTermRelation in postTermRelations)
// {
// var taxanomy = termTaxonomies.FirstOrDefault(f => f.term_taxonomy_id == postTermRelation.term_taxonomy_id);
// if (taxanomy != null)
// {
// if (taxanomy.taxonomy == "pa_brand")
// brandId = brandsRest.FirstOrDefault(f => f.Key == taxanomy.term_id.ToInt()).Value;
// if (taxanomy.taxonomy == "product_cat")
// categoryId = categoriesRest.FirstOrDefault(c => c.Key == taxanomy.term_id.ToInt()).Value;
// }
// }
Console.WriteLine($"{i*50} / {products.Count} Product Added Success !");
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
// if (brandId == default)
// brandId = brandsRest.FirstOrDefault(f => f.Key == 0).Value;
// if (categoryId == default)
// categoryId = categoriesRest.FirstOrDefault(c => c.Key == 0).Value;
// var price = postMetas.FirstOrDefault(pm => pm.post_id == wordPressPostDto.ID && pm.meta_key == "_price");
// if (price != null && double.TryParse(price.meta_value, out double dPrice))
// product = new CreateProductCommand(wordPressPostDto.post_title, string.Empty, wordPressPostDto.post_content,
// wordPressPostDto.post_excerpt, string.Empty, string.Empty, true, dPrice, 0,10,
// false,10,false,brandId, categoryId,
// new DiscountSDto(),new List<SpecificationSDto>(), new List<StorageFileSDto>());
// else
// product = new CreateProductCommand(wordPressPostDto.post_title, string.Empty, wordPressPostDto.post_content,
// wordPressPostDto.post_excerpt, string.Empty, string.Empty, true, 0, 0,10,false,10,
// false,brandId,categoryId,
// new DiscountSDto(),new List<SpecificationSDto>(), new List<StorageFileSDto>());
// products.Add(product);
// }
// for (int i = 0; i < products.Count / 50 ; i++)
// {
// await RestWrapper.Instance.SeedRestApi.SeedProductsAsync(products.Skip(i * 50).Take(50).ToList(),
// "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==");
// Console.WriteLine($"{i*50} / {products.Count} Product Added Success !");
// }
//}
//catch (Exception e)
//{
// Console.WriteLine(e);
// throw;
//}