public async Task <IActionResult> AddNewDocument(DocumentModel documentModel) { if (documentModel.ScopeDocument != null) { string folder = "projects/ScopeDocument/"; folder += Guid.NewGuid().ToString() + " " + documentModel.ScopeDocument.FileName; documentModel.ScopeDocumentUrl = "/" + folder; string serverFolder = Path.Combine(_webHostEnvironment.WebRootPath, folder); await documentModel.ScopeDocument.CopyToAsync(new FileStream(serverFolder, FileMode.Create)); } else if (documentModel.ActionPlan != null) { string folder = "projects/ActionPlan/"; folder += Guid.NewGuid().ToString() + " " + documentModel.ActionPlan.FileName; documentModel.ActionPlanUrl = "/" + folder; string serverFolder = Path.Combine(_webHostEnvironment.WebRootPath, folder); await documentModel.ActionPlan.CopyToAsync(new FileStream(serverFolder, FileMode.Create)); } else { string folder = "projects/TimePlan/"; folder += Guid.NewGuid().ToString() + " " + documentModel.TimePlan.FileName; documentModel.TimePlanUrl = "/" + folder; string serverFolder = Path.Combine(_webHostEnvironment.WebRootPath, folder); await documentModel.TimePlan.CopyToAsync(new FileStream(serverFolder, FileMode.Create)); } int id = await _documentRepository.AddNewDocument(documentModel); if (id > 0) { return(RedirectToAction(nameof(AddNewDocument), new { isSuccess = true, projectId = documentModel.ProjectsID })); } ViewBag.projects = new SelectList(await _projectRepository.GetProjects(), "ID", "Title"); ViewData["Document"] = await _documentRepository.GetDocument(documentModel.ProjectsID); return(View()); }