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(); //} using (var command = new SQLiteCommand($"select * from {TABNAME} where Exported=0 orderby ChangedAt DESC", _dbTool.ConnectDb())) { using (var reader = await command.ExecuteReaderAsync()) { var items = new List<InventurItem>(); if (await reader.ReadAsync()) { while (await reader.ReadAsync()) { var i = new InventurItem { ID = Convert.ToInt32(reader["ID"]), CreatedAt = Convert.ToDateTime(reader["CreatedAt"]), ChangedAt = Convert.ToDateTime(reader["ChangedAt"]), EANCode = reader["EANCode"].ToString(), Amount = Convert.ToInt32(reader["Amount"]), Exported = Convert.ToBoolean(reader["Exported"]) }; items.Add(i); } } return items; } } }
public Task<int> SaveDataAsync(InventurItem item, bool isNew = false) { return Task.Factory.StartNew(() => { item.ChangedAt = DateTime.Now; item.Exported = false; using (var db = new LiteDatabase(dbName)) { var col = db.GetCollection<InventurItem>(tabName); if (isNew) { //Zuerst prüfen ob es bereits einen Eintrag gibt var existing = col.Find(x => x.EANCode == item.EANCode && x.Exported == false).FirstOrDefault(); if (existing != null) { existing.Amount += item.Amount; existing.ChangedAt = item.ChangedAt; col.Update(existing); } else { item.CreatedAt = DateTime.Now; var res = col.Insert(item); } } else { col.Update(item); } return 1; } }); }
public async Task<int> DeleteDataAsync(InventurItem item) { using (var db = new InventurContext()) { db.InventurItems.Attach(item); db.InventurItems.Remove(item); return await db.SaveChangesAsync(); } }
public InventurItemViewModel(IDataService dataService, InventurItem item, bool update = true) { _item = item; _update = update; _dataService = dataService; ArticleId = _item.EANCode; Piece = _item.Amount.ToString(); }
public async Task<int> DeleteDataAsync(InventurItem item) { //using (var db = new InventurContext()) //{ // db.InventurItems.Attach(item); // db.InventurItems.Remove(item); // return await db.SaveChangesAsync(); //} var command = new SQLiteCommand($"delete from {TABNAME} where ID={item.ID}", _dbTool.ConnectDb()); return await command.ExecuteNonQueryAsync(); }
public Task<int> DeleteDataAsync(InventurItem item) { return Task.Factory.StartNew(() => { using (var db = new LiteDatabase(dbName)) { var col = db.GetCollection<InventurItem>(tabName); var res = col.Delete(x => x.Id == item.Id); return res; } }); }
//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(); } }
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(); //} SQLiteCommand command; item.ChangedAt = DateTime.Now; if (isNew) { item.CreatedAt = DateTime.Now; command = new SQLiteCommand($"insert into {TABNAME} (CreatedAt, ChangedAt, EANCode, Amout, Exported) values ({item.CreatedAt}, {item.ChangedAt}, {item.EANCode}, {item.Amount}, 0)", _dbTool.ConnectDb()); return await command.ExecuteNonQueryAsync(); } else { command = new SQLiteCommand($"update {TABNAME} set EANCode={item.EANCode}, ChangedAt={item.ChangedAt}, Amount={item.Amount} where ID={item.ID}", _dbTool.ConnectDb()); return await command.ExecuteNonQueryAsync(); } }
public InventurItemViewModel(IDataService dataService) { _dataService = dataService; _item = new InventurItem(); //ArticleId = String.Empty; //Piece = String.Empty; }