예제 #1
0
        public AccountsController()
        {
            Model1         = new ClientsAccount().GetType().Name;
            Model1FileName = AppDataFolder + "InnerAPI\\" + Model1 + ".json";
            Model2         = new ClientsRole().GetType().Name;
            Model2FileName = AppDataFolder + "InnerAPI\\" + Model2 + ".json";
            FileChecker <ClientsRole> .AutoCreateIfNotExists(Model2FileName);

            FileChecker <ClientsAccount> .AutoCreateIfNotExists(Model1FileName);
        }
예제 #2
0
 public async Task <ClientsAccount> Save(ClientsAccount newData)
 {
     return(await Task.Run(async() => {
         try {
             accounts = await Reader <ClientsAccount> .JsonReaderListAsync(Model1FileName);
             accounts.Add(newData);
             _ = await Writer <ClientsAccount> .JsonWriterListAsync(accounts, Model1FileName);
             return newData;
         } catch {
             return newData;
         }
     }));
 }
예제 #3
0
 public async Task <ClientsAccount> Edit(ClientsAccount updatedData)
 {
     return(await Task.Run(async() => {
         try {
             accounts = await Reader <ClientsAccount> .JsonReaderListAsync(Model1FileName);
             if (accounts.Count == 0)
             {
                 throw new Exception("No data to be update");
             }
             var old = accounts.Where(a => a.Id.Equals(updatedData.Id)).ToList();
             if (old == null)
             {
                 throw new Exception("No data to be update");
             }
             accounts = accounts.Where(a => !a.Id.Equals(updatedData.Id)).ToList();
             updatedData.DateUpdated = DateTime.Now;
             accounts.Add(updatedData);
             _ = await Writer <ClientsAccount> .JsonWriterListAsync(accounts, Model1FileName);
             return updatedData;
         } catch {
             return null;
         }
     }));
 }