|
1 | | -using AccountGoWeb.Models.Financial; |
2 | | -using Dto.Administration; |
| 1 | +using Dto.Administration; |
3 | 2 | using Dto.Security; |
4 | 3 | using Microsoft.AspNetCore.Mvc; |
5 | 4 | using Microsoft.Extensions.Configuration; |
|
8 | 7 |
|
9 | 8 | namespace AccountGoWeb.Controllers |
10 | 9 | { |
11 | | - [Microsoft.AspNetCore.Authorization.Authorize] |
12 | | - public class AdministrationController : BaseController |
| 10 | + [Microsoft.AspNetCore.Authorization.Authorize] |
| 11 | + public class AdministrationController : BaseController |
| 12 | + { |
| 13 | + public AdministrationController(IConfiguration config) |
13 | 14 | { |
14 | | - public AdministrationController(IConfiguration config) { |
15 | | - _baseConfig = config; |
16 | | - Models.SelectListItemHelper._config = config; |
17 | | - } |
18 | | - |
19 | | - public IActionResult Company() |
20 | | - { |
21 | | - ViewBag.PageContentHeader = "Company"; |
22 | | - var model = GetAsync<Company>("administration/company").Result; |
23 | | - if (model == null) |
24 | | - model = new Dto.Administration.Company(); |
25 | | - return View(model); |
26 | | - } |
27 | | - |
28 | | - [HttpPost] |
29 | | - public IActionResult Company(Company model) |
30 | | - { |
31 | | - ViewBag.PageContentHeader = "Company"; |
32 | | - if (ModelState.IsValid) |
33 | | - { |
34 | | - var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(model); |
35 | | - var content = new StringContent(serialize); |
36 | | - content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); |
| 15 | + _baseConfig = config; |
| 16 | + Models.SelectListItemHelper._config = config; |
| 17 | + } |
37 | 18 |
|
38 | | - var response = PostAsync("administration/savecompany", content); |
| 19 | + public IActionResult Company() |
| 20 | + { |
| 21 | + ViewBag.PageContentHeader = "Company"; |
| 22 | + var model = GetAsync<Company>("administration/company").Result; |
| 23 | + if (model == null) |
| 24 | + model = new Company(); |
| 25 | + return View(model); |
| 26 | + } |
39 | 27 |
|
40 | | - return View(model); |
41 | | - } |
42 | | - return View(model); |
43 | | - } |
| 28 | + [HttpPost] |
| 29 | + public IActionResult Company(Company model) |
| 30 | + { |
| 31 | + ViewBag.PageContentHeader = "Company"; |
| 32 | + if (ModelState.IsValid) |
| 33 | + { |
| 34 | + var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(model); |
| 35 | + var content = new StringContent(serialize); |
| 36 | + content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); |
| 37 | + |
| 38 | + var response = PostAsync("administration/savecompany", content); |
| 39 | + |
| 40 | + return View(model); |
| 41 | + } |
| 42 | + return View(model); |
| 43 | + } |
44 | 44 |
|
45 | | - public IActionResult Settings() |
46 | | - { |
47 | | - ViewBag.PageContentHeader = "Setup and Configuration"; |
48 | | - ViewBag.Accounts = Models.SelectListItemHelper.Accounts(); |
49 | | - return View(); |
50 | | - } |
| 45 | + public IActionResult Settings() |
| 46 | + { |
| 47 | + ViewBag.PageContentHeader = "Setup and Configuration"; |
| 48 | + ViewBag.Accounts = Models.SelectListItemHelper.Accounts(); |
| 49 | + var model = GetAsync<GeneralLedgerSetting>("administration/settings").Result; |
| 50 | + if (model == null) |
| 51 | + model = new GeneralLedgerSetting(); |
| 52 | + return View(model); |
| 53 | + } |
51 | 54 |
|
52 | | - [HttpPost] |
53 | | - public IActionResult SaveSettings(GeneralLedgerSetting model) |
54 | | - { |
55 | | - if(ModelState.IsValid) |
56 | | - { |
| 55 | + [HttpPost] |
| 56 | + public IActionResult SaveSettings(Models.Financial.GeneralLedgerSetting model) |
| 57 | + { |
| 58 | + if (ModelState.IsValid) |
| 59 | + { |
57 | 60 |
|
58 | | - } |
59 | | - ViewBag.Accounts = Models.SelectListItemHelper.Accounts(); |
60 | | - ViewBag.PageContentHeader = "Setup and Configuration"; |
61 | | - return RedirectToAction(nameof(AdministrationController.Settings)); |
62 | | - } |
| 61 | + } |
| 62 | + ViewBag.Accounts = Models.SelectListItemHelper.Accounts(); |
| 63 | + ViewBag.PageContentHeader = "Setup and Configuration"; |
| 64 | + return RedirectToAction(nameof(AdministrationController.Settings)); |
| 65 | + } |
63 | 66 |
|
64 | | - [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
65 | | - public async System.Threading.Tasks.Task<IActionResult> Users() |
66 | | - { |
67 | | - var users = await GetAsync<System.Collections.Generic.IEnumerable<User>>("administration/users"); |
68 | | - ViewBag.PageContentHeader = "Users"; |
69 | | - return View(users); |
70 | | - } |
| 67 | + [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
| 68 | + public async System.Threading.Tasks.Task<IActionResult> Users() |
| 69 | + { |
| 70 | + var users = await GetAsync<System.Collections.Generic.IEnumerable<User>>("administration/users"); |
| 71 | + ViewBag.PageContentHeader = "Users"; |
| 72 | + return View(users); |
| 73 | + } |
71 | 74 |
|
72 | | - [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
73 | | - public async System.Threading.Tasks.Task<IActionResult> Roles() |
74 | | - { |
75 | | - var roles = await GetAsync<System.Collections.Generic.IEnumerable<Role>>("administration/roles"); |
76 | | - ViewBag.PageContentHeader = "Security Roles"; |
77 | | - return View(roles); |
78 | | - } |
| 75 | + [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
| 76 | + public async System.Threading.Tasks.Task<IActionResult> Roles() |
| 77 | + { |
| 78 | + var roles = await GetAsync<System.Collections.Generic.IEnumerable<Role>>("administration/roles"); |
| 79 | + ViewBag.PageContentHeader = "Security Roles"; |
| 80 | + return View(roles); |
| 81 | + } |
79 | 82 |
|
80 | | - [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
81 | | - public async System.Threading.Tasks.Task<IActionResult> Groups() |
82 | | - { |
83 | | - var groups = await GetAsync<System.Collections.Generic.IEnumerable<Group>>("administration/groups"); |
84 | | - ViewBag.PageContentHeader = "Security Groups"; |
85 | | - return View(groups); |
86 | | - } |
| 83 | + [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
| 84 | + public async System.Threading.Tasks.Task<IActionResult> Groups() |
| 85 | + { |
| 86 | + var groups = await GetAsync<System.Collections.Generic.IEnumerable<Group>>("administration/groups"); |
| 87 | + ViewBag.PageContentHeader = "Security Groups"; |
| 88 | + return View(groups); |
| 89 | + } |
87 | 90 |
|
88 | | - [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
89 | | - public async System.Threading.Tasks.Task<IActionResult> AuditLogs() |
90 | | - { |
91 | | - var auditLogs = await GetAsync<System.Collections.Generic.IEnumerable<AuditLog>>("administration/auditlogs"); |
| 91 | + [Microsoft.AspNetCore.Authorization.Authorize(Roles = "SystemAdministrators")] |
| 92 | + public async System.Threading.Tasks.Task<IActionResult> AuditLogs() |
| 93 | + { |
| 94 | + var auditLogs = await GetAsync<System.Collections.Generic.IEnumerable<AuditLog>>("administration/auditlogs"); |
92 | 95 |
|
93 | | - ViewBag.PageContentHeader = "Audit Logs"; |
94 | | - return View(model:auditLogs); |
95 | | - } |
| 96 | + ViewBag.PageContentHeader = "Audit Logs"; |
| 97 | + return View(model: auditLogs); |
| 98 | + } |
96 | 99 |
|
97 | | - [HttpGet] |
98 | | - public new IActionResult User(int id = 0) |
99 | | - { |
100 | | - if(id != 0) |
101 | | - { |
102 | | - ViewBag.PageContentHeader = "User"; |
103 | | - } |
104 | | - else |
105 | | - { |
106 | | - ViewBag.PageContentHeader = "New User"; |
107 | | - } |
108 | | - |
109 | | - return View(new Models.Account.RegisterViewModel()); |
110 | | - } |
| 100 | + [HttpGet] |
| 101 | + public new IActionResult User(int id = 0) |
| 102 | + { |
| 103 | + if (id != 0) |
| 104 | + { |
| 105 | + ViewBag.PageContentHeader = "User"; |
| 106 | + } |
| 107 | + else |
| 108 | + { |
| 109 | + ViewBag.PageContentHeader = "New User"; |
| 110 | + } |
| 111 | + |
| 112 | + return View(new Models.Account.RegisterViewModel()); |
| 113 | + } |
111 | 114 |
|
112 | | - [HttpPost] |
113 | | - public new IActionResult User(Models.Account.RegisterViewModel model) |
| 115 | + [HttpPost] |
| 116 | + public new IActionResult User(Models.Account.RegisterViewModel model) |
| 117 | + { |
| 118 | + try |
| 119 | + { |
| 120 | + if (ModelState.IsValid) |
114 | 121 | { |
115 | | - try |
116 | | - { |
117 | | - if (ModelState.IsValid) |
118 | | - { |
119 | | - var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(model); |
120 | | - var content = new StringContent(serialize); |
121 | | - content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); |
122 | | - HttpResponseMessage responseAddNewUser = Post("account/addnewuser", content); |
123 | | - Newtonsoft.Json.Linq.JObject resultAddNewUser = Newtonsoft.Json.Linq.JObject.Parse(responseAddNewUser.Content.ReadAsStringAsync().Result); |
124 | | - |
125 | | - if ((bool)resultAddNewUser["succeeded"]) |
126 | | - { |
127 | | - return RedirectToAction(nameof(AdministrationController.Users), "Administration"); |
128 | | - } |
129 | | - else |
130 | | - { |
131 | | - ModelState.AddModelError(string.Empty, resultAddNewUser["errors"][0]["description"].ToString()); |
132 | | - return View(model); |
133 | | - } |
134 | | - } |
135 | | - } |
136 | | - catch (Exception ex) |
137 | | - { |
138 | | - ModelState.AddModelError(string.Empty, "Please check if your database is ready/published." + ": " + ex.Message); |
139 | | - return View(model); |
140 | | - } |
141 | | - ViewBag.PageContentHeader = "New User"; |
| 122 | + var serialize = Newtonsoft.Json.JsonConvert.SerializeObject(model); |
| 123 | + var content = new StringContent(serialize); |
| 124 | + content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); |
| 125 | + HttpResponseMessage responseAddNewUser = Post("account/addnewuser", content); |
| 126 | + Newtonsoft.Json.Linq.JObject resultAddNewUser = Newtonsoft.Json.Linq.JObject.Parse(responseAddNewUser.Content.ReadAsStringAsync().Result); |
| 127 | + |
| 128 | + if ((bool)resultAddNewUser["succeeded"]) |
| 129 | + { |
| 130 | + return RedirectToAction(nameof(AdministrationController.Users), "Administration"); |
| 131 | + } |
| 132 | + else |
| 133 | + { |
| 134 | + ModelState.AddModelError(string.Empty, resultAddNewUser["errors"][0]["description"].ToString()); |
142 | 135 | return View(model); |
| 136 | + } |
143 | 137 | } |
| 138 | + } |
| 139 | + catch (Exception ex) |
| 140 | + { |
| 141 | + ModelState.AddModelError(string.Empty, "Please check if your database is ready/published." + ": " + ex.Message); |
| 142 | + return View(model); |
| 143 | + } |
| 144 | + ViewBag.PageContentHeader = "New User"; |
| 145 | + return View(model); |
144 | 146 | } |
| 147 | + } |
145 | 148 | } |
0 commit comments