diff --git a/src/SFA.ROATP.Types/RoatpProvider.cs b/src/SFA.ROATP.Types/RoatpProvider.cs index a36ab53..ef5e5fa 100644 --- a/src/SFA.ROATP.Types/RoatpProvider.cs +++ b/src/SFA.ROATP.Types/RoatpProvider.cs @@ -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; + } + } } diff --git a/src/Sfa.Roatp.Register.Web/Controllers/DownloadController.cs b/src/Sfa.Roatp.Register.Web/Controllers/DownloadController.cs index 13ba687..bfd32b4 100644 --- a/src/Sfa.Roatp.Register.Web/Controllers/DownloadController.cs +++ b/src/Sfa.Roatp.Register.Web/Controllers/DownloadController.cs @@ -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 { @@ -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; - } } } } \ No newline at end of file diff --git a/src/Sfa.Roatp.Register.Web/Models/CsvProvider.cs b/src/Sfa.Roatp.Register.Web/Models/CsvProvider.cs index baad9c2..5687f17 100644 --- a/src/Sfa.Roatp.Register.Web/Models/CsvProvider.cs +++ b/src/Sfa.Roatp.Register.Web/Models/CsvProvider.cs @@ -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; } } } \ No newline at end of file diff --git a/src/Sfa.Roatp.Register.Web/Models/CsvProviderMapper.cs b/src/Sfa.Roatp.Register.Web/Models/CsvProviderMapper.cs index edd73d5..0a124d5 100644 --- a/src/Sfa.Roatp.Register.Web/Models/CsvProviderMapper.cs +++ b/src/Sfa.Roatp.Register.Web/Models/CsvProviderMapper.cs @@ -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;