예제 #1
0
 public async Task<int> DeleteDataAsync(InventurItem item)
 {
     using (var db = new InventurContext())
     {
         db.InventurItems.Attach(item);
         db.InventurItems.Remove(item);
         return await db.SaveChangesAsync();
     }
 }
예제 #2
0
 public async Task<bool> SetExportedAsync()
 {
     using (var db = new InventurContext())
     {
         await db.InventurItems.Where(x => x.Exported == false).ForEachAsync<InventurItem>(y => y.Exported = true);
         var changes = await db.SaveChangesAsync();
         if (changes > 0) return true;
         return false;
     }
 }
예제 #3
0
 public async Task<List<InventurItem>> GetDataAsync()
 {
     using (var db = new InventurContext())
     {
         return await (from i in db.InventurItems
                       where i.Exported == false
                       orderby i.ChangedAt descending
                       select i).ToListAsync();
     }
 }
예제 #4
0
        //private InventurContext db = new InventurContext();*/

        public async Task<int> SaveDataAsync(InventurItem item, bool isNew = false)
        {
            using (var db = new InventurContext())
            {
                item.ChangedAt = DateTime.Now;
                if (isNew)
                {
                    item.CreatedAt = DateTime.Now;
                    db.InventurItems.Add(item);
                }
                else
                {
                    db.InventurItems.Attach(item);
                    var entry = db.Entry(item);
                    entry.Property(x => x.EANCode).IsModified = true;
                    entry.Property(x => x.ChangedAt).IsModified = true;
                    entry.Property(x => x.Amount).IsModified = true;
                }
                return await db.SaveChangesAsync();
            }
        }