示例#1
0
        public async Task <IActionResult> Create(BankStatementViewModel BankStatementViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(BankStatementViewModel));
            }

            if (!await Import(BankStatementViewModel.FileUpload))
            {
                ViewData["Erro"] = "A file with the same name already exists!";
                return(View("create"));
            }

            var filename = BankStatementViewModel.FileUpload.FileName;

            var builder = _ioservice.ReadFile(filename);

            // transform
            var bank = new BankStatement();
            var ofx  = bank.Create(builder, bank.Id);

            await _bankStatementService.Save(ofx);

            ViewData["Message"] = "Send to Database";


            return(View("create"));
        }
示例#2
0
        public void TestSaveDataStoreToJson()
        {
            //given
            IDataStore <JObject> dataStore = new InMemoryDataStore <JObject>();

            dataStore.PersistPath = _dataPersistFile;
            var obj = new JObject();

            obj["key"] = "value";

            //when
            dataStore.Insert("main-key", obj);
            dataStore.Save();

            //then
            Assert.IsTrue(_ioService.Exists(_dataPersistFile));
            var content = _ioService.ReadFile(_dataPersistFile);

            Assert.AreEqual("{\"main-key\":{\"key\":\"value\"}}", content);
        }
        /// <summary>
        /// Load in-memory storage from file.
        /// </summary>
        /// <typeparam name="X"></typeparam>
        /// <param name="fullFilePath"></param>
        /// <returns></returns>
        public static InMemoryDataStore <X> Load <X>(string fullFilePath)
        {
            InMemoryDataStore <X> dataStore = new InMemoryDataStore <X>();

            dataStore.PersistPath = fullFilePath;
            IIOService  ioService = ServiceFinder.Resolve <IIOService> ();
            ILogService logger    = ServiceFinder.Resolve <ILogService> ();

            if (ioService.Exists(fullFilePath))
            {
                try {
                    string fileContent = ioService.ReadFile(fullFilePath);
                    dataStore.memoryStore = (Dictionary <string, X>)FHSyncUtils.DeserializeObject(fileContent, typeof(Dictionary <string, X>));
                } catch (Exception ex) {
                    logger.e("FHSyncClient.InMemoryDataStore", "Failed to load file " + fullFilePath, ex);
                    dataStore.memoryStore = new Dictionary <string, X> ();
                }
            }
            return(dataStore);
        }