0
0
MyDarling/Pages/Feed.xml.cshtml

42 lines
1.5 KiB
Plaintext
Raw Normal View History

2024-01-29 14:34:51 +03:00
@page "/feed.yml"
@using Microsoft.AspNetCore.Http
@using Microsoft.EntityFrameworkCore
@inject MyDarling.Models.DataContext context
@{
var p =
new { Url = "https://mydarlingunderwear.ru/", LastUpdated = DateTime.Today };
Response.ContentType = "text/xml";
var products = context.Products
.Include(b => b.Figures)
.Where(b => b.Price != 0 && b.Figures.Count > 0);
await Response.WriteAsync("<?xml version='1.0' encoding='UTF-8' ?>");
var updateDate = p.LastUpdated.ToString("yyyy-MM-dd");
}
<yml_catalog date="@updateDate">
<shop>
<name>My Darling Underwear</name>
<company>Екатерина Мануйлова</company>
<url>@p.Url</url>
<currencies>
<currency id="RUB" rate="1"></currency>
</currencies>
<categories>
<category id="1">Нижнее бельё</category>
</categories>
<offers>
@foreach (var product in products)
{
var figureUrl = $"{@p.Url}Content/{@product.Id}/{@product.Figures[0].Id}.jpg";
<offer id="@product.Id" available="true">
<url>@p.Url#@product.Id-1</url>
<price>@product.Price</price>
<currencyId>RUR</currencyId>
<categoryId>1</categoryId>
<name>@product.Name</name>
<picture>@figureUrl</picture>
</offer>
}
</offers>
</shop>
</yml_catalog>