< Summary

Information
Class: OzonWebApp.Controllers.ExcludedArticlesController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/ExcludedArticlesController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 55
Coverable lines: 55
Total lines: 119
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 32
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%
Create()0%156120%
Create()0%4260%
Edit()0%2040%
Edit()0%4260%
Delete()0%620%
DeleteConfirmed()0%620%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/ExcludedArticlesController.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using OzonDomains.Models;
 4using OzonOrdersWeb.Areas.Studio2.ViewModels.ExcludedArticles;
 5using Services.DataServices;
 6
 7namespace OzonWebApp.Controllers
 8{
 9    [Area("Studio2")]
 10    [Authorize(Roles = "User,Admin")]
 11    public class ExcludedArticlesController : Controller
 12    {
 13        private readonly ExcludedArticleDataServices _excludedArticleService;
 14        private readonly OzonClientServices _ozonClientService;
 15        private readonly OrdersDataServices _ordersService;
 16
 017        public ExcludedArticlesController(
 018            ExcludedArticleDataServices excludedArticleService,
 019            OzonClientServices ozonClientService,
 020            OrdersDataServices ordersService)
 21        {
 022            _excludedArticleService = excludedArticleService;
 023            _ozonClientService = ozonClientService;
 024            _ordersService = ordersService;
 025        }
 26
 27        /// <summary>Весь список исключений для грида AG Grid: фильтры, сортировка и поиск — на клиенте.</summary>
 28        public async Task<IActionResult> Index()
 29        {
 030            return View(await _excludedArticleService.GetExcludedArticles());
 031        }
 32
 33        [HttpGet]
 34        public async Task<IActionResult> Create(int orderId)
 35        {
 036            var clients = await _ozonClientService.GetOzonClients();
 037            ViewBag.OzonClients = clients ?? new List<OzonClient>();
 38
 039            if (orderId != 0)
 40            {
 041                var order = await _ordersService.GetOrder(orderId);
 042                if (order == null)
 043                    return View(new ExcludedArticleViewModel());
 44
 045                return View(new ExcludedArticleViewModel
 046                {
 047                    Article = order.Article ?? string.Empty,
 048                    OzonClientId = order.OzonClient?.Id ?? 0
 049                });
 50            }
 051            return View(new ExcludedArticleViewModel());
 052        }
 53
 54
 55        [HttpPost]
 56        [ValidateAntiForgeryToken]
 57        public async Task<IActionResult> Create(ExcludedArticleViewModel model)
 58        {
 059            if (ModelState.IsValid)
 60            {
 061                var article = new ExcludedArticle
 062                {
 063                    Article = model.Article ?? string.Empty,
 064                    OzonClientId = model.OzonClientId
 065                };
 66
 067                await _excludedArticleService.AddExcludedArticle(article);
 068                return RedirectToAction(nameof(Index));
 69            }
 70
 071            ViewBag.OzonClients = await _ozonClientService.GetOzonClients();
 072            return View(model);
 073        }
 74
 75        public async Task<IActionResult> Edit(int id)
 76        {
 077            var article = await _excludedArticleService.GetExcludedArticleAsync(id);
 078            if (article == null) return NotFound();
 79
 080            ViewBag.OzonClients = await _ozonClientService.GetOzonClients();
 081            return View(article);
 082        }
 83
 84        [HttpPost]
 85        [ValidateAntiForgeryToken]
 86        public async Task<IActionResult> Edit(int id, ExcludedArticle model)
 87        {
 088            if (id != model.Id) return NotFound();
 89
 090            if (ModelState.IsValid)
 91            {
 092                await _excludedArticleService.UpdateExcludedArticle(model);
 093                return RedirectToAction(nameof(Index));
 94            }
 095            ViewBag.OzonClients = await _ozonClientService.GetOzonClients();
 096            return View(model);
 097        }
 98
 99        public async Task<IActionResult> Delete(int id)
 100        {
 0101            var article = await _excludedArticleService.GetExcludedArticleAsync(id);
 0102            if (article == null) return NotFound();
 103
 0104            return View(article);
 0105        }
 106
 107        [HttpPost, ActionName("Delete")]
 108        [ValidateAntiForgeryToken]
 109        public async Task<IActionResult> DeleteConfirmed(int id)
 110        {
 0111            var article = await _excludedArticleService.GetExcludedArticleAsync(id);
 0112            if (article != null)
 113            {
 0114                await _excludedArticleService.DeleteExcludedArticle(article);
 115            }
 0116            return RedirectToAction(nameof(Index));
 0117        }
 118    }
 119}