コード例 #1
0
        private async void newFolder()
        {
            var result = await((MetroWindow)System.Windows.Application.Current.MainWindow).ShowInputAsync("Input the folder's name", "");

            if (result == null || result.Length == 0)
            {
                return;
            }
            int currentFolder = NavFolder.ElementAt(NavFolder.Count - 1).Key;
            int resultCode    = await Utils.NetUtils.createNewFolder(result, currentFolder);

            if (resultCode == -1)
            {
                await((MetroWindow)System.Windows.Application.Current.MainWindow).ShowMessageAsync("", "Error");
            }
            else
            {
                await((MetroWindow)System.Windows.Application.Current.MainWindow).ShowMessageAsync("", "Success!");
                UserFileModel model = new UserFileModel();
                model.file_name  = result;
                model.id         = resultCode;
                model.created_at = DateTime.Now.ToString();
                FolderData.Add(model);
                Data.Add(model);
            }
        }
コード例 #2
0
        public List <ReadUserModel> Parse(string filePath, FilesImportStatistic importStatistic)
        {
            using (var csv = new CsvReader(new StreamReader(filePath), _configuration))
            {
                csv.Context.RegisterClassMap(_map);

                var users = new List <ReadUserModel>();
                csv.Read();
                csv.ReadHeader();

                csv.ValidateHeader(typeof(UserFileModel));

                while (csv.Read())
                {
                    string currentCsvRow = csv.Context.Parser.RawRecord;
                    try
                    {
                        UserFileModel user = csv.GetRecord <UserFileModel>();
                        users.Add(new ReadUserModel(user, currentCsvRow));

                        importStatistic.TotalCount++;
                    }
                    catch (Exception ex)
                    {
                        string message = $"Can't parse user. Line: '{currentCsvRow}.' {ex.Message}";
                        importStatistic.Errors.Add(message);
                        //LogHolder.MainLog.Error(ex, message);
                    }
                }

                return(users);
            }
        }
コード例 #3
0
        public async Task <UserModel> RegisterAsync(UserModel user, UserFileModel userFile)
        {
            if (!_userRepository.CheckExists(user.Email))
            {
                UserModel userAdded = await _userRepository.AddUserAsync(user);

                if (userAdded != null)
                {
                    userFile.UserId = userAdded.Id;
                    UserFileModel userFileAdded = await _userRepository.AddUserFileAsync(userFile);

                    if (userFileAdded != null)
                    {
                        return(userAdded);
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(null);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        private async void changeFolder(UserFileModel file)
        {
            NavFolder.Add(new KeyValuePair <int, string>(file.id, file.file_name));
            Data = await Utils.NetUtils.GetFilesAndFoldersById(file.id);

            spliteData();
        }
コード例 #5
0
        public async Task <UserFileModel> AddUserFileAsync(UserFileModel userFileSubscriber)
        {
            UserFile userToAdd = _mapper.Map <UserFile>(userFileSubscriber);

            _userDbContext.UserFiles.Add(userToAdd);
            await _userDbContext.SaveChangesAsync();

            return(_mapper.Map <UserFileModel>(userToAdd));
        }
コード例 #6
0
 private void showDetailedFolder(UserFileModel file)
 {
     ChoosenFile = file;
     log(file.is_encrypted);
     IsDetailedInfoOpen         = true;
     _canceled                  = true;
     ChoosenFileEncryptionState = file.is_encrypted;
     OnPropertyChanged("ChoosenFolderName");
     OnPropertyChanged("ChoosenFile");
 }
コード例 #7
0
        public async Task <ActionResult <UserFileDTO> > GetUserFileById(Guid userCardId)
        {
            UserFileModel file = await _userService.GetUserFileById(userCardId);

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


            return(_mapper.Map <UserFileDTO>(file));
        }
コード例 #8
0
        public IActionResult FilePage(long fileId)
        {
            HostingFile file = _hostingCore.GetFileById(fileId);

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

            var userFileInfo = new UserFileModel
            {
                File = file,
                User = _hostingCore.GetUserById(file.AuthorId)
            };

            return(View(userFileInfo));
        }
コード例 #9
0
        private async void share(UserFileModel file)
        {
            bool result = await Utils.NetUtils.shareFile(file.id);

            if (result)
            {
                MessageDialogResult msg = await((MetroWindow)System.Windows.Application.Current.MainWindow)
                                          .ShowMessageAsync("Success!", "已分享,链接为" + App.URL + "/shared/" + file.id + " 点击确认复制链接", MessageDialogStyle.AffirmativeAndNegative);

                if ("Affirmative".Equals(msg.ToString()))
                {
                    System.Windows.Forms.Clipboard.SetDataObject(App.URL + "/shared/" + file.id);
                }
            }
            else
            {
                showAlertDialog("分享失败!");
            }
        }
コード例 #10
0
        private async void download(UserFileModel file)
        {
            Stream stream = await Utils.NetUtils.downloadFile(file.id);

            if (null == stream)
            {
                return;
            }
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            DialogResult        result = dialog.ShowDialog();

            if (DialogResult.OK == result)
            {
                string folderName   = dialog.SelectedPath;
                string fullFilePath = string.Format("{0}{1}", folderName, file.file_name);
                Stream temp         = File.Create(fullFilePath);
                stream.CopyTo(temp);
                temp.Dispose();
                showSuccessDialog("Downloaded!");
            }
        }
コード例 #11
0
        public async Task <ActionResult <bool> > Register(SubscriberDTO userRegister)
        {
            UserModel     userToRegister     = _mapper.Map <UserModel>(userRegister);
            UserFileModel userFileToRegister = _mapper.Map <UserFileModel>(userRegister);
            UserModel     newUser            = await _userService.RegisterAsync(userToRegister, userFileToRegister);

            if (newUser == null)
            {
                Log.Information("User with email {@email} requested to create but already exists", userRegister.Email);
                throw new Exception("Bad Request: Patient with email ${ userRegister.Email } requested to create but already exists");
                //   throw new HttpResponseException(HttpStatusCode.NotFound);
                // return BadRequest($"patient with id:{newPatient.PatientId} already exists");
            }



            else
            {
                Log.Information("User with email {@email} created successfully", newUser.Email);
                return(StatusCode((int)HttpStatusCode.Created));
            }
        }