Пример #1
0
        public async Task <IActionResult> OnPostUploadAsync(int?id)
        {
            if (id == null)
            {
                return(RedirectToPage("/Index"));
            }
            Project = await _projectContext.FindOrDefault(id.Value);

            if (Project == null)
            {
                return(RedirectToPage("/Index"));
            }

            var fileToUpload = await _uploadService.Upload(FileUpload.FormFile.FileName, FileUpload.FormFile.Length, FileUpload.FormFile.OpenReadStream(), id.Value);

            if (fileToUpload == null)
            {
                Result = "There is already file with that name in this project";
                return(Page());
            }

            await _fileContext.Add(fileToUpload);

            return(Redirect("/Projects/Details?id=" + fileToUpload.ProjectId));
        }
Пример #2
0
        public async Task <ActionResult> UploadFile([FromForm] IFormFile file, int id)
        {
            var Project = await _projectDatabase.FindOrDefault(id);

            if (Project == null)
            {
                return(NotFound("Project with this id doesn't exist!"));
            }
            var fileToUpload = await _uploadService.Upload(file.FileName, file.Length, file.OpenReadStream(), id);

            if (fileToUpload == null)
            {
                return(Conflict("There is already file with that name in this project"));
            }
            await _fileDatabase.Add(fileToUpload);

            return(NoContent());
        }