Beispiel #1
0
        public IActionResult ReceiveFile([FromRoute] Guid id, [FromBody] DownloadReceiveViewModel param)
        {
            if (ModelState.IsValid)
            {
                // Create file from uploaded script
                string scriptLocation = string.Format(@"{0}/Downloads/{1}", _hostingEnv.ContentRootPath, id);
                System.IO.File.WriteAllBytes(scriptLocation, param.Content);

                // Add database entry for new script
                Download download = new Download
                {
                    Id           = id,
                    ComputerName = param.ComputerName,
                    Name         = param.Name,
                    FullPath     = param.FullPath,
                    DownloadTime = DateTime.UtcNow,
                    ModifiedTime = param.ModifiedTime,
                    AccessedTime = param.AccessedTime,
                    BornTime     = DateTime.UtcNow
                };
                _context.Downloads.Add(download);
                _context.SaveChanges();

                return(Ok(download));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Beispiel #2
0
        public IActionResult ReceiveFile([FromRoute] Guid id, [FromBody] DownloadReceiveViewModel param)
        {
            if (ModelState.IsValid)
            {
                _context.Downloads.Add(new Download {
                    Id           = id,
                    ComputerName = param.ComputerName,
                    Name         = param.Name,
                    FullPath     = param.FullPath,
                    Content      = param.Content,
                    DownloadTime = DateTime.UtcNow
                });
                _context.SaveChanges();

                return(Ok(param.FullPath));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }