Advertisement
Guest User

create shift new

a guest
Sep 24th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. @page "{handler?}"
  2. @model Platibus.Web.Pages.Booking.Booking_CreateShiftModel
  3.  
  4. @{
  5. ViewData["Title"] = "User Index";
  6.  
  7. }
  8.  
  9.  
  10.  
  11.  
  12.  
  13. <div class="row justify-content-lg-center">
  14. <div class="col-lg-10">
  15. <div class="box">
  16. <div class="box-header with-border">
  17. <h3 class="box-title text-primary"><i class="fas fa-user"></i> Administrative Page</h3>
  18. <div class="box-tools pull-right">
  19. <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip"
  20. title="Collapse">
  21. <i class="fa fa-minus"></i>
  22. </button>
  23. <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
  24. <i class="fa fa-times"></i>
  25. </button>
  26. </div>
  27. </div>
  28. <div class="box-body center-admin">
  29.  
  30.  
  31. <!-- Content -->
  32.  
  33. <div class="row justify-content-center">
  34. <div class="col-md-4 center-div">
  35. <form method="post">
  36. <div class="form-group">
  37. <label asp-for="shift.ShiftStart" class="control-label"></label>
  38. <input asp-for="shift.ShiftStart" class="form-control" />
  39.  
  40. </div>
  41. <div class="form-group">
  42. <label asp-for="shift.ShiftEnd" class="control-label"></label>
  43. <input asp-for="shift.ShiftEnd" class="form-control" />
  44. </div>
  45.  
  46. <div class="form-group">
  47. <label class="control-label">How many of this shift</label> <br></br>
  48. <input type="number" asp-for="numberOfShifts"/>
  49. </div>
  50.  
  51.  
  52. <div class="form-group">
  53. <input type="hidden" asp-for="shift.id"/>
  54. <button type="submit" asp-page-handler="CreateShift" class="far fa-check-square fa-4x"></button>
  55. </div>
  56. </form>
  57. </div>
  58. </div>
  59. <!-- End content -->
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64.  
  65.  
  66.  
  67.  
  68. using System;
  69. using System.Collections.Generic;
  70. using System.ComponentModel.DataAnnotations;
  71. using System.Linq;
  72. using System.Threading.Tasks;
  73. using Microsoft.AspNetCore.Mvc;
  74. using Microsoft.AspNetCore.Mvc.RazorPages;
  75. using Microsoft.AspNetCore.Mvc.Rendering;
  76. using Platibus.Web.Acquaintance.IDataServices;
  77. using Platibus.Web.DataServices.Models.Shift;
  78. using Platibus.Web.DataServices.Models.User;
  79.  
  80. namespace Platibus.Web.Pages.Booking
  81. {
  82. public class Booking_CreateShiftModel : PageModel
  83. {
  84. private readonly IShiftDataService _shiftDataService;
  85. private readonly IUserDataService _userDataService;
  86.  
  87. [BindProperty]
  88. public Shift shift { get; set; }
  89.  
  90. [BindProperty]
  91. public List<SelectListItem> UserList { get; set; }
  92.  
  93. [BindProperty]
  94. public User user { get; set; }
  95.  
  96. [BindProperty]
  97. public int numberOfShifts { get; set; }
  98.  
  99. public Booking_CreateShiftModel(IShiftDataService shiftDataService , IUserDataService userDataService)
  100. {
  101. _shiftDataService = shiftDataService;
  102. _userDataService = userDataService;
  103. }
  104.  
  105.  
  106. public async Task OnGetAsync(DateTime dateTime)
  107. {
  108.  
  109. Console.WriteLine();
  110.  
  111. var users = await _userDataService.ListUsersAsync(2, 2);
  112. UserList = users.Select(x => new SelectListItem()
  113. {
  114. Text = x.Name,
  115. Value = x.Id.ToString()
  116. }).ToList();
  117.  
  118.  
  119. }
  120.  
  121. public async Task<IActionResult> OnPostCreateShiftAsync(User user , Shift shift , int numberOfShifts)
  122. {
  123.  
  124. var list = new ListOfShifts();
  125. list.listOfShifts = new List<Shift>();
  126.  
  127.  
  128. for (int i = 0; i < numberOfShifts; i++)
  129. {
  130. list.listOfShifts.Add(new Shift{ShiftEnd = shift.ShiftEnd , ShiftStart = shift.ShiftStart});
  131.  
  132.  
  133. }
  134.  
  135. var result = _shiftDataService.CreateManyShifts(list);
  136.  
  137.  
  138.  
  139. return RedirectToPage("/Booking/Booking_index");
  140. }
  141.  
  142.  
  143. public async Task OnGetTestAsync(string date)
  144. {
  145.  
  146.  
  147. }
  148.  
  149.  
  150.  
  151.  
  152. }
  153. }
  154.  
  155.  
  156.  
  157. <div class="box-body">
  158.  
  159.  
  160.  
  161. <div class="center">
  162. <div class="form-group">
  163.  
  164. <a asp-page="./Booking_CreateShift">
  165. <i class="fas fa-plus fa-5x"></i>
  166. <p style="margin-left: -40px;">Click to add a new shift</p>
  167. </a>
  168. </div>
  169.  
  170. </div>
  171.  
  172. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement