using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using MapsDb; using MapsDb.Interfaces; using MapsDb.DataService; using MapsModels.ViewModels; using MapsModels.DsModels; using System; namespace Maps.Controllers { public class AuthorityController : Controller { private readonly IAuthorityDs _authorityDs; private readonly IRoadDs _roadDs; private readonly ICrossSectionDs _crossSectionDs; public AuthorityController(IAuthorityDs AuthorityDs, IRoadDs RoadDs, ICrossSectionDs CrossSectionDs, IRegionDs RegionDs) { _authorityDs = AuthorityDs; _roadDs = RoadDs; _crossSectionDs = CrossSectionDs; } // GET: Authority [HttpGet] public async Task Index([FromQuery] PaginationDsM data) { var authoritys = await _authorityDs.GetIndexListAsync(data); AuthorityListVm vm = new AuthorityListVm { AuthorityEditDsM = authoritys.ToList() }; return Json(vm); } [HttpGet] public async Task Directory(){ var Road = await _roadDs.GetSelectListAsync(); var CrossSection = await _crossSectionDs.GetSelectListAsync(); CatalogListVm vm = new CatalogListVm { RoadSelectListDsM = Road.ToList(), CrossSectionSelectListDsM = CrossSection.ToList(), }; return Json(vm); } [HttpPost] public async Task Create([FromBody] AuthorityEditDsM data) { var result = await _authorityDs.CreateAsync(data); return Json(result); } [HttpPost] public async Task Update(int id, [FromBody] AuthorityEditDsM data){ await _authorityDs.UpdateAsync(data,id); return Json(String.Empty); } [HttpDelete] public async Task Delete(int id) { try { int authority = await _authorityDs.DeleteAsync(id); return Json(authority); } catch (ArgumentNullException ) { return NotFound(); } } } }