Guest User

Untitled

a guest
Oct 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. form method="post">
  2. <table class="table">
  3. <thead>
  4. <tr>
  5. <th>
  6. @Html.DisplayNameFor(model => model.Positions[0].Number)
  7. </th>
  8. <th>
  9. @Html.DisplayNameFor(model => model.Positions[0].IsSelected)
  10. </th>
  11. </tr>
  12. </thead>
  13. <tbody>
  14. @if (!(Model.Positions is null))
  15. {
  16. @foreach (var item in Model.Positions)
  17. {
  18. <tr>
  19. <td>
  20. @Html.DisplayFor(modelItem => item.Number)
  21. </td>
  22. <td>
  23. @Html.CheckBoxFor(modelItem => item.IsSelected)
  24. </td>
  25. </tr>
  26. }
  27. }
  28. </tbody>
  29. </table>
  30. <input type="submit" />
  31.  
  32. using System;
  33. using System.Collections.Generic;
  34. using System.ComponentModel.DataAnnotations;
  35. using System.Linq;
  36. using System.Threading.Tasks;
  37. using Project.Models;
  38. using Microsoft.AspNetCore.Mvc;
  39. using Microsoft.AspNetCore.Mvc.RazorPages;
  40. using Microsoft.AspNetCore.Mvc.Rendering;
  41. using Microsoft.EntityFrameworkCore;
  42.  
  43. namespace Project.Pages
  44. {
  45. public class TestModel : PageModel
  46. {
  47. private readonly DBContext _context;
  48.  
  49.  
  50. [FromRoute]
  51. public int? Id { get; set; }
  52. public List<SelectListItem> CustomerOrder { get; set; } = new List<SelectListItem>();
  53. [BindProperty]
  54. public string SelectedNumber { get; set; }
  55. [BindProperty]
  56. public List<Position> Positions { get; set; }
  57. public TestModel(Project.Models.DBContext context)
  58. {
  59. _context = context;
  60. }
  61. public void OnGet()
  62. {
  63. if (!(Id is null))
  64. {
  65. _context.CustomerOrder.Select(co => co.OrderNumber).Distinct().ToList().ForEach(y => CustomerOrder.Add(new SelectListItem(text: y, value: y)));
  66. }
  67. }
  68.  
  69. public async Task OnPostAsync()
  70. {
  71. if (!(SelectedNumber is null))
  72. {
  73. string s = $@"
  74. select * from Table1 xyz where xyz.Column1 in (
  75. SELECT distinct Column1
  76. FROM Table1
  77. where value = '" + SelectedNumber + "') and xyz.name = 'SLLZ'";
  78.  
  79. var res = await _context.Table1.FromSql(s).Select(x => x.ValueDescription).Distinct().OrderBy(x => x).ToListAsync();
  80.  
  81. Positions = new List<Position>();
  82. foreach (var item in res)
  83. {
  84. Positions.Add(new Position { Number = item });
  85. }
  86.  
  87.  
  88. }
  89. _context.CustomerOrder.Select(co => co.OrderNumber).Distinct().ToList().ForEach(y => CustomerOrder.Add(new SelectListItem(text: y, value: y)));
  90.  
  91. }
  92. }
  93. public class Position
  94. {
  95. public string Number { get; set; }
  96. public bool IsSelected { get; set; }
  97. }
  98. }
Add Comment
Please, Sign In to add comment