using DbCommon.BusinessCore.DbCore; using DbCommon.Enties.DbModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DbCommon.BusinessCore.BaseCore { public class FmsStockManager : FmsDbContext { public void Init() { //If no exist create datebase //Db.DbMaintenance.CreateDatabase(); if (!Db.DbMaintenance.IsAnyTable("barcodesforagv")) { //Create tables Db.CodeFirst.InitTables(typeof(FmsStock)); } } public int CountMaterial(string material) { return Db.Queryable() .Where(d => d.StockCode == material && d.Flag == 0) .Select(f => f.StockCode) .Count(); } public bool UpdateFlag(string material) { return CurrentDb.Update( d => new FmsStock() { Flag = 1, }, d => d.StockCode == material && d.Flag == 0); } public bool UpdateFlag(string[] materialArray) { return CurrentDb.Update( d => new FmsStock() { Flag = 1, }, d => materialArray.Contains(d.StockCode) && d.Flag == 0); } public bool UpdateAllFlag() { return CurrentDb.Update( d => new FmsStock() { Flag = 1, }, d => d.Flag == 0); } } }