Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #4 from SkillsFundingAgency/feature/CI-203_remove_…
Browse files Browse the repository at this point in the history
…dates_in_csv

CI-203 adding logic to filter providers that appear in the CSV
  • Loading branch information
scottcowan authored Apr 11, 2017
2 parents df5aed0 + 26482a6 commit b75c4b1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
16 changes: 16 additions & 0 deletions src/SFA.ROATP.Types/RoatpProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,21 @@ public class RoatpProvider
public DateTime? StartDate { get; set; }

public DateTime? EndDate { get; set; }

public bool IsDateValid(DateTime currenDate)
{
if (StartDate == null)
{
return false;
}

if (StartDate.Value.Date <= currenDate.Date && currenDate.Date <= EndDate)
{
return true;
}

return StartDate.Value.Date <= currenDate.Date && EndDate == null;
}

}
}
29 changes: 11 additions & 18 deletions src/Sfa.Roatp.Register.Web/Controllers/DownloadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Sfa.Roatp.Register.Core.Models;
using Sfa.Roatp.Register.Core.Services;
using Sfa.Roatp.Register.Web.Models;
using SFA.ROATP.Types;

namespace Sfa.Roatp.Register.Web.Controllers
{
Expand All @@ -29,30 +30,22 @@ public ActionResult Index()

public ActionResult Csv()
{
try
{
var providers = _getProviders.GetAllProviders();
var result = providers.Select(CsvProviderMapper.Map);
var providers = _getProviders.GetAllProviders().Where(x => x.IsDateValid(DateTime.UtcNow));
var result = providers.Select(CsvProviderMapper.Map);

using (var memoryStream = new MemoryStream())
using (var memoryStream = new MemoryStream())
{
using (var streamWriter = new StreamWriter(memoryStream))
{
using (var streamWriter = new StreamWriter(memoryStream))
using (var csvWriter = new CsvWriter(streamWriter))
{
using (var csvWriter = new CsvWriter(streamWriter))
{
csvWriter.WriteRecords(result);
streamWriter.Flush();
memoryStream.Position = 0;
return File(memoryStream.ToArray(), "text/csv", $"roatp-{DateTime.Today.ToString("yyyy-MM-dd")}.csv");
}
csvWriter.WriteRecords(result);
streamWriter.Flush();
memoryStream.Position = 0;
return File(memoryStream.ToArray(), "text/csv", $"roatp-{DateTime.UtcNow.ToString("yyyy-MM-dd")}.csv");
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
}
4 changes: 0 additions & 4 deletions src/Sfa.Roatp.Register.Web/Models/CsvProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ public class CsvProvider
public bool ParentCompanyGuarantee { get; set; }

public bool NewOrganisationWithoutFinancialTrackRecord { get; set; }

public string StartDate { get; set; }

public string EndDate { get; set; }
}
}
4 changes: 1 addition & 3 deletions src/Sfa.Roatp.Register.Web/Models/CsvProviderMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public static CsvProvider Map(RoatpProvider provider)
Name = provider.Name,
ProviderType = Enumerations.GetEnumDescription(provider.ProviderType),
NewOrganisationWithoutFinancialTrackRecord = provider.NewOrganisationWithoutFinancialTrackRecord,
ParentCompanyGuarantee = provider.ParentCompanyGuarantee,
StartDate = FormatDate(provider.StartDate),
EndDate = FormatDate(provider.EndDate)
ParentCompanyGuarantee = provider.ParentCompanyGuarantee
};

return csvProvider;
Expand Down

0 comments on commit b75c4b1

Please sign in to comment.