Guest User

Untitled

a guest
Jul 17th, 2018
4,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. //this is supposed to take the last five "tickets" created from a database
  2. [Route("Ticket")]
  3. public IActionResult Index(int page = 0)
  4. {
  5. var model = _db.Tickets.OrderByDescending(x => x.Time).Take(5).ToArray();
  6. return View(model);
  7. }
  8.  
  9. @model IEnumerable<Test.Models.Ticket>
  10. @{
  11. Layout = "_Layout";
  12. }
  13.  
  14. <p>Below is supposed to display the latest 5 "tickets" from a database.</p>
  15.  
  16. <div class="ticket-create">
  17. @foreach (var ticket in Model)
  18. {
  19. @Html.Partial("_Ticket", ticket)
  20. }
  21. </div>
  22.  
  23. @model Test.Models.Ticket
  24.  
  25. <article class="ticket-create">
  26. <h1>@Html.ActionLink(Model.Type, "Create", "Ticket", new { year = Model.Time.Year, month = Model.Time.Month, day = Model.Time.Day, time = Model.Time.TimeOfDay, key = Model.Key })</h1>
  27. <div class="type">
  28. Created on <span>@Model.Time</span> by <span>@Model.Name</span>
  29. </div>
  30. <div class="desc">
  31. @Model.Desc
  32. </div>
  33. <div class="clearance">
  34. @Model.Clearance
  35. </div>
  36. </article>
  37.  
  38. using System;
  39. using System.Collections.Generic;
  40. using System.ComponentModel.DataAnnotations;
  41. using System.Linq;
  42. using System.Text.RegularExpressions;
  43. using System.Threading.Tasks;
  44.  
  45. namespace Test.Models
  46. {
  47. public class Ticket
  48. {
  49. public long Id { get; set; }
  50.  
  51. private string _key;
  52.  
  53. public string Key
  54. {
  55. get
  56. {
  57. if(_key == null)
  58. {
  59. _key = Regex.Replace(Name.ToLower(), "[^a-z0-9]", "-");
  60. }
  61. return _key;
  62. }
  63. set { _key = value; }
  64. }
  65.  
  66. [Required]
  67. [DataType(DataType.Text)]
  68. public string Type { get; set; }
  69.  
  70. [Required]
  71. [DataType(DataType.Text)]
  72. public string Name { get; set; }
  73.  
  74. [StringLength(300, MinimumLength = 5, ErrorMessage = "The description must be between 5 and 300 characters long.")]
  75. [DataType(DataType.MultilineText)]
  76. public string Desc { get; set; }
  77.  
  78. [DataType(DataType.DateTime)]
  79. public DateTime Time { get; set; }
  80.  
  81. [Required]
  82. [DataType(DataType.Text)]
  83. public string Clearance { get; set; }
  84.  
  85. [DataType(DataType.Text)]
  86. public string Author { get; set; }
  87. }
  88. }
Add Comment
Please, Sign In to add comment