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:
chris.watts90@outlook.com 2017-06-26 21:05:19 +01:00
parent 5f07e0c3ab
commit aff90d4e79
3 changed files with 15 additions and 7 deletions

View File

@ -28,8 +28,8 @@ namespace RaceLapTimer.ApiControllers
private dynamic RemoveTransponderToken(dynamic args)
{
var pilotId = args.Id;
//_provider.
var pilotId = (int)args.Id;
var resp = _provider.RemoveTransponderAssociation(pilotId);
return Context.GetRedirect("/pilots");
}
@ -37,7 +37,7 @@ namespace RaceLapTimer.ApiControllers
{
var pilotId = args.Id;
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");
@ -65,9 +65,10 @@ namespace RaceLapTimer.ApiControllers
pilot.ImageUrl = "/images/" + generatedFileName;
_provider.UpdatePilot(pilot);
if(!string.IsNullOrEmpty(oldImageName))
File.Delete(Path.Combine(uploadDirectory, oldImageName));
}
string returnurl = "/pilot/edit/" + pilotId;
return Context.GetRedirect(returnurl);
}

View File

@ -118,7 +118,6 @@
<Compile Include="Extensions\SystemControl\SystemControlManager.cs" />
<Compile Include="Extensions\TransponderUtilities\TransponderUtilityManager.cs" />
<Compile Include="Assists\AsyncHelpers.cs" />
<Compile Include="IDbProvider.cs" />
<Compile Include="ApiControllers\LapTrackApiModule.cs" />
<Compile Include="ApiControllers\MonitorApiModule.cs" />
<Compile Include="ApiControllers\PilotApiModule.cs" />

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Interfaces;
using RaceLapTimer.ApiControllers;
namespace RaceLapTimer
{
@ -193,6 +192,15 @@ namespace RaceLapTimer
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()
{
var rand = new Random();