summaryrefslogtreecommitdiff
path: root/Pages/Feed.xml.cshtml
blob: c17981f631cdc8aebc0b9cf9a8c384c6a06708c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@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>