public IActionResult Get(long id) { TrainingFiles file = _dataRepository.Get(id); if (file == null) { return(NotFound("The record couldn't be found.")); } return(Ok(file)); }
public IActionResult Delete(long id) { TrainingFiles file = _dataRepository.Get(id); if (file == null) { return(NotFound("The file record couldn't be found.")); } _dataRepository.Delete(file); return(NoContent()); }
public IActionResult Post([FromBody] TrainingFiles file) { if (file == null) { return(BadRequest("File is null.")); } _dataRepository.Add(file); return(CreatedAtRoute( "Get", new { Id = file.FileID }, file)); }
public IActionResult Put(long id, [FromBody] TrainingFiles file) { if (file == null) { return(BadRequest("File is null.")); } TrainingFiles fileToUpdate = _dataRepository.Get(id); if (fileToUpdate == null) { return(NotFound("The file record couldn't be found.")); } _dataRepository.Update(fileToUpdate, file); return(NoContent()); }
private void AddFilesToDB() { //gets local files. //TODO: need to check if Directory exists string[] fileArray = Directory.GetFiles(@"d:\Testing\"); foreach (var item in fileArray) { string fileName; string filePath; filePath = item; fileName = Path.GetFileName(filePath); //save to DB TrainingFiles fileToAdd = new TrainingFiles(); fileToAdd.FileName = fileName; fileToAdd.FilePath = filePath; //if (!System.IO.File.Exists(filePath)) //{ _dataRepository.Add(fileToAdd); //} } }