Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.Rendering;
- using Microsoft.EntityFrameworkCore;
- using edxl_cap_v1_2.Data;
- using edxl_cap_v1_2.Models;
- using edxl_cap_v1_2.Models.ContentViewModels;
- namespace edxl_cap_v1_2.Controllers
- {
- public class AlertsController : Controller
- {
- private readonly ApplicationDbContext _context;
- public AlertsController(ApplicationDbContext context)
- {
- _context = context;
- }
- // GET: Alerts
- public ActionResult AlertSelect()
- {
- var vm = new AlertViewModel();
- //Load the Identifiers property which will be used to build the SELECT element
- vm.Alert_Identifiers = _context.EdxlCapMsg
- .Select(x => new SelectListItem
- {
- Value = x.AlertIndex.ToString(),
- Text = x.Alert_Identifier
- }).ToList();
- //Load the Alerts
- vm.Alerts = _context.EdxlCapMsg.Select(a => new AlertVm
- {
- AlertIndex = a.AlertIndex,
- Alert_Identifier = a.Alert_Identifier
- }).ToList();
- return View(vm);
- }
- // GET: Alerts
- public async Task<IActionResult> Index()
- {
- return View(await _context.Alert.ToListAsync());
- }
- [HttpPost]
- public IActionResult LoadAlert(Alert obj, string LoadAlert)
- {
- if (!string.IsNullOrEmpty(LoadAlert))
- {
- ViewBag.Message = "Alert loaded successfully";
- }
- return RedirectToAction("Index", "Alerts");
- }
- @model edxl_cap_v1_2.Models.ContentViewModels.AlertViewModel
- @{
- ViewData["Title"] = "AlertSelect";
- Layout = "~/Views/Shared/_CapCategoryLayout.cshtml";
- }
- <head>
- <meta name="viewport" content="width=device-width" />
- <title>@ViewBag.Title</title>
- </head>
- @{
- <h4>@Model.Alerts.Count Alerts</h4>
- <form asp-controller="Alerts" asp-action="LoadAlert" method="post">
- <select asp-for="SelectedAlertIndex" asp-items="@Model.Alert_Identifiers">
- <option>Select one</option>
- </select>
- <br />
- <input type="submit" name="LoadAlert" value="LoadAlert" />
- </form>
- }
- @model IEnumerable<edxl_cap_v1_2.Models.Alert>
- @using edxl_cap_v1_2.Models
- @{
- ViewData["Title"] = "Index";
- Layout = "~/Views/Shared/_CapCategoryLayout.cshtml";
- }
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title>@ViewBag.Title</title>
- </head>
- <body>
- <h4>@ViewBag.Message</h4>
- <h3>Alert</h3>
- <style>
- tr:nth-child(even) {
- background-color: lightBlue;
- }
- tr:nth-child(odd) {
- background-color: white;
- }
- </style>
- <table id="elementTable" class="smallText">
- @foreach (var item in Model)
- {
- <tr>
- <td>
- <input type="checkbox" name="start">start
- </td>
- <td>
- element:<br>
- @Html.DisplayNameFor(model => model.Alert_Identifier)<text>*</text>
- @if (Element.Required == true)
- {
- <text>*</text>
- }
- else
- {
- <text> </text>
- }
- </td>
- <td>
- <div id="elementInput">
- @if (Element.DatatypeSize < 49)
- {
- <span class="smallText">
- Enter @Html.DisplayNameFor(model => model.AlertIndex) value
- <input type="text" name="elementValue" value="@Html.DisplayFor(modelItem => item.AlertIndex)" size="25" />
- </span>
- }
- else if (Element.DatatypeSize > 49)
- {
- <span class="smallText">
- Enter @Html.DisplayNameFor(model => model.AlertIndex) value
- <textarea name="elementValue" rows="4" value="@Html.DisplayFor(modelItem => item.AlertIndex)" cols="25">
- </textarea>
- </span>
- }
- </div>
- </td>
- <td>
- @if (Element.Repeatable == true)
- {
- <input type="radio" name="repeatElement" value="repeat" /><text> repeat</text>
- }
- else
- {
- <text> </text>
- }
- </td>
- <td>
- <form asp-area="" asp-controller="alerts" asp-action="Details" method="post" asp-route-id="@item.AlertIndex">
- <input type="hidden"
- name="Identifier"
- value="@Html.DisplayFor(modelItem => item.AlertIndex)">
- <input type="submit"
- value="add element">
- </form>
- </td>
- <td>
- <a asp-action="Edit" asp-route-id="@item.AlertIndex">Edit</a>
- <a asp-action="Delete" asp-route-id="@item.AlertIndex">Delete</a>
- </td>
- </tr>
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- namespace edxl_cap_v1_2.Models
- {
- public class Alert
- {
- [Key]
- public int AlertIndex { get; set; }
- [MaxLength(150)]
- public string Alert_Identifier { get; set; }
- public string Sender { get; set; }
- public DateTime Sent { get; set; }
- public Status Status { get; set; }
- public MsgType MsgType { get; set; }
- public string Source { get; set; }
- public Scope Scope { get; set; }
- public string Restriction { get; set; }
- public string Addresses { get; set; }
- public string Code { get; set; }
- public string Note { get; set; }
- public string References { get; set; }
- public string Incidents { get; set; }
- public int DataCategory_Id { get; set; }
- public ICollection<Element> Elements { get; set; }
- public System.Collections.IEnumerator GetEnumerator()
- {
- throw new NotImplementedException();
- }
- }
- public enum Status
- {
- Actual,
- Exercise,
- System,
- Test,
- Draft
- }
- public enum MsgType
- {
- Alert,
- Update,
- Cancel,
- Ack,
- Error
- }
- public enum Scope
- {
- Public,
- Restricted,
- Private
- }
- using Microsoft.AspNetCore.Mvc.Rendering;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- namespace edxl_cap_v1_2.Models.ContentViewModels
- {
- public class AlertViewModel
- {
- public string SelectedAlertIndex { get; set; }
- public List<SelectListItem> Alert_Identifiers { get; set; }
- public List<AlertVm> Alerts { get; set; }
- }
- public class AlertVm
- {
- [Key]
- public int AlertIndex { get; set; }
- [MaxLength(150)]
- public string Alert_Identifier { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement