示例#1
0
 public async Task <Item> GetItemAsync(string id)
 {
     using (var uow = XpoHelper.CreateUnitOfWork()) {
         var item = uow.GetObjectByKey <Item>(id);
         return(await Task.FromResult(item));
     }
 }
示例#2
0
 public async Task <bool> AddItemAsync(Item item)
 {
     try {
         using (var uow = XpoHelper.CreateUnitOfWork()) {
             item.Id = Guid.NewGuid().ToString();
             uow.Save(item);
             uow.CommitChanges();
         }
     } catch (Exception) {
         return(await Task.FromResult(false));
     }
     return(await Task.FromResult(true));
 }
示例#3
0
 public async Task <bool> DeleteItemAsync(string id)
 {
     try {
         using (var uow = XpoHelper.CreateUnitOfWork()) {
             var itemToDelete = uow.GetObjectByKey <Item>(id);
             if (itemToDelete != null)
             {
                 uow.Delete(itemToDelete);
                 uow.CommitChanges();
             }
         }
     } catch (Exception) {
         return(await Task.FromResult(false));
     }
     return(await Task.FromResult(true));
 }
示例#4
0
 public async Task <bool> UpdateItemAsync(Item item)
 {
     try {
         using (var uow = XpoHelper.CreateUnitOfWork()) {
             var itemToUpdate = uow.GetObjectByKey <Item>(item.Id);
             if (itemToUpdate == null)
             {
                 return(await Task.FromResult(false));
             }
             itemToUpdate.Text        = item.Text;
             itemToUpdate.Description = item.Description;
             uow.Save(itemToUpdate);
             uow.CommitChanges();
         }
     } catch (Exception) {
         return(await Task.FromResult(false));
     }
     return(await Task.FromResult(true));
 }
示例#5
0
 public async Task <IEnumerable <Item> > GetItemsAsync(bool forceRefresh = false)
 {
     using (var uow = XpoHelper.CreateUnitOfWork()) {
         return(await Task.FromResult(uow.Query <Item>().OrderBy(i => i.Description).ToList()));
     }
 }
示例#6
0
 public Task <Item> GetItemAsync(string id)
 {
     using (var uow = XpoHelper.CreateUnitOfWork()) {
         return(uow.GetObjectByKeyAsync <Item>(id));
     }
 }