Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 public async Task <ClientsRole> Save(ClientsRole newData)
 {
     return(await Task.Run(async() => {
         try {
             roles = await Reader <ClientsRole> .JsonReaderListAsync(Model1FileName);
             roles.Add(newData);
             _ = await Writer <ClientsRole> .JsonWriterListAsync(roles, Model1FileName);
             return newData;
         } catch {
             return null;
         }
     }));
 }
Ejemplo n.º 3
0
 public async Task <ClientsRole> Edit(ClientsRole updatedData)
 {
     return(await Task.Run(async() => {
         try {
             roles = await Reader <ClientsRole> .JsonReaderListAsync(Model1FileName);
             if (roles.Count == 0)
             {
                 throw new Exception("No data to be update");
             }
             var old = roles.Where(a => a.Id.Equals(updatedData.Id)).FirstOrDefault();
             if (old == null)
             {
                 throw new Exception("No data to be update");
             }
             roles = roles.Where(a => !a.Id.Equals(updatedData.Id)).ToList();
             updatedData.DateUpdated = DateTime.Now;
             roles.Add(updatedData);
             _ = await Writer <ClientsRole> .JsonWriterListAsync(roles, Model1FileName);
             return old;
         } catch (Exception ex) {
             throw ex;
         }
     }));
 }