Beispiel #1
0
        public virtual ActionResult Edit(string id, FileMetadataDto dto)
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            if (ModelState.IsValid)
            {
                try
                {
                    var oldPath = PhysicalPath + id.Replace("/", "\\");

                    var fileInfo = new FileInfo(oldPath);

                    string fileName = Path.GetFileNameWithoutExtension(dto.Caption) + Path.GetExtension(oldPath);
                    var    newPath  = Path.GetDirectoryName(oldPath) + "\\" + fileName;

                    if (oldPath.ToLower() != newPath.ToLower())
                    {
                        fileInfo.MoveTo(newPath);
                    }

                    System.IO.File.SetLastWriteTime(newPath, dto.CreationTime);

                    //await Service.UpdateAsync(dto, cts.Token);
                    return(RedirectToControllerDefault().WithSuccess(this, Messages.UpdateSuccessful));
                }
                catch (Exception ex)
                {
                    HandleUpdateException(ex);
                }
            }

            ViewBag.PageTitle = Title;
            ViewBag.Admin     = Admin;
            return(View("Edit", dto));
        }
 public static FileMetadata DtoToEntity(FileMetadataDto dto)
 {
     return(new FileMetadata
     {
         FileSystemId = dto.FileSystemId,
         UpdatedDate = DateTime.Now
     });
 }
Beispiel #3
0
        public Task <FileMetadataDto> GetFileById(string id)
        {
            var binaryData = _fsService.GetFile(id).Result;

            var result = new FileMetadataDto(_dataAccessReadOnlyService.Repository <FileMetadata>().Get(i => i.FileSystemId == id).First(), binaryData);

            return(Task.FromResult(result));
        }
        public IActionResult Update([FromBody] FileMetadataDto fileMetadataDto, [FromRoute] Guid fileId)
        {
            var result = _fileMetadataLogic.Update(fileMetadataDto, fileId);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Beispiel #5
0
        public FileMetadataDto GetById(Guid id)
        {
            var file = _repository.GetByFilter <FileMetadata>(f => f.Id == id);

            var fileDto = new FileMetadataDto
            {
                CourseId = file.CourseId,
                Path     = file.Path,
                FileName = file.FileName
            };

            return(fileDto);
        }
        public FileMetadataDto GetById(Guid fileEntityId)
        {
            var file = _repository.GetLastByFilter <FileMetadata>(f => f.EntityId == fileEntityId);

            var fileDto = new FileMetadataDto
            {
                EntityId = file.EntityId,
                CourseId = file.CourseId,
                Path     = file.Path,
                FileName = file.FileName
            };

            return(fileDto);
        }
Beispiel #7
0
        public FileMetadata Create(FileMetadataDto fileMetadataDto)
        {
            var newFileMetadata = new FileMetadata
            {
                Id       = Guid.NewGuid(),
                CourseId = fileMetadataDto.CourseId,
                Path     = fileMetadataDto.Path,
                FileName = fileMetadataDto.FileName
            };

            _repository.Insert(newFileMetadata);
            _repository.Save();

            return(newFileMetadata);
        }
Beispiel #8
0
        public FileMetadata Update(FileMetadataDto fileMetadataDto, Guid id)
        {
            var file = _repository.GetByFilter <FileMetadata>(c => c.Id == id);


            if (file == null)
            {
                return(null);
            }

            file.CourseId = fileMetadataDto.CourseId;
            file.Path     = fileMetadataDto.Path;

            _repository.Update(file);
            _repository.Save();

            return(file);
        }
Beispiel #9
0
        public ICollection <FileMetadataDto> GetAll()
        {
            List <FileMetadataDto> fileDtos = new List <FileMetadataDto>();

            var files = _repository.GetAll <FileMetadata>();

            foreach (var file in files)
            {
                var fileDto = new FileMetadataDto
                {
                    CourseId = file.CourseId,
                    Path     = file.Path,
                    FileName = file.FileName
                };

                fileDtos.Add(fileDto);
            }

            return(fileDtos);
        }
        public ICollection <FileMetadataDto> GetByCourseId(Guid courseEntityId)
        {
            List <FileMetadataDto> fileDtos = new List <FileMetadataDto>();

            var files = _repository.GetAll <FileMetadata>();

            foreach (var file in files)
            {
                if (file.CourseId == courseEntityId)
                {
                    var fileDto = new FileMetadataDto
                    {
                        EntityId = file.EntityId,
                        CourseId = file.CourseId,
                        Path     = file.Path,
                        FileName = file.FileName
                    };

                    fileDtos.Add(fileDto);
                }
            }

            return(fileDtos);
        }
        public FileMetadata Update(FileMetadataDto fileMetadataDto, Guid fileEntityId)
        {
            var file = _repository.GetLastByFilter <FileMetadata>(c => c.EntityId == fileEntityId);

            if (file.DeletedDate != null)
            {
                return(null);
            }

            if (file == null)
            {
                return(null);
            }

            file.Id       = Guid.NewGuid();
            file.AuthorId = Guid.NewGuid();
            file.CourseId = fileMetadataDto.CourseId;
            file.Path     = fileMetadataDto.Path;

            _repository.Insert(file);
            _repository.Save();

            return(file);
        }
 public static FileSystemViewModel DtoToViewModel(FileMetadataDto dto)
 {
     return(new FileSystemViewModel(dto));
 }
 public FileSystemViewModel(FileMetadataDto i)
 {
     FileSystemId = i.FileSystemId;
 }
        public async Task <FileMetadataDto> UploadFiles(Guid courseId, IFormFile file)
        {
            var course = _fileClassesCommunication.GetCourse(courseId);

            if (course.Result == null || course.Result.Length == 0)
            {
                return(null);
            }

            // full path to file in temp location
            FileMetadataDto result = null;

            if (file.Length > 0)
            {
                var filePath = Path.GetTempFileName();

                // copy files to temp location for checking
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                // check if files valid
                if (CheckFileValid(filePath))
                {
                    // create folder if it doesn't exists
                    if (!Directory.Exists("../files/" + courseId.ToString() + "/"))
                    {
                        Directory.CreateDirectory("../files/" + courseId.ToString() + "/");
                    }

                    var path = "../files/" + courseId.ToString() + "/";
                    // download files to server folder
                    using (var stream = new FileStream(path + file.FileName, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    // create metadatas
                    result = new FileMetadataDto
                    {
                        EntityId = Guid.NewGuid(),
                        CourseId = courseId,
                        Path     = path,
                        FileName = file.FileName
                    };



                    // delete temp files after processing
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                }
            }

            var body         = "The file '" + result.FileName + "' was added for the course '" + JObject.Parse(course.Result)["courseTitle"] + "'!";
            var notification = new Notification
            {
                Subject  = "A new file was added for one of your courses!",
                Body     = body,
                Receiver = "*****@*****.**"
            };

            await _fileNotification.SendEmail(notification);

            return(result);
        }
Beispiel #15
0
        public async Task <FileMetadataDto> UploadFiles(Guid courseId, IFormFile file, bool IsExcel, string id)
        {
            var isPost = false;
            var course = _repository.GetByFilter <Course>(x => x.Id == courseId);

            if (course == null)
            {
                isPost = true;
            }

            // full path to file in temp location
            FileMetadataDto result = null;

            if (file.Length > 0)
            {
                var filePath = Path.GetTempFileName();

                // copy files to temp location for checking
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                // check if files valid
                if (CheckFileValid(filePath))
                {
                    // create folder if it doesn't exists
                    if (!Directory.Exists("../../AcademicManagementFrontEnd/src/assets/files/" + courseId.ToString() + "/"))
                    {
                        Directory.CreateDirectory("../../AcademicManagementFrontEnd/src/assets/files/" + courseId.ToString() + "/");
                    }

                    var path = "../../AcademicManagementFrontEnd/src/assets/files/" + courseId.ToString() + "/";
                    // download files to server folder
                    using (var stream = new FileStream(path + file.FileName, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    var guid = isPost ? Guid.NewGuid() : courseId;

                    // create metadatas
                    result = new FileMetadataDto
                    {
                        CourseId = guid,
                        Path     = path,
                        FileName = file.FileName
                    };

                    if (IsExcel)
                    {
                        ImportDataFromExcel(path + file.FileName, courseId, id);
                    }

                    // delete temp files after processing
                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                }
            }

            return(result);
        }