public IActionResult UploadAssignmentFile([FromBody] FileAssignment fileAssignment) { try { return(Ok(_gradeservice.UploadAssignmentFile(fileAssignment))); } catch (Exception e) { return(BadRequest("Error uploading file")); } }
// Uploads the assignment to the server public async Task <FileAssignment> UploadAssignmentFile(FileAssignment fileAssignment) { try { fileAssignment = await _httpClient.PostJsonAsync <FileAssignment>("api/grade/fileAssignmentUpload", fileAssignment); return(fileAssignment); } catch (Exception e) { return(null); } }
// Takes in a fileAssignment and writes creates the file on the server and returns the url. public FileAssignment UploadAssignmentFile(FileAssignment fileAssignment) { // Save assignment on the server and update the Url in the FileAssignment object and pass it back string cwd = Directory.GetCurrentDirectory(); //Store only the AssignmentFiles and filename in the database fileAssignment.URL = "\\" + "AssignmentFiles\\" + fileAssignment.Name; // Add in the current working directory to save the file on the server var path = cwd + fileAssignment.URL; File.WriteAllBytes(path, fileAssignment.Data); return(fileAssignment); }