fixed re-form submission
This commit is contained in:
Родитель
a0bd483443
Коммит
9e6178a3ca
|
@ -72,7 +72,7 @@ namespace Project.Zap.Tests
|
|||
SearchShiftViewModel viewModel = new SearchShiftViewModel { Locations = new List<string> { "Contoso" }, Start = DateTime.Now };
|
||||
|
||||
// Act
|
||||
await controller.Search(viewModel);
|
||||
await controller.Index(viewModel);
|
||||
|
||||
// Assert
|
||||
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
||||
|
@ -95,7 +95,7 @@ namespace Project.Zap.Tests
|
|||
SearchShiftViewModel viewModel = new SearchShiftViewModel { Locations = new List<string> { "Contoso" }, Start = DateTime.Now };
|
||||
|
||||
// Act
|
||||
IActionResult result = await controller.Search(viewModel);
|
||||
IActionResult result = await controller.Index(viewModel);
|
||||
|
||||
// Assert
|
||||
ViewResult viewResult = Assert.IsType<ViewResult>(result);
|
||||
|
@ -121,7 +121,7 @@ namespace Project.Zap.Tests
|
|||
SearchShiftViewModel viewModel = new SearchShiftViewModel { Locations = new List<string> { "Contoso" }, Start = DateTime.Now.Add(new TimeSpan(1, 0, 0, 0)) };
|
||||
|
||||
// Act
|
||||
IActionResult result = await controller.Search(viewModel);
|
||||
IActionResult result = await controller.Index(viewModel);
|
||||
|
||||
// Assert
|
||||
ViewResult viewResult = Assert.IsType<ViewResult>(result);
|
||||
|
@ -146,7 +146,7 @@ namespace Project.Zap.Tests
|
|||
SearchShiftViewModel viewModel = new SearchShiftViewModel { Locations = new List<string> { "Contoso" }, Start = DateTime.Now };
|
||||
|
||||
// Act
|
||||
IActionResult result = await controller.Search(viewModel);
|
||||
IActionResult result = await controller.Index(viewModel);
|
||||
|
||||
// Assert
|
||||
ViewResult viewResult = Assert.IsType<ViewResult>(result);
|
||||
|
|
|
@ -47,7 +47,10 @@ namespace Project.Zap.Controllers
|
|||
this.logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index()
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index(SearchShiftViewModel search = null)
|
||||
{
|
||||
if(search == null)
|
||||
{
|
||||
IEnumerable<Location> locations = await this.locationService.Get();
|
||||
if (locations == null || !locations.Any())
|
||||
|
@ -61,6 +64,9 @@ namespace Project.Zap.Controllers
|
|||
return View("Index", viewModel);
|
||||
}
|
||||
|
||||
return await this.Search(search);
|
||||
}
|
||||
|
||||
private async Task<SearchShiftViewModel> GetShifts(IEnumerable<Location> locations)
|
||||
{
|
||||
IEnumerable<Shift> shifts = await this.shiftRepository.Get("SELECT * FROM c WHERE c.StartDateTime > @start", new Dictionary<string, object> { { "@start", DateTime.Now } });
|
||||
|
@ -79,7 +85,12 @@ namespace Project.Zap.Controllers
|
|||
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Search(SearchShiftViewModel search)
|
||||
public IActionResult OnSearch(SearchShiftViewModel search)
|
||||
{
|
||||
return RedirectToAction("Index", new { Start = search.Start.ToString("yyyy-MM-ddTHH:mm"), search.Locations, search.UseMyLocation, search.Available, search.ZipOrPostcode });
|
||||
}
|
||||
|
||||
private async Task<IActionResult> Search(SearchShiftViewModel search)
|
||||
{
|
||||
IEnumerable<Location> locations = await this.locationService.Get();
|
||||
|
||||
|
@ -89,7 +100,7 @@ namespace Project.Zap.Controllers
|
|||
{
|
||||
locationIds.AddRange(locations.Where(x => search.Locations.Contains(x.Name)).Select(x => x.id).ToList());
|
||||
}
|
||||
if(search.DistanceInMeters != null && !string.IsNullOrWhiteSpace(search.ZipOrPostcode))
|
||||
if (search.DistanceInMeters != null && !string.IsNullOrWhiteSpace(search.ZipOrPostcode))
|
||||
{
|
||||
Point point = await this.mapService.GetCoordinates(new Address { ZipOrPostcode = search.ZipOrPostcode });
|
||||
IEnumerable<Location> filteredLocations = await this.locationService.GetByDistance(point, search.DistanceInMeters.Value);
|
||||
|
@ -107,12 +118,13 @@ namespace Project.Zap.Controllers
|
|||
sql = sql + " AND ARRAY_CONTAINS(@locationIds, c.LocationId)";
|
||||
parameters.Add("@locationIds", locationIds);
|
||||
}
|
||||
IEnumerable <Shift> shifts = await this.shiftRepository.Get(sql, parameters);
|
||||
IEnumerable<Shift> shifts = await this.shiftRepository.Get(sql, parameters);
|
||||
|
||||
search.LocationNames = this.GetLocationNames(locations);
|
||||
search.Result = shifts.Map(locations).Where(x => search.Available ? x.Available > 0 : true);
|
||||
|
||||
ViewData["AzureMapsKey"] = this.configuration["AzureMapsSubscriptionKey"];
|
||||
|
||||
return View("Index", search);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
}
|
||||
|
||||
<div class="container">
|
||||
<partial name="Search" model="new Project.Zap.Models.SearchShiftViewModel { LocationNames = Model.LocationNames }" />
|
||||
<partial name="Search" model="Model ?? new Project.Zap.Models.SearchShiftViewModel { LocationNames = Model.LocationNames }" />
|
||||
</div>
|
||||
|
||||
<div id="results">
|
||||
|
@ -127,7 +127,7 @@
|
|||
|
||||
map = L.map('myMap', { layers: [roads] });
|
||||
|
||||
@if((Model.Locations == null || !Model.Locations.Any()) && string.IsNullOrEmpty(Model.ZipOrPostcode))
|
||||
@if(Model.UseMyLocation)
|
||||
{
|
||||
<text>
|
||||
map.locate({ setView: false, enableHighAccuracy: true });
|
||||
|
@ -140,7 +140,6 @@
|
|||
};
|
||||
|
||||
L.control.layers(baseMaps, null, { collapsed: false }).addTo(map);
|
||||
var count = 0.00004;
|
||||
|
||||
@foreach(var shift in Model.Result)
|
||||
{
|
||||
|
@ -166,13 +165,11 @@
|
|||
<a class="btn btn-primary text-white" asp-controller="Shifts" asp-action="Book" asp-route-LocationName="@shift.LocationName" asp-route-Start="@shift.Start.ToString("yyyy-MM-ddTHH:mm")" asp-route-End="@shift.End.ToString("yyyy-MM-ddTHH:mm")" asp-route-WorkType="@shift.WorkType">@Localizer["LinkBook"]</a>
|
||||
}`);
|
||||
|
||||
markers.push(L.marker([@shift.Point.Coordinates[0] - count, @shift.Point.Coordinates[1] - count])
|
||||
markers.push(L.marker([@shift.Point.Coordinates[0], @shift.Point.Coordinates[1]])
|
||||
.addTo(map)
|
||||
.bindPopup(popUpContent)
|
||||
.openPopup());
|
||||
|
||||
count = count - 0.00004;
|
||||
|
||||
</text>
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче