Guest User

Untitled

a guest
May 17th, 2018
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.11 KB | None | 0 0
  1. @using WebMatrix.Data
  2. @{
  3. Validation.Add("Prioriteit", Validator.Range(1, 10, "Getal moet tussen de 1 en 10 zijn."));
  4. Validation.RequireField("Prioriteit", "Dit veld mag niet leeg zijn!");
  5. Validation.RequireField("CadeauItem", "Dit veld mag niet leeg zijn!");
  6.  
  7. Database db;
  8. using (db = Database.Open("Todo"))
  9. {
  10. if (!Request.QueryString["KoopID"].IsEmpty() && Request.QueryString["KoopID"].IsInt())
  11. {
  12. int updateid = Request.QueryString["KoopID"].AsInt();
  13. string update = "UPDATE Wishlist SET Gekocht = '1' WHERE GiftID = @0";
  14. db.Execute(update, updateid);
  15. }
  16. if (!Request.QueryString["VerwijderID"].IsEmpty() && Request.QueryString["VerwijderID"].IsInt())
  17. {
  18. int VerwijderID = Request.QueryString["VerwijderID"].AsInt();
  19. string verwijder = "DELETE FROM Wishlist WHERE GiftID = @0";
  20. db.Execute(verwijder, VerwijderID);
  21. }
  22. if (IsPost && Validation.IsValid())
  23. {
  24. string CadeauItem = Request.Form["CadeauItem"];
  25. string Prioriteit = Request.Form["Prioriteit"];
  26. var LoginID = Session["cadeaucode"];
  27.  
  28. string insert = "INSERT INTO Wishlist (CadeauItem, Prioriteit, LoginID) VALUES (@0, @1, @2)";
  29.  
  30. db.Execute(insert, CadeauItem, Prioriteit, LoginID);
  31. }
  32.  
  33. }
  34. var lijstje = "SELECT CadeauItem, Prioriteit, LoginID, Gekocht, GiftID FROM Wishlist where LoginID = @0 ORDER BY Prioriteit DESC";
  35. var records = db.Query(lijstje, Session["cadeaucode"]);
  36. }
  37. <html xmlns="http://www.w3.org/1999/xhtml">
  38. <head>
  39. @RenderPage("head.cshtml")
  40. </head>
  41. <body>
  42. @RenderPage("nav.cshtml")
  43. <section>
  44. @if (Session["LoggedIn"] != null)
  45. {
  46. <h3>Uw cadeaucode is: @Session["cadeaucode"].</h3>
  47. <div class="container">
  48. <div class="row justify-content-center">
  49. <div class="login col-lg-3">
  50. <form class="justify-content-center" method="post">
  51. <div class="form-group">
  52. <input class="form-control" type="text" name="CadeauItem" placeholder="Cadeautje" />
  53. @Html.ValidationMessage("CadeauItem")
  54. </div>
  55. <div class="form-group">
  56. <input class="form-control" type="number" name="Prioriteit" placeholder="Prioriteit (1 - 10)" />
  57. @Html.ValidationMessage("Prioriteit")
  58. <label>10 is heel graag, 1 is dat je het graag wilt</label>
  59. </div>
  60. <input class="btn btn-outline-primary" value="Toevoegen" type="submit" />
  61. </form>
  62. </div>
  63. </div>
  64. </div>
  65. <table class="table">
  66. <tr>
  67. <th style="width: 33%">Naam cadeau</th>
  68. <th style="width: 33%">Prioriteit cadeau (1-10)</th>
  69. <th style="width: 33%">Reeds gekocht?</th>
  70. <th>Verwijderen?</th>
  71. </tr>
  72. </table>
  73. foreach (var record in records)
  74. {
  75. <table class="table">
  76. <tr>
  77. <td style="width: 33%">@record.CadeauItem</td>
  78. <td style="width: 33%">@record.Prioriteit</td>
  79. @if (@record.Gekocht == true)
  80. {
  81. <td style="width: 33%">Gekocht</td>
  82. }
  83. else
  84. {
  85. <td style="width: 33%">Niet gekocht</td>
  86. }
  87. <td style="width: 33%"><a href="~/wishlist.cshtml?VerwijderID=@record.GiftID" class="btn btn-outline-primary" role="button">Verwijder</a></td>
  88. </tr>
  89. </table>
  90. }
  91. }
  92. else
  93. {
  94. <h4>Vul hier het wenslijst nummer in, die u van het bruidspaar hebt gekregen:</h4>
  95. <div class="container">
  96. <div class="row justify-content-center">
  97. <div class="login col-lg-3">
  98. <form class="justify-content-center" method="get">
  99. <div class="form-group">
  100. <input class="form-control" type="number" name="WishlistID" placeholder="Wenslijst nummer" />
  101. </div>
  102. <input class="btn btn-outline-primary" value="Bevestig" type="submit" />
  103. </form>
  104. </div>
  105. </div>
  106. </div>
  107.  
  108. if (!Request.QueryString["WishlistID"].IsEmpty())
  109. {
  110. string searchcode = Request.QueryString["WishlistID"];
  111. var search_command = "SELECT GiftID, CadeauItem, Prioriteit, LoginID, Gekocht FROM Wishlist where LoginID = @0 AND Gekocht = 0 ORDER BY Prioriteit DESC";
  112. var selectedData = db.Query(search_command, searchcode);
  113. <table class="table">
  114. <tr>
  115. <th style="width: 33%">Naam cadeau</th>
  116. <th style="width: 33%">Prioriteit cadeau (1-10)</th>
  117. <th>Gekocht?</th>
  118. </tr>
  119. </table>
  120.  
  121. foreach (var record in selectedData)
  122. {
  123. <table class="table">
  124. <tr>
  125. <td style="width: 33%">@record.CadeauItem</td>
  126. <td style="width: 33%">@record.Prioriteit</td>
  127. <td style="width: 33%"><a href="~/wishlist.cshtml?KoopID=@record.GiftID" class="btn btn-outline-primary" role="button">Gekocht</a></td>
  128.  
  129. </tr>
  130. </table>
  131. }
  132. }
  133. }
  134. </section>
  135. @RenderPage("footer.cshtml")
  136. </body>
  137. </html>
Add Comment
Please, Sign In to add comment