create implementation for Removing Transponder Association from a pilot.
pad out to prevent null reference exception in UploadPicture method. implement RemoveTransponderToken method in api.
This commit is contained in:
parent
5f07e0c3ab
commit
aff90d4e79
@ -28,8 +28,8 @@ namespace RaceLapTimer.ApiControllers
|
|||||||
|
|
||||||
private dynamic RemoveTransponderToken(dynamic args)
|
private dynamic RemoveTransponderToken(dynamic args)
|
||||||
{
|
{
|
||||||
var pilotId = args.Id;
|
var pilotId = (int)args.Id;
|
||||||
//_provider.
|
var resp = _provider.RemoveTransponderAssociation(pilotId);
|
||||||
return Context.GetRedirect("/pilots");
|
return Context.GetRedirect("/pilots");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ namespace RaceLapTimer.ApiControllers
|
|||||||
{
|
{
|
||||||
var pilotId = args.Id;
|
var pilotId = args.Id;
|
||||||
var pilot = (Pilot)_provider.GetPilot(pilotId);
|
var pilot = (Pilot)_provider.GetPilot(pilotId);
|
||||||
var oldImageName = Path.GetFileName(pilot.ImageUrl);
|
var oldImageName = Path.GetFileName(pilot.ImageUrl??string.Empty);
|
||||||
|
|
||||||
var uploadDirectory = Path.Combine(_rootPathProvider.GetRootPath(), "images");
|
var uploadDirectory = Path.Combine(_rootPathProvider.GetRootPath(), "images");
|
||||||
|
|
||||||
@ -65,9 +65,10 @@ namespace RaceLapTimer.ApiControllers
|
|||||||
pilot.ImageUrl = "/images/" + generatedFileName;
|
pilot.ImageUrl = "/images/" + generatedFileName;
|
||||||
_provider.UpdatePilot(pilot);
|
_provider.UpdatePilot(pilot);
|
||||||
|
|
||||||
|
if(!string.IsNullOrEmpty(oldImageName))
|
||||||
File.Delete(Path.Combine(uploadDirectory, oldImageName));
|
File.Delete(Path.Combine(uploadDirectory, oldImageName));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string returnurl = "/pilot/edit/" + pilotId;
|
string returnurl = "/pilot/edit/" + pilotId;
|
||||||
return Context.GetRedirect(returnurl);
|
return Context.GetRedirect(returnurl);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,7 +118,6 @@
|
|||||||
<Compile Include="Extensions\SystemControl\SystemControlManager.cs" />
|
<Compile Include="Extensions\SystemControl\SystemControlManager.cs" />
|
||||||
<Compile Include="Extensions\TransponderUtilities\TransponderUtilityManager.cs" />
|
<Compile Include="Extensions\TransponderUtilities\TransponderUtilityManager.cs" />
|
||||||
<Compile Include="Assists\AsyncHelpers.cs" />
|
<Compile Include="Assists\AsyncHelpers.cs" />
|
||||||
<Compile Include="IDbProvider.cs" />
|
|
||||||
<Compile Include="ApiControllers\LapTrackApiModule.cs" />
|
<Compile Include="ApiControllers\LapTrackApiModule.cs" />
|
||||||
<Compile Include="ApiControllers\MonitorApiModule.cs" />
|
<Compile Include="ApiControllers\MonitorApiModule.cs" />
|
||||||
<Compile Include="ApiControllers\PilotApiModule.cs" />
|
<Compile Include="ApiControllers\PilotApiModule.cs" />
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Interfaces;
|
using Interfaces;
|
||||||
using RaceLapTimer.ApiControllers;
|
|
||||||
|
|
||||||
namespace RaceLapTimer
|
namespace RaceLapTimer
|
||||||
{
|
{
|
||||||
@ -193,6 +192,15 @@ namespace RaceLapTimer
|
|||||||
return _pilots.Remove(_pilots.FirstOrDefault(x => x.Id == id));
|
return _pilots.Remove(_pilots.FirstOrDefault(x => x.Id == id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool RemoveTransponderAssociation(int pilotId)
|
||||||
|
{
|
||||||
|
if (_pilots.All(x => x.Id != pilotId))
|
||||||
|
return false;
|
||||||
|
var pilot = _pilots.First(x => x.Id == pilotId);
|
||||||
|
pilot.TransponderToken = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public int GetLastScannedId()
|
public int GetLastScannedId()
|
||||||
{
|
{
|
||||||
var rand = new Random();
|
var rand = new Random();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user