Exemplo n.º 1
0
        public IActionResult Get(long id)
        {
            TrainingFiles file = _dataRepository.Get(id);

            if (file == null)
            {
                return(NotFound("The record couldn't be found."));
            }
            return(Ok(file));
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
 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));
 }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
        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);
                //}
            }
        }