Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Mvc.Rendering;
  7. using Microsoft.EntityFrameworkCore;
  8. using edxl_cap_v1_2.Data;
  9. using edxl_cap_v1_2.Models;
  10. using edxl_cap_v1_2.Models.ContentViewModels;
  11.  
  12. namespace edxl_cap_v1_2.Controllers
  13. {
  14. public class AlertsController : Controller
  15. {
  16. private readonly ApplicationDbContext _context;
  17.  
  18. public AlertsController(ApplicationDbContext context)
  19. {
  20. _context = context;
  21. }
  22.  
  23. // GET: Alerts
  24. public ActionResult AlertSelect()
  25. {
  26. var vm = new AlertViewModel();
  27.  
  28. //Load the Identifiers property which will be used to build the SELECT element
  29. vm.Alert_Identifiers = _context.EdxlCapMsg
  30. .Select(x => new SelectListItem
  31. {
  32. Value = x.AlertIndex.ToString(),
  33. Text = x.Alert_Identifier
  34. }).ToList();
  35.  
  36. //Load the Alerts
  37. vm.Alerts = _context.EdxlCapMsg.Select(a => new AlertVm
  38. {
  39. AlertIndex = a.AlertIndex,
  40. Alert_Identifier = a.Alert_Identifier
  41. }).ToList();
  42. return View(vm);
  43. }
  44.  
  45. // GET: Alerts
  46. public async Task<IActionResult> Index()
  47. {
  48. return View(await _context.Alert.ToListAsync());
  49. }
  50.  
  51. [HttpPost]
  52. public IActionResult LoadAlert(Alert obj, string LoadAlert)
  53. {
  54. if (!string.IsNullOrEmpty(LoadAlert))
  55. {
  56. ViewBag.Message = "Alert loaded successfully";
  57. }
  58. return RedirectToAction("Index", "Alerts");
  59. }
  60.  
  61. @model edxl_cap_v1_2.Models.ContentViewModels.AlertViewModel
  62.  
  63. @{
  64. ViewData["Title"] = "AlertSelect";
  65. Layout = "~/Views/Shared/_CapCategoryLayout.cshtml";
  66. }
  67.  
  68. <head>
  69. <meta name="viewport" content="width=device-width" />
  70. <title>@ViewBag.Title</title>
  71. </head>
  72.  
  73. @{
  74. <h4>@Model.Alerts.Count Alerts</h4>
  75.  
  76. <form asp-controller="Alerts" asp-action="LoadAlert" method="post">
  77. <select asp-for="SelectedAlertIndex" asp-items="@Model.Alert_Identifiers">
  78. <option>Select one</option>
  79. </select>
  80. <br />
  81. <input type="submit" name="LoadAlert" value="LoadAlert" />
  82. </form>
  83. }
  84.  
  85. @model IEnumerable<edxl_cap_v1_2.Models.Alert>
  86. @using edxl_cap_v1_2.Models
  87.  
  88. @{
  89. ViewData["Title"] = "Index";
  90. Layout = "~/Views/Shared/_CapCategoryLayout.cshtml";
  91. }
  92.  
  93. <html>
  94. <head>
  95. <meta name="viewport" content="width=device-width" />
  96. <title>@ViewBag.Title</title>
  97. </head>
  98. <body>
  99.  
  100. <h4>@ViewBag.Message</h4>
  101.  
  102. <h3>Alert</h3>
  103.  
  104. <style>
  105. tr:nth-child(even) {
  106. background-color: lightBlue;
  107. }
  108.  
  109. tr:nth-child(odd) {
  110. background-color: white;
  111. }
  112. </style>
  113.  
  114. <table id="elementTable" class="smallText">
  115.  
  116. @foreach (var item in Model)
  117. {
  118. <tr>
  119. <td>
  120. <input type="checkbox" name="start">start
  121. </td>
  122. <td>
  123. &nbsp;&nbsp;element:<br>
  124. &nbsp;&nbsp;@Html.DisplayNameFor(model => model.Alert_Identifier)<text>*</text>
  125. @if (Element.Required == true)
  126. {
  127. <text>*</text>
  128. }
  129. else
  130. {
  131. <text>&nbsp;&nbsp;</text>
  132. }
  133. </td>
  134. <td>
  135. <div id="elementInput">
  136.  
  137. @if (Element.DatatypeSize < 49)
  138. {
  139. <span class="smallText">
  140. Enter @Html.DisplayNameFor(model => model.AlertIndex) value
  141. <input type="text" name="elementValue" value="@Html.DisplayFor(modelItem => item.AlertIndex)" size="25" />
  142. </span>
  143. }
  144. else if (Element.DatatypeSize > 49)
  145. {
  146. <span class="smallText">
  147. Enter @Html.DisplayNameFor(model => model.AlertIndex) value
  148. <textarea name="elementValue" rows="4" value="@Html.DisplayFor(modelItem => item.AlertIndex)" cols="25">
  149. </textarea>
  150. </span>
  151. }
  152. </div>
  153. </td>
  154. <td>
  155. @if (Element.Repeatable == true)
  156. {
  157. <input type="radio" name="repeatElement" value="repeat" /><text>&nbsp; repeat</text>
  158. }
  159. else
  160. {
  161. <text>&nbsp;&nbsp;</text>
  162. }
  163. </td>
  164. <td>
  165. <form asp-area="" asp-controller="alerts" asp-action="Details" method="post" asp-route-id="@item.AlertIndex">
  166. <input type="hidden"
  167. name="Identifier"
  168. value="@Html.DisplayFor(modelItem => item.AlertIndex)">
  169. <input type="submit"
  170. value="add element">
  171. </form>
  172. </td>
  173. <td>
  174. <a asp-action="Edit" asp-route-id="@item.AlertIndex">Edit</a>
  175. <a asp-action="Delete" asp-route-id="@item.AlertIndex">Delete</a>
  176. </td>
  177. </tr>
  178.  
  179. using System;
  180. using System.Collections.Generic;
  181. using System.ComponentModel.DataAnnotations;
  182.  
  183. namespace edxl_cap_v1_2.Models
  184. {
  185. public class Alert
  186. {
  187. [Key]
  188. public int AlertIndex { get; set; }
  189. [MaxLength(150)]
  190. public string Alert_Identifier { get; set; }
  191. public string Sender { get; set; }
  192. public DateTime Sent { get; set; }
  193. public Status Status { get; set; }
  194. public MsgType MsgType { get; set; }
  195. public string Source { get; set; }
  196. public Scope Scope { get; set; }
  197. public string Restriction { get; set; }
  198. public string Addresses { get; set; }
  199. public string Code { get; set; }
  200. public string Note { get; set; }
  201. public string References { get; set; }
  202. public string Incidents { get; set; }
  203. public int DataCategory_Id { get; set; }
  204.  
  205. public ICollection<Element> Elements { get; set; }
  206.  
  207. public System.Collections.IEnumerator GetEnumerator()
  208. {
  209. throw new NotImplementedException();
  210. }
  211. }
  212.  
  213. public enum Status
  214. {
  215. Actual,
  216. Exercise,
  217. System,
  218. Test,
  219. Draft
  220. }
  221. public enum MsgType
  222. {
  223. Alert,
  224. Update,
  225. Cancel,
  226. Ack,
  227. Error
  228. }
  229. public enum Scope
  230. {
  231. Public,
  232. Restricted,
  233. Private
  234. }
  235.  
  236. using Microsoft.AspNetCore.Mvc.Rendering;
  237. using System;
  238. using System.Collections.Generic;
  239. using System.ComponentModel.DataAnnotations;
  240.  
  241. namespace edxl_cap_v1_2.Models.ContentViewModels
  242. {
  243. public class AlertViewModel
  244. {
  245. public string SelectedAlertIndex { get; set; }
  246. public List<SelectListItem> Alert_Identifiers { get; set; }
  247. public List<AlertVm> Alerts { get; set; }
  248. }
  249. public class AlertVm
  250. {
  251. [Key]
  252. public int AlertIndex { get; set; }
  253. [MaxLength(150)]
  254. public string Alert_Identifier { get; set; }
  255. }
  256.  
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement