< Summary

Information
Class: OzonOrdersWeb.Areas.Studio2.Controllers.Admin.DataScopeSetsController
Assembly: OzonOrdersWeb
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/Admin/DataScopeSetsController.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 75
Coverable lines: 75
Total lines: 164
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%
Details()0%2040%
Create()100%210%
Create()0%620%
Edit()0%2040%
Edit()0%2040%
Delete()0%2040%
DeleteConfirmed()0%620%
AddItem()0%620%
RemoveItem()0%620%
LoadReferenceLists()0%7280%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonOrdersWeb/Areas/Studio2/Controllers/Admin/DataScopeSetsController.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authorization;
 2using Microsoft.AspNetCore.Mvc;
 3using Microsoft.EntityFrameworkCore;
 4using OzonDomains.Models.AccessControl;
 5using OzonRepositories.Context;
 6
 7namespace OzonOrdersWeb.Areas.Studio2.Controllers.Admin;
 8
 9[Authorize(Roles = "Admin")]
 10[Area("Studio2")]
 11public class DataScopeSetsController : Controller
 12{
 13    private readonly ApplicationDbContext _context;
 14
 015    public DataScopeSetsController(ApplicationDbContext context)
 16    {
 017        _context = context;
 018    }
 19
 20    // GET: DataScopeSets
 21    public async Task<IActionResult> Index()
 22    {
 023        var sets = await _context.DataScopeSets
 024            .Include(s => s.Items)
 025            .ToListAsync();
 026        return View(sets);
 027    }
 28
 29    // GET: DataScopeSets/Details/5
 30    public async Task<IActionResult> Details(int? id)
 31    {
 032        if (id == null) return NotFound();
 33
 034        var set = await _context.DataScopeSets
 035            .Include(s => s.Items)
 036            .Include(s => s.AccessProfiles)
 037            .AsSplitQuery()
 038            .FirstOrDefaultAsync(s => s.Id == id);
 39
 040        if (set == null) return NotFound();
 41
 042        await LoadReferenceLists();
 043        return View(set);
 044    }
 45
 46    // GET: DataScopeSets/Create
 47    public IActionResult Create()
 48    {
 049        return View(new DataScopeSet());
 50    }
 51
 52    // POST: DataScopeSets/Create
 53    [HttpPost]
 54    [ValidateAntiForgeryToken]
 55    public async Task<IActionResult> Create([Bind("Name,Description")] DataScopeSet set)
 56    {
 057        if (ModelState.IsValid)
 58        {
 059            set.CreatedAt = DateTime.UtcNow;
 060            _context.DataScopeSets.Add(set);
 061            await _context.SaveChangesAsync();
 062            return RedirectToAction(nameof(Details), new { id = set.Id });
 63        }
 064        return View(set);
 065    }
 66
 67    // GET: DataScopeSets/Edit/5
 68    public async Task<IActionResult> Edit(int? id)
 69    {
 070        if (id == null) return NotFound();
 71
 072        var set = await _context.DataScopeSets.FindAsync(id);
 073        if (set == null) return NotFound();
 74
 075        return View(set);
 076    }
 77
 78    // POST: DataScopeSets/Edit/5
 79    [HttpPost]
 80    [ValidateAntiForgeryToken]
 81    public async Task<IActionResult> Edit(int id, [Bind("Id,Name,Description,CreatedAt")] DataScopeSet set)
 82    {
 083        if (id != set.Id) return NotFound();
 84
 085        if (ModelState.IsValid)
 86        {
 087            _context.Update(set);
 088            await _context.SaveChangesAsync();
 089            return RedirectToAction(nameof(Index));
 90        }
 091        return View(set);
 092    }
 93
 94    // GET: DataScopeSets/Delete/5
 95    public async Task<IActionResult> Delete(int? id)
 96    {
 097        if (id == null) return NotFound();
 98
 099        var set = await _context.DataScopeSets
 0100            .Include(s => s.Items)
 0101            .FirstOrDefaultAsync(s => s.Id == id);
 102
 0103        if (set == null) return NotFound();
 104
 0105        return View(set);
 0106    }
 107
 108    // POST: DataScopeSets/Delete/5
 109    [HttpPost, ActionName("Delete")]
 110    [ValidateAntiForgeryToken]
 111    public async Task<IActionResult> DeleteConfirmed(int id)
 112    {
 0113        var set = await _context.DataScopeSets.FindAsync(id);
 0114        if (set != null)
 115        {
 0116            _context.DataScopeSets.Remove(set);
 0117            await _context.SaveChangesAsync();
 118        }
 0119        return RedirectToAction(nameof(Index));
 0120    }
 121
 122    // POST: DataScopeSets/AddItem
 123    [HttpPost]
 124    [ValidateAntiForgeryToken]
 125    public async Task<IActionResult> AddItem(int setId, DataScopeType scopeType, int referenceId)
 126    {
 0127        var set = await _context.DataScopeSets.FindAsync(setId);
 0128        if (set == null) return NotFound();
 129
 0130        var item = new DataScopeSetItem
 0131        {
 0132            DataScopeSetId = setId,
 0133            ScopeType = scopeType,
 0134            ReferenceId = referenceId
 0135        };
 0136        _context.DataScopeSetItems.Add(item);
 0137        await _context.SaveChangesAsync();
 138
 0139        return RedirectToAction(nameof(Details), new { id = setId });
 0140    }
 141
 142    // POST: DataScopeSets/RemoveItem/5
 143    [HttpPost]
 144    [ValidateAntiForgeryToken]
 145    public async Task<IActionResult> RemoveItem(int itemId, int setId)
 146    {
 0147        var item = await _context.DataScopeSetItems.FindAsync(itemId);
 0148        if (item != null)
 149        {
 0150            _context.DataScopeSetItems.Remove(item);
 0151            await _context.SaveChangesAsync();
 152        }
 0153        return RedirectToAction(nameof(Details), new { id = setId });
 0154    }
 155
 156    private async Task LoadReferenceLists()
 157    {
 0158        ViewBag.AppStatuses = await _context.AppStatuses.ToListAsync();
 0159        ViewBag.Suppliers = await _context.Suppliers.ToListAsync();
 0160        ViewBag.OzonClients = await _context.OzonClients.ToListAsync();
 0161        ViewBag.Warehouses = await _context.Warehouses.ToListAsync();
 0162        ViewBag.DeliveryProviders = await _context.DeliveryProviders.ToListAsync();
 0163    }
 164}