Merge pull request #4 from JimPaine/master
Added additional validation and ux changes
This commit is contained in:
Коммит
a856c20e05
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
@ -22,6 +23,23 @@ namespace Project.Zap.Controllers
|
|||
[AllowAnonymous]
|
||||
public IActionResult Index()
|
||||
{
|
||||
Claim zapRole = HttpContext.User.Claims.Where(x => x.Type == "extension_zaprole").FirstOrDefault();
|
||||
|
||||
if (zapRole == null)
|
||||
{
|
||||
throw new ArgumentException("Claim extension_zaprole is required ");
|
||||
}
|
||||
|
||||
if(zapRole.Value == "org_a_manager")
|
||||
{
|
||||
return Redirect("/Shift");
|
||||
}
|
||||
|
||||
if(zapRole.Value == "org_b_employee")
|
||||
{
|
||||
return Redirect("/Shift/ViewShifts");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Project.Zap.Helpers;
|
||||
using Project.Zap.Library.Models;
|
||||
using Project.Zap.Library.Services;
|
||||
|
@ -21,17 +22,19 @@ namespace Project.Zap.Controllers
|
|||
private readonly IRepository<Organization> organizationRepository;
|
||||
private readonly Microsoft.Graph.IGraphServiceClient graphServiceClient;
|
||||
|
||||
public ShiftController(IRepository<Shift> shiftRepository, IRepository<Organization> organizationRepository, Microsoft.Graph.IGraphServiceClient graphServiceClient)
|
||||
public ShiftController(
|
||||
IRepository<Shift> shiftRepository,
|
||||
IRepository<Organization> organizationRepository,
|
||||
Microsoft.Graph.IGraphServiceClient graphServiceClient)
|
||||
{
|
||||
this.shiftRepository = shiftRepository;
|
||||
this.organizationRepository = organizationRepository;
|
||||
this.graphServiceClient = graphServiceClient;
|
||||
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
IEnumerable<Shift> shifts = await this.shiftRepository.Get();
|
||||
IEnumerable<Shift> shifts = this.shiftRepository.Get(x => x.Start > DateTime.Now);
|
||||
SearchShiftViewModel viewModel = new SearchShiftViewModel
|
||||
{
|
||||
StoreNames = await this.GetStoreNames(),
|
||||
|
@ -88,12 +91,12 @@ namespace Project.Zap.Controllers
|
|||
throw new ArgumentException("http://schemas.microsoft.com/identity/claims/objectidentifier claim is required ");
|
||||
}
|
||||
|
||||
IEnumerable<Shift> shifts = this.shiftRepository.Get(x => x.EmployeeId == id.Value).AsEnumerable();
|
||||
IEnumerable<Shift> shifts = this.shiftRepository.Get(x => x.EmployeeId == id.Value && x.Start > DateTime.Now).AsEnumerable();
|
||||
if (shifts?.Any() == false)
|
||||
{
|
||||
ViewData["NoShifts"] = "You have no shifts booked.";
|
||||
}
|
||||
return View(shifts.Map());
|
||||
return View("ViewShifts", shifts.Map());
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
@ -154,6 +157,13 @@ namespace Project.Zap.Controllers
|
|||
throw new ArgumentException("http://schemas.microsoft.com/identity/claims/objectidentifier claim is required ");
|
||||
}
|
||||
|
||||
IEnumerable<Shift> bookedShifts = this.shiftRepository.Get(x => x.EmployeeId == id.Value);
|
||||
if(bookedShifts?.Where(x => x.Start.DayOfYear == viewModel.Start.DayOfYear && x.Start.Year == viewModel.Start.Year).FirstOrDefault() != null)
|
||||
{
|
||||
ViewData["ValidationError"] = "You are already booked to work on this day.";
|
||||
return await this.Index();
|
||||
}
|
||||
|
||||
Shift storeShift = this.shiftRepository.Get(x => x.StoreName == viewModel.StoreName && x.Start == viewModel.Start && x.End == viewModel.End && x.WorkType == viewModel.WorkType && x.Allocated == false).FirstOrDefault();
|
||||
|
||||
if (storeShift == null)
|
||||
|
@ -167,7 +177,7 @@ namespace Project.Zap.Controllers
|
|||
|
||||
await this.shiftRepository.Update(storeShift);
|
||||
|
||||
return await this.Index();
|
||||
return this.ViewShifts();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
|
|
@ -117,9 +117,6 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="DemoMessage" xml:space="preserve">
|
||||
<value>To get started Sign up using "123456" as the Registration Code to become a new Manager at Contoso!</value>
|
||||
</data>
|
||||
<data name="ProjectZap" xml:space="preserve">
|
||||
<value>Project ZAP</value>
|
||||
</data>
|
||||
|
|
|
@ -117,9 +117,6 @@
|
|||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="DemoMessage" xml:space="preserve">
|
||||
<value>Pour commencez, saisissez le code d'enregistrement "123456" pour devenir nouveau manager chez Contoso!</value>
|
||||
</data>
|
||||
<data name="ProjectZap" xml:space="preserve">
|
||||
<value>Projet Zap</value>
|
||||
</data>
|
||||
|
|
|
@ -7,8 +7,4 @@
|
|||
<div class="text-center">
|
||||
<h1 class="display-4">@Localizer["ProjectZap"]</h1>
|
||||
<h2>@Localizer["SubTitle"]</h2>
|
||||
|
||||
<p>
|
||||
@Localizer["DemoMessage"]
|
||||
</p>
|
||||
</div>
|
||||
|
|
Загрузка…
Ссылка в новой задаче