SettlementAddressLinkController.cs
3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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 SettlementAddressLinkController : Controller
{
private readonly ISettlementAddressLinkDs _settlementAddressLinkDs;
private readonly IRoadDs _roadDs;
private readonly ISettlementDs _settlementDs;
private readonly IRegionDs _regionDs;
private readonly ISettlementLocationDs _settlementLocationDs;
public SettlementAddressLinkController(ISettlementAddressLinkDs SettlementAddressLinkDs, IRoadDs RoadDs, ISettlementDs SettlementDs, IRegionDs RegionDs, ISettlementLocationDs SettlementLocationDs)
{
_settlementAddressLinkDs = SettlementAddressLinkDs;
_roadDs = RoadDs;
_settlementDs = SettlementDs;
_regionDs = RegionDs;
_settlementLocationDs = SettlementLocationDs;
}
// GET: SettlementAddressLink
[HttpGet]
public async Task<IActionResult> Index([FromQuery] PaginationDsM data)
{
try
{
var settlementAddressLinks = await _settlementAddressLinkDs.GetIndexListAsync(data);
SettlementAddressLinkListVm vm = new SettlementAddressLinkListVm
{
SettlementAddressLinkEditDsM = settlementAddressLinks.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<IActionResult> Directory(){
var Settlement = await _settlementDs.GetSelectListAsync();
var Road = await _roadDs.GetSelectListAsync();
var Region = await _regionDs.GetSelectListAsync();
var SettlementLocation = await _settlementLocationDs.GetSelectListAsync();
CatalogListVm vm = new CatalogListVm
{
SettlementSelectListDsM = Settlement.ToList(),
RoadSelectListDsM = Road.ToList(),
RegionSelectListDsM = Region.ToList(),
SettlementLocationSelectListDsM = SettlementLocation.ToList()
};
return Json(vm);
}
[HttpPost]
public async Task<IActionResult> Create([FromBody] SettlementAddressLinkEditDsM data)
{
var result = await _settlementAddressLinkDs.CreateAsync(data);
return Json(result);
}
[HttpPost]
public async Task<IActionResult> Update(int id, [FromBody] SettlementAddressLinkEditDsM data){
await _settlementAddressLinkDs.UpdateAsync(data,id);
return Json(String.Empty);
}
[HttpDelete]
public async Task<IActionResult> Delete(int id)
{
try
{
int settlementAddressLink = await _settlementAddressLinkDs.DeleteAsync(id);
return Json(settlementAddressLink);
}
catch (ArgumentNullException )
{
return NotFound();
}
}
}
}