Advertisement
Guest User

new edit shift

a guest
Sep 24th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. @page
  2. @using Newtonsoft.Json.Serialization
  3. @model Platibus.Web.Pages.Booking.Booking_EditShiftModel
  4.  
  5. @{
  6. ViewData["Title"] = "User Index";
  7. }
  8.  
  9.  
  10.  
  11.  
  12. <div class="row justify-content-lg-center">
  13. <div class="col-lg-10">
  14. <div class="box">
  15. <div class="box-header with-border">
  16. <h3 class="box-title text-primary"><i class="fas fa-user"></i> Administrative Page</h3>
  17. <div class="box-tools pull-right">
  18. <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip"
  19. title="Collapse">
  20. <i class="fa fa-minus"></i>
  21. </button>
  22. <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
  23. <i class="fa fa-times"></i>
  24. </button>
  25. </div>
  26. </div>
  27. <div class="box-body center-admin">
  28.  
  29.  
  30. <!-- Content -->
  31.  
  32. <div class="row justify-content-center">
  33. <div class="col-md-4 center-div">
  34. <form method="post">
  35. <div class="form-group">
  36. <label asp-for="shift.ShiftStart" class="control-label"></label>
  37. <input asp-for="shift.ShiftStart" class="form-control" />
  38.  
  39. </div>
  40. <div class="form-group">
  41. <label asp-for="shift.ShiftEnd" class="control-label"></label>
  42. <input asp-for="shift.ShiftEnd" class="form-control" />
  43. </div>
  44. <div class="form-group">
  45. <label class="control-label">Add a employee to the shift</label> <br></br>
  46. @Html.DropDownListFor(model => model.user.Id, Model.UserList, "Empty Shift")
  47. </div>
  48. <div class="form-group">
  49. <input type="hidden" asp-for="shift.id"/>
  50. <label>Update User</label>
  51. <button type="submit" asp-page-handler="UpdateShiftWithUser" class="far fa-check-square fa-4x"></button>
  52. </div>
  53.  
  54. <div class="form-group">
  55. <input type="hidden" asp-for="shift.id"/>
  56. <label>Delete</label>
  57. <button type="submit" asp-page-handler="DeleteShift" class="fas fa-ban fa-4x"></button>
  58. </div>
  59. </form>
  60. </div>
  61. </div>
  62. <!-- End content -->
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. using System;
  78. using System.Collections.Generic;
  79. using System.ComponentModel.DataAnnotations;
  80. using System.Linq;
  81. using System.Threading.Tasks;
  82. using Microsoft.AspNetCore.Mvc;
  83. using Microsoft.AspNetCore.Mvc.RazorPages;
  84. using Microsoft.AspNetCore.Mvc.Rendering;
  85. using Platibus.Web.Acquaintance.IDataServices;
  86. using Platibus.Web.DataServices.Models.Shift;
  87. using Platibus.Web.DataServices.Models.User;
  88. using Platibus.Web.DataServices.Models.WorkSchedule;
  89. using Platibus.Web.Helpers;
  90.  
  91. namespace Platibus.Web.Pages.Booking
  92. {
  93. public class Booking_EditShiftModel : PageModel
  94. {
  95. private readonly IShiftDataService _shiftDataService;
  96. private readonly IUserDataService _userDataService;
  97.  
  98. [BindProperty]
  99. public Shift shift { get; set; }
  100.  
  101. [BindProperty]
  102. public User user { get; set; }
  103.  
  104. [BindProperty]
  105. public List<SelectListItem> UserList { get; set; }
  106.  
  107. private List<User> Employees;
  108.  
  109. public Booking_EditShiftModel(IShiftDataService shiftDataService , IUserDataService userDataService)
  110. {
  111. _shiftDataService = shiftDataService;
  112. _userDataService = userDataService;
  113. UserList = new List<SelectListItem>();
  114. shift = new Shift();
  115. Employees = new List<User>();
  116. }
  117.  
  118.  
  119. public async Task OnGetAsync(Guid id)
  120. {
  121. if (id.Equals(Guid.Empty))
  122. {
  123. // do error stuff
  124. }
  125.  
  126. shift.id = id;
  127. // get shift
  128. shift = await _shiftDataService.GetShiftById(id);
  129. var users = await _userDataService.ListUsersAsync(2, 2);
  130.  
  131.  
  132. foreach (var VARIABLE in users)
  133. {
  134. if (VARIABLE.AccessLevel.Equals(UserRoles.Employee))
  135. {
  136. Employees.Add(VARIABLE);
  137. }
  138. }
  139.  
  140.  
  141. UserList = Employees.Select(x => new SelectListItem()
  142. {
  143. Text = x.Name,
  144. Value = x.Id.ToString()
  145. }).ToList();
  146. }
  147.  
  148.  
  149. public async Task<IActionResult> OnPostUpdateShiftWithUserAsync(User user , Shift shift)
  150. {
  151. if (shift.ShiftStart == null)
  152. {
  153. return null; // More check and redirect to error page
  154. }
  155.  
  156. //shift.EmployeeOnShift = user.Id;
  157. var shiftWithEmployee = new UpdateShiftModel()
  158. {
  159. EmployeeId = user.Id,
  160. ShiftId = shift.id,
  161. ShiftStart = shift.ShiftStart,
  162. ShiftEnd = shift.ShiftEnd
  163. };
  164.  
  165. var result = await _shiftDataService.UpdateShift(shiftWithEmployee);
  166. return RedirectToPage("/Booking/Booking_index");
  167. }
  168.  
  169. public async Task<IActionResult> OnPostDeleteShiftAsync(Shift shift)
  170. {
  171. var result = await _shiftDataService.DeleteShiftById(shift.id);
  172.  
  173. return RedirectToPage("/Booking/Booking_Index");
  174. }
  175. }
  176. }
  177.  
  178.  
  179.  
  180.  
  181. <a asp-page="./Booking_EditShift" asp-route-id="@shift.Id" >
  182. <i class="fa fa-edit fa-2x padding-5"></i>
  183. </a>
  184. <form method="post">
  185. <button asp-page-handler="DeleteShift" type="submit" name="ShiftId" value="@shift.Id" class="fa fa-trash fa-2x padding-5"></button>
  186. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement