Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @page "{handler?}"
- @model Platibus.Web.Pages.Booking.Booking_CreateShiftModel
- @{
- 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">How many of this shift</label> <br></br>
- <input type="number" asp-for="numberOfShifts"/>
- </div>
- <div class="form-group">
- <input type="hidden" asp-for="shift.id"/>
- <button type="submit" asp-page-handler="CreateShift" class="far fa-check-square 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;
- namespace Platibus.Web.Pages.Booking
- {
- public class Booking_CreateShiftModel : PageModel
- {
- private readonly IShiftDataService _shiftDataService;
- private readonly IUserDataService _userDataService;
- [BindProperty]
- public Shift shift { get; set; }
- [BindProperty]
- public List<SelectListItem> UserList { get; set; }
- [BindProperty]
- public User user { get; set; }
- [BindProperty]
- public int numberOfShifts { get; set; }
- public Booking_CreateShiftModel(IShiftDataService shiftDataService , IUserDataService userDataService)
- {
- _shiftDataService = shiftDataService;
- _userDataService = userDataService;
- }
- public async Task OnGetAsync(DateTime dateTime)
- {
- Console.WriteLine();
- var users = await _userDataService.ListUsersAsync(2, 2);
- UserList = users.Select(x => new SelectListItem()
- {
- Text = x.Name,
- Value = x.Id.ToString()
- }).ToList();
- }
- public async Task<IActionResult> OnPostCreateShiftAsync(User user , Shift shift , int numberOfShifts)
- {
- var list = new ListOfShifts();
- list.listOfShifts = new List<Shift>();
- for (int i = 0; i < numberOfShifts; i++)
- {
- list.listOfShifts.Add(new Shift{ShiftEnd = shift.ShiftEnd , ShiftStart = shift.ShiftStart});
- }
- var result = _shiftDataService.CreateManyShifts(list);
- return RedirectToPage("/Booking/Booking_index");
- }
- public async Task OnGetTestAsync(string date)
- {
- }
- }
- }
- <div class="box-body">
- <div class="center">
- <div class="form-group">
- <a asp-page="./Booking_CreateShift">
- <i class="fas fa-plus fa-5x"></i>
- <p style="margin-left: -40px;">Click to add a new shift</p>
- </a>
- </div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement