public void Create(InStore instroe) { using (var ctx = new LYLQEntities()) { //ctx.InStores.Add(instroe); //ctx.SaveChanges(); string sql = @"INSERT INTO InStore(Code,CreatedBy,CreatedDate,Department,Id,Number,RemainNumber,RemainTotalPrice,TotalPrice,Type,UnitPrice,UpdatedBy,UpdatedDate)VALUES( @Code,@CreatedBy,@CreatedDate,@Department,@Id,@Number,@RemainNumber,@RemainTotalPrice,@TotalPrice,@Type,@UnitPrice,@UpdatedBy,@UpdatedDate)"; List<SQLiteParameter> sqlParams = new List<SQLiteParameter>(); sqlParams.Add(new SQLiteParameter("@Code", instroe.Code)); sqlParams.Add(new SQLiteParameter("@CreatedBy", instroe.CreatedBy)); sqlParams.Add(new SQLiteParameter("@CreatedDate", instroe.CreatedDate)); sqlParams.Add(new SQLiteParameter("@Department", instroe.Department)); sqlParams.Add(new SQLiteParameter("@Id", instroe.Id)); sqlParams.Add(new SQLiteParameter("@Number", instroe.Number)); sqlParams.Add(new SQLiteParameter("@RemainNumber", instroe.RemainNumber)); sqlParams.Add(new SQLiteParameter("@RemainTotalPrice", instroe.RemainTotalPrice)); sqlParams.Add(new SQLiteParameter("@TotalPrice", instroe.TotalPrice)); sqlParams.Add(new SQLiteParameter("@Type", instroe.Type)); sqlParams.Add(new SQLiteParameter("@UnitPrice", instroe.UnitPrice)); sqlParams.Add(new SQLiteParameter("@UpdatedBy", instroe.UpdatedBy)); sqlParams.Add(new SQLiteParameter("@UpdatedDate", instroe.UpdatedDate)); ctx.Database.ExecuteSqlCommand(sql, sqlParams.ToArray()); } }
public void Update(InStore instore) { using (var ctx = new LYLQEntities()) { //var dbInsts = from dbInst in ctx.InStores // where dbInst.Id == dpt.Id // select dbInst; //var dbModelInSt = dbInsts.First(); //dbModelInSt.Code = dpt.Code; //dbModelInSt.UnitPrice = dpt.UnitPrice; //dbModelInSt.RemainNumber = dpt.RemainNumber; //dbModelInSt.RemainTotalPrice = dpt.RemainTotalPrice; //dbModelInSt.TotalPrice = dpt.TotalPrice; //dbModelInSt.Department = dpt.Department; //dbModelInSt.Type = dpt.Type; //dbModelInSt.UpdatedBy = dpt.UpdatedBy; //dbModelInSt.UpdatedDate = DateTime.Now; //ctx.SaveChanges(); string sql = @"UPDATE InStore SET Code = @Code, UnitPrice = @UnitPrice, RemainNumber = @RemainNumber, RemainTotalPrice = @RemainTotalPrice, TotalPrice = @TotalPrice, Department = @Department, Type = @Type, UpdatedBy = @UpdatedBy, UpdatedDate = @UpdatedDate WHERE Id = '" + instore.Id + "'"; List<SQLiteParameter> sqlParams = new List<SQLiteParameter>(); sqlParams.Add(new SQLiteParameter("@Code", instore.Code)); sqlParams.Add(new SQLiteParameter("@UnitPrice", instore.UnitPrice)); sqlParams.Add(new SQLiteParameter("@RemainNumber", instore.RemainNumber)); sqlParams.Add(new SQLiteParameter("@RemainTotalPrice", instore.RemainTotalPrice)); sqlParams.Add(new SQLiteParameter("@TotalPrice", instore.TotalPrice)); sqlParams.Add(new SQLiteParameter("@Department", instore.Department)); sqlParams.Add(new SQLiteParameter("@Type", instore.Type)); sqlParams.Add(new SQLiteParameter("@UpdatedBy", instore.UpdatedBy)); sqlParams.Add(new SQLiteParameter("@UpdatedDate", instore.UpdatedDate)); ctx.Database.ExecuteSqlCommand(sql, sqlParams.ToArray()); } }
public DBLayer.InStore GetDBModel(InStore dpt) { DBLayer.InStore dbInst = null; if (dpt != null) { dbInst = new DBLayer.InStore(); dbInst.Code = dpt.Code; dbInst.Id = dpt.Id; dbInst.Number = dpt.Number; dbInst.RemainNumber = dpt.RemainNumber; dbInst.RemainTotalPrice = dpt.RemainTotalPrice; dbInst.UnitPrice = dpt.UnitPrice; dbInst.TotalPrice = dpt.TotalPrice; dbInst.Department = dpt.Department; dbInst.Type = dpt.Type; dbInst.CreatedBy = dpt.CreatedBy; dbInst.CreatedDate = dpt.CreatedDate; dbInst.UpdatedBy = dpt.UpdatedBy; dbInst.UpdatedDate = dpt.UpdatedDate; } return dbInst; }