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 FlowIntensityController : Controller { private readonly IFlowIntensityDs _flowIntensityDs; private readonly IRoadDs _roadDs; private readonly IRegionDs _regionDs; private readonly IRoadDirectionDs _roadDirectionDs; private readonly ISettlementDs _settlementDs; public FlowIntensityController(IFlowIntensityDs FlowIntensityDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDs RegionDs, IRoadDirectionDs RoadDirectionDs) { _flowIntensityDs = FlowIntensityDs; _roadDs = RoadDs; _settlementDs = SettlementDs; _regionDs = RegionDs; _roadDirectionDs = RoadDirectionDs; } // GET: FlowIntensity [HttpGet] public async Task Index([FromQuery] PaginationDsM data) { try { var flowIntensitys = await _flowIntensityDs.GetIndexListAsync(data); FlowIntensityListVm vm = new FlowIntensityListVm { FlowIntensityEditDsM = flowIntensitys.ToList() }; return Json(vm); } catch (NullReferenceException) { Response.StatusCode = 400; return Json("There is no field with name " + data.sort); } catch (Exception) { return NotFound(); } } [HttpGet] public async Task Directory(){ var Settlement = await _settlementDs.GetSelectListAsync(); var Road = await _roadDs.GetSelectListAsync(); var Region = await _regionDs.GetSelectListAsync(); var RoadDirection = await _roadDirectionDs.GetSelectListAsync(); CatalogListVm vm = new CatalogListVm { SettlementSelectListDsM = Settlement.ToList(), RoadSelectListDsM = Road.ToList(), RegionSelectListDsM = Region.ToList(), RoadDirectionSelectListDsM = RoadDirection.ToList(), }; return Json(vm); } [HttpPost] public async Task Create([FromBody] FlowIntensityEditDsM data) { var result = await _flowIntensityDs.CreateAsync(data); return Json(result); } [HttpPost] public async Task Update(int id, [FromBody] FlowIntensityEditDsM data){ await _flowIntensityDs.UpdateAsync(data,id); return Json(String.Empty); } [HttpDelete] public async Task Delete(int id) { try { int flowIntensity = await _flowIntensityDs.DeleteAsync(id); return Json(flowIntensity); } catch (ArgumentNullException ) { return NotFound(); } } } }