public bool ExportToExcel() { var path = System.IO.Path.Combine(Environment.ExternalStorageDirectory.AbsolutePath, FileApp.FileDataDirectory); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var model = new AccountsFileJson { Accounts = _accountRepository.GetItems().ToList(), DocDate = DateTime.Now }; foreach (var account in model.Accounts) { account.Password = _cryptService.DecryptText(account.Password, "test"); } try { var modelJson = JsonConvert.SerializeObject(model); System.IO.File.WriteAllText(System.IO.Path.Combine(path, $"{"Passwords "}{model.DocDate.ToShortDateString()}.{"json"}"), modelJson); } catch (Exception e) { return(false); } return(true); }
public AccountsFileJson ImportFromExcel(string path) { var model = new AccountsFileJson(); try { var file = File.ReadAllText(path); model = JsonConvert.DeserializeObject <AccountsFileJson>(file); foreach (var account in model.Accounts) { account.Password = _cryptService.DecryptText(account.Password, "test"); } return(model); } catch (Exception e) { model.resultMes = "Ошибка чтения файла"; return(model); } }