< Summary

Information
Class: OzonOrdersWeb.Authorization.OrderListFieldSync
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Authorization/OrderListFieldSync.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 26
Coverable lines: 26
Total lines: 54
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 10
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
EnsureInDatabaseAsync()0%110100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Authorization/OrderListFieldSync.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using OzonDomains.Models.Authorization;
 3using OzonDomains.Models.Authorization.Enums;
 4using OzonOrdersWeb.Areas.Admin.OrderList;
 5using OzonRepositories.Context;
 6
 7namespace OzonOrdersWeb.Authorization;
 8
 9/// <summary>
 10/// Добавляет/обновляет <see cref="AppField"/> для сущности <see cref="OrderListColumnCatalog.EntityName"/>
 11/// строго по реестру колонок главной таблицы заказов.
 12/// </summary>
 13public static class OrderListFieldSync
 14{
 15    public static async Task<int> EnsureInDatabaseAsync(ApplicationDbContext db, CancellationToken ct = default)
 16    {
 017        var existing = await db.AppFields
 018            .Where(f => f.EntityName == OrderListColumnCatalog.EntityName)
 019            .ToListAsync(ct);
 020        var byName = existing.ToDictionary(f => f.FieldName, StringComparer.OrdinalIgnoreCase);
 21
 022        var n = 0;
 023        foreach (var col in OrderListColumnCatalog.All)
 24        {
 025            if (byName.TryGetValue(col.FieldName, out var f))
 26            {
 027                if (f.DisplayName != col.DisplayName || f.SortOrder != col.SortOrder)
 28                {
 029                    f.DisplayName = col.DisplayName;
 030                    f.SortOrder = col.SortOrder;
 031                    f.IsActive = true;
 032                    f.UpdatedAt = DateTime.UtcNow;
 033                    n++;
 34                }
 35            }
 36            else
 37            {
 038                db.AppFields.Add(new AppField
 039                {
 040                    EntityName = OrderListColumnCatalog.EntityName,
 041                    FieldName = col.FieldName,
 042                    DisplayName = col.DisplayName,
 043                    FieldType = FieldType.FormField,
 044                    SortOrder = col.SortOrder,
 045                    IsActive = true,
 046                });
 047                n++;
 48            }
 49        }
 50
 051        if (n > 0) await db.SaveChangesAsync(ct);
 052        return n;
 053    }
 54}

Methods/Properties

EnsureInDatabaseAsync()