< Summary

Information
Class: OzonOrdersWeb.Areas.Studio2.Controllers.Directories.SupplierStatusController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/Directories/SupplierStatusController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 53
Coverable lines: 53
Total lines: 115
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Index()100%210%
Update()100%210%
UpdateStatusColor()100%210%
ResetStatusColor()100%210%
Delete()0%620%
DescribeKind(...)0%2040%
DescribeProvider(...)0%110100%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/Directories/SupplierStatusController.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using OzonDomains.Models;
 4using OzonDomains.Models.SupplierStatuses;
 5using Services.CacheServices.Cache;
 6using Services.CacheServices.Cache.OzonOrdersCache;
 7using Services.SupplierStatusServices;
 8
 9namespace OzonOrdersWeb.Areas.Studio2.Controllers.Directories;
 10
 11/// <summary>
 12/// Справочник статусов API-поставщиков. Записи создаются автоматически при первой встрече
 13/// статуса, здесь администратор задаёт им цвет, отображаемое имя и признак конечного статуса.
 14/// </summary>
 15[Area("Studio2")]
 16[Authorize(Roles = "Admin")]
 17public class SupplierStatusController : Controller
 18{
 19    private readonly ISupplierStatusDirectoryService _directory;
 20    private readonly ISupplierStatusResolver _resolver;
 21    private readonly OrderCache _cache;
 22    private readonly CacheUpdater<Order> _cacheUpdater;
 23
 024    public SupplierStatusController(
 025        ISupplierStatusDirectoryService directory,
 026        ISupplierStatusResolver resolver,
 027        OrderCache cache,
 028        CacheUpdater<Order> cacheUpdater)
 29    {
 030        _directory = directory;
 031        _resolver = resolver;
 032        _cache = cache;
 033        _cacheUpdater = cacheUpdater;
 034    }
 35
 36    /// <summary>Весь справочник: поставщик, стадия и прочие срезы — фильтры грида AG Grid на клиенте.</summary>
 37    public async Task<IActionResult> Index(CancellationToken ct)
 38    {
 039        var statuses = await _directory.GetAsync(null, null, ct);
 040        return View(statuses);
 041    }
 42
 43    [HttpPost, ValidateAntiForgeryToken]
 44    public async Task<IActionResult> Update(
 45        int id, string name, bool isFinal, int? sortOrder, CancellationToken ct)
 46    {
 047        await _directory.UpdateAsync(id, name, isFinal, sortOrder, ct);
 048        _resolver.InvalidateCache();
 049        await _cacheUpdater.Update(_cache);
 50        // Срез (фильтры грида) восстанавливается из последнего вида пользователя.
 051        return RedirectToAction(nameof(Index));
 052    }
 53
 54    [HttpPost, ValidateAntiForgeryToken]
 55    public async Task<IActionResult> UpdateStatusColor(int statusId, string colorCode, CancellationToken ct)
 56    {
 57        try
 58        {
 059            await _directory.UpdateStatusColorAsync(statusId, colorCode, ct);
 060            await _cacheUpdater.Update(_cache);
 061            return Json(new { success = true });
 62        }
 063        catch (Exception ex)
 64        {
 065            return Json(new { success = false, error = ex.Message });
 66        }
 067    }
 68
 69    [HttpPost, ValidateAntiForgeryToken]
 70    public async Task<IActionResult> ResetStatusColor(int statusId, CancellationToken ct)
 71    {
 72        try
 73        {
 074            await _directory.ResetStatusColorAsync(statusId, ct);
 075            await _cacheUpdater.Update(_cache);
 076            return Json(new { success = true });
 77        }
 078        catch (Exception ex)
 79        {
 080            return Json(new { success = false, error = ex.Message });
 81        }
 082    }
 83
 84    [HttpPost, ValidateAntiForgeryToken]
 85    public async Task<IActionResult> Delete(int id, CancellationToken ct)
 86    {
 087        var status = await _directory.GetByIdAsync(id, ct);
 088        if (status is null) return NotFound();
 89
 090        await _directory.DeleteAsync(id, ct);
 091        _resolver.InvalidateCache();
 092        await _cacheUpdater.Update(_cache);
 093        TempData["SupplierStatusMessage"] = $"Статус «{status.Name}» удалён. При следующем опросе поставщика он создастс
 094        return RedirectToAction(nameof(Index));
 095    }
 96
 97    /// <summary>Человекочитаемое название стадии для интерфейса.</summary>
 098    public static string DescribeKind(string statusKind) => statusKind switch
 099    {
 0100        SupplierStatusKind.Cart => "Корзина",
 0101        SupplierStatusKind.Order => "Заказ",
 0102        _ => statusKind
 0103    };
 104
 105    /// <summary>Название поставщика по ключу провайдера — для фильтра и таблицы.</summary>
 0106    public static string DescribeProvider(string providerKey) => providerKey switch
 0107    {
 0108        ApiSupplierSettings.AvdProviderKey => "АВД",
 0109        ApiSupplierSettings.ArmtekProviderKey => "Армтек RU",
 0110        ApiSupplierSettings.ArmtekByProviderKey => "Армтек BY",
 0111        ApiSupplierSettings.MlAutoProviderKey => "ML-Auto BY",
 0112        ApiSupplierSettings.MlAutoRuProviderKey => "ML-Auto RU",
 0113        _ => providerKey
 0114    };
 115}