public async Task<int> UploadPrivateNote(Note note, int userId)
        {
            var targetDirectory = string.Format("/FTP/{0}/{1}", GetFileServerRoot(userId), "Private");
            _ftpClient.GoToRootDir();
            _ftpClient.GoToOrCreatePath(targetDirectory);

            if (_ftpClient.CheckIfFileExists(note.Name))
            {
                note.Name = _ftpClient.GetNewName(note.Name);
            }

            await _ftpClient.UploadFile(new FileManager.Base.File(note.Name, note.Content));
            if ((int)_ftpClient.ServerResponse == 226)
            {
                //string tagsWithSeparator = note.Tags.Aggregate("", (current, tag) => current + string.Format("{0},", tag));
                _fileRepository.Add(new File()
                {
                    Name = note.Name,
                    Category = note.Category,
                    Path = targetDirectory,
                    Size = note.Size,
                    UploadDate = DateTime.Now,
                    IsShared = false,
                    UserId = userId,
                    FileTags = GetFileTagsWithSeparator(note.Tags)
                });
                _fileRepository.Commit();
                return 0;
            }
            return -1;
        }
 public AllNotesDetailsViewModel()
 {
     Response = new ResponseMessageViewModel();
     NoteOwner = new SimpleUserModel();
     NoteGroup = new List<SimpleGroupModel>();
     Note = new Note();
     NoteTags = new NoteTagsViewModel();
 }
        public Note DownloadNote(int noteId)
        {
            var file = _fileRepository.GetById(noteId);
            var returnNote = new Note(file);

            _ftpClient.GoToPath(file.Path);

            var downloadedFile = _ftpClient.DownloadFile(file.Name);

            returnNote.Content = downloadedFile.Content;

            return returnNote;
        }
        public async Task<ActionResult> SendFile(SendFileRequest request)
        {
            var response = request.Validate();
            if (!request.IsValid)
            {
                TempData["ResponseViewModel"] = response;
                return RedirectToAction("RetriveInfo");
            }
                
            foreach (var file in request.Files)
            {
                var fileName = Path.GetFileName(file.FileName);
                BinaryReader fileReader = new BinaryReader(file.InputStream);
                byte[] fileContent = fileReader.ReadBytes((int)file.InputStream.Length);

                Note note = new Note()
                {
                    Name = fileName,
                    Content = fileContent,
                    Size = fileContent.Length.ToString(),
                    Category = CategorySelector.GetCategory(fileName),
                    Tags = request.FileTags
                };

                if (request.FileType == "Private")
                {
                    if (await _uploadService.UploadPrivateNote(note, (int)Session["CurrentUserId"]) == 0)
                    {
                        _uploadService.SaveUpload();
                    }
                }
                else if (request.FileType == "University")
                {
                    if (await _uploadService.UploadUniversityNote(note, (int)Session["CurrentUserId"], request.UploadPath, int.Parse(request.SemesterSubjectId)) == 0)
                    {
                        _uploadService.SaveUpload();
                    }
                }
            }
            response.AddSuccess(ResourceKeyResolver.SuccessNoteUploaded);
            TempData["ResponseViewModel"] = response;

            return RedirectToAction("RetriveInfo");
        }
        public async Task<int> UploadUniversityNote(Note note, int userId, string filePath, int semesterSubjectId)
        {
            var targetDirectory = string.Format("/FTP/{0}/{1}", GetFileServerRoot(userId), filePath);
            _ftpClient.GoToRootDir();
            _ftpClient.GoToOrCreatePath(targetDirectory);

            if (_ftpClient.CheckIfFileExists(note.Name))
            {
                note.Name = _ftpClient.GetNewName(note.Name);
            }

            await _ftpClient.UploadFile(new FileManager.Base.File(note.Name, note.Content));
            if ((int)_ftpClient.ServerResponse == 226)
            {
                _fileRepository.Add(new File()
                {
                    Name = note.Name,
                    Category = note.Category,
                    Path = targetDirectory,
                    Size = note.Size,
                    UploadDate = DateTime.Now,
                    IsShared = false,
                    UserId = userId,
                    FileTags = GetFileTagsWithSeparator(note.Tags),
                    SemesterSubjectFile = new List<SemesterSubjectFile>()
                    {
                        new SemesterSubjectFile()
                        {
                            SemesterSubjectId = semesterSubjectId
                        }
                    }
                });

                _fileRepository.Commit();
                return 0;
            }
            return -1;
        }