Skip to content

Instantly share code, notes, and snippets.

@JordiCorbilla
Created September 16, 2018 13:48
Show Gist options
  • Save JordiCorbilla/ad13dbb53429e96c055deacf8ee485f0 to your computer and use it in GitHub Desktop.
Save JordiCorbilla/ad13dbb53429e96c055deacf8ee485f0 to your computer and use it in GitHub Desktop.
[Authorize(Policy = "Administrator")]
public IActionResult ListFiles(string date)
{
var model = new FilesViewModel();
DateTime day;
if (!string.IsNullOrEmpty(date))
{
day = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture);
}
else
{
day = DateTime.UtcNow;
}
string todayDate = day.ToString("yyyyMMdd");
string yesterday = day.AddDays(-1).ToString("yyyyMMdd");
string tomorrow = day.AddDays(1).ToString("yyyyMMdd");
model.Today = todayDate;
model.TodayFormat = day.ToString("dd-MMM-yyyy");
model.Yesterday = yesterday;
model.Tomorrow = tomorrow;
foreach (var item in _fileProvider.GetDirectoryContents(todayDate))
{
FileInfo f = new FileInfo(item.PhysicalPath);
model.Files.Add(new FileDetails { Name = item.Name, FullPath = item.PhysicalPath, CreationTime = f.CreationTime, Size = f.Length });
}
return View(model);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment