public void Create(Stock stock) { using (var ctx = new LYLQEntities()) { string sql = @"INSERT INTO Stock(Code,CreatedBy,CreatedDate,Department,Id,InstoreId,Number,TotalPrice,Type,UnitPrice,UpdatedBy,UpdatedDate)VALUES( @Code,@CreatedBy,@CreatedDate,@Department,@Id,@InstoreId,@Number,@TotalPrice,@Type,@UnitPrice,@UpdatedBy,@UpdatedDate)"; List<SQLiteParameter> sqlParams = new List<SQLiteParameter>(); sqlParams.Add(new SQLiteParameter("@Code", stock.Code)); sqlParams.Add(new SQLiteParameter("@CreatedBy", stock.CreatedBy)); sqlParams.Add(new SQLiteParameter("@CreatedDate", stock.CreatedDate)); sqlParams.Add(new SQLiteParameter("@Department", stock.Department)); sqlParams.Add(new SQLiteParameter("@Id", stock.Id)); sqlParams.Add(new SQLiteParameter("@InstoreId", stock.InstoreId)); sqlParams.Add(new SQLiteParameter("@Number", stock.Number)); sqlParams.Add(new SQLiteParameter("@TotalPrice", stock.TotalPrice)); sqlParams.Add(new SQLiteParameter("@Type", stock.Type)); sqlParams.Add(new SQLiteParameter("@UnitPrice", stock.UnitPrice)); sqlParams.Add(new SQLiteParameter("@UpdatedBy", stock.UpdatedBy)); sqlParams.Add(new SQLiteParameter("@UpdatedDate", stock.UpdatedDate)); ctx.Database.ExecuteSqlCommand(sql, sqlParams.ToArray()); } }
public void Update(Stock stock) { using (var ctx = new LYLQEntities()) { string sql = @"UPDATE Stock SET Number = @Number, TotalPrice = @TotalPrice, UpdatedBy = @UpdatedBy, UpdatedDate = @UpdatedDate WHERE Id = '" + stock.Id + "'"; List<SQLiteParameter> sqlParams = new List<SQLiteParameter>(); sqlParams.Add(new SQLiteParameter("@Number", stock.Number)); sqlParams.Add(new SQLiteParameter("@TotalPrice", stock.TotalPrice)); sqlParams.Add(new SQLiteParameter("@UpdatedBy", stock.UpdatedBy)); sqlParams.Add(new SQLiteParameter("@UpdatedDate", stock.UpdatedDate)); ctx.Database.ExecuteSqlCommand(sql, sqlParams.ToArray()); } }
public DBLayer.Stock GetDBModel(Stock stock) { DBLayer.Stock dbStock = null; if (stock != null) { dbStock = new DBLayer.Stock(); dbStock.Code = stock.Code; dbStock.Id = stock.Id; dbStock.InstoreId = stock.InstoreId; dbStock.Number = stock.Number; dbStock.UnitPrice = stock.UnitPrice; dbStock.TotalPrice = stock.TotalPrice; dbStock.Department = stock.Department; dbStock.Type = stock.Type; dbStock.CreatedBy = stock.CreatedBy; dbStock.CreatedDate = stock.CreatedDate; dbStock.UpdatedBy = stock.UpdatedBy; dbStock.UpdatedDate = stock.UpdatedDate; } return dbStock; }