Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @page
- @using Newtonsoft.Json.Serialization
- @model Platibus.Web.Pages.Booking.Booking_EditShiftModel
- @{
- ViewData["Title"] = "User Index";
- }
- <div class="row justify-content-lg-center">
- <div class="col-lg-10">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title text-primary"><i class="fas fa-user"></i> Administrative Page</h3>
- <div class="box-tools pull-right">
- <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip"
- title="Collapse">
- <i class="fa fa-minus"></i>
- </button>
- <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
- <i class="fa fa-times"></i>
- </button>
- </div>
- </div>
- <div class="box-body center-admin">
- <!-- Content -->
- <div class="row justify-content-center">
- <div class="col-md-4 center-div">
- <form method="post">
- <div class="form-group">
- <label asp-for="shift.ShiftStart" class="control-label"></label>
- <input asp-for="shift.ShiftStart" class="form-control" />
- </div>
- <div class="form-group">
- <label asp-for="shift.ShiftEnd" class="control-label"></label>
- <input asp-for="shift.ShiftEnd" class="form-control" />
- </div>
- <div class="form-group">
- <label class="control-label">Add a employee to the shift</label> <br></br>
- @Html.DropDownListFor(model => model.user.Id, Model.UserList, "Empty Shift")
- </div>
- <div class="form-group">
- <input type="hidden" asp-for="shift.id"/>
- <label>Update User</label>
- <button type="submit" asp-page-handler="UpdateShiftWithUser" class="far fa-check-square fa-4x"></button>
- </div>
- <div class="form-group">
- <input type="hidden" asp-for="shift.id"/>
- <label>Delete</label>
- <button type="submit" asp-page-handler="DeleteShift" class="fas fa-ban fa-4x"></button>
- </div>
- </form>
- </div>
- </div>
- <!-- End content -->
- </div>
- </div>
- </div>
- </div>
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- using Microsoft.AspNetCore.Mvc.Rendering;
- using Platibus.Web.Acquaintance.IDataServices;
- using Platibus.Web.DataServices.Models.Shift;
- using Platibus.Web.DataServices.Models.User;
- using Platibus.Web.DataServices.Models.WorkSchedule;
- using Platibus.Web.Helpers;
- namespace Platibus.Web.Pages.Booking
- {
- public class Booking_EditShiftModel : PageModel
- {
- private readonly IShiftDataService _shiftDataService;
- private readonly IUserDataService _userDataService;
- [BindProperty]
- public Shift shift { get; set; }
- [BindProperty]
- public User user { get; set; }
- [BindProperty]
- public List<SelectListItem> UserList { get; set; }
- private List<User> Employees;
- public Booking_EditShiftModel(IShiftDataService shiftDataService , IUserDataService userDataService)
- {
- _shiftDataService = shiftDataService;
- _userDataService = userDataService;
- UserList = new List<SelectListItem>();
- shift = new Shift();
- Employees = new List<User>();
- }
- public async Task OnGetAsync(Guid id)
- {
- if (id.Equals(Guid.Empty))
- {
- // do error stuff
- }
- shift.id = id;
- // get shift
- shift = await _shiftDataService.GetShiftById(id);
- var users = await _userDataService.ListUsersAsync(2, 2);
- foreach (var VARIABLE in users)
- {
- if (VARIABLE.AccessLevel.Equals(UserRoles.Employee))
- {
- Employees.Add(VARIABLE);
- }
- }
- UserList = Employees.Select(x => new SelectListItem()
- {
- Text = x.Name,
- Value = x.Id.ToString()
- }).ToList();
- }
- public async Task<IActionResult> OnPostUpdateShiftWithUserAsync(User user , Shift shift)
- {
- if (shift.ShiftStart == null)
- {
- return null; // More check and redirect to error page
- }
- //shift.EmployeeOnShift = user.Id;
- var shiftWithEmployee = new UpdateShiftModel()
- {
- EmployeeId = user.Id,
- ShiftId = shift.id,
- ShiftStart = shift.ShiftStart,
- ShiftEnd = shift.ShiftEnd
- };
- var result = await _shiftDataService.UpdateShift(shiftWithEmployee);
- return RedirectToPage("/Booking/Booking_index");
- }
- public async Task<IActionResult> OnPostDeleteShiftAsync(Shift shift)
- {
- var result = await _shiftDataService.DeleteShiftById(shift.id);
- return RedirectToPage("/Booking/Booking_Index");
- }
- }
- }
- <a asp-page="./Booking_EditShift" asp-route-id="@shift.Id" >
- <i class="fa fa-edit fa-2x padding-5"></i>
- </a>
- <form method="post">
- <button asp-page-handler="DeleteShift" type="submit" name="ShiftId" value="@shift.Id" class="fa fa-trash fa-2x padding-5"></button>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement