public void Create(Department dpt) { using (var ctx = new LYLQEntities()) { //ctx.Departments.Add(dpt); //ctx.SaveChanges(); string sql = @"INSERT INTO Department(Code,CreatedBy,CreatedDate,Name,Type,UpdatedBy,UpdatedDate)VALUES( @Code,@CreatedBy,@CreatedDate,@Name,@Type,@UpdatedBy,@UpdatedDate)"; List<SQLiteParameter> sqlParams = new List<SQLiteParameter>(); sqlParams.Add(new SQLiteParameter("@Code", dpt.Code)); sqlParams.Add(new SQLiteParameter("@CreatedBy", dpt.CreatedBy)); sqlParams.Add(new SQLiteParameter("@CreatedDate", dpt.CreatedDate)); sqlParams.Add(new SQLiteParameter("@Name", dpt.Name)); sqlParams.Add(new SQLiteParameter("@Type", dpt.Type)); sqlParams.Add(new SQLiteParameter("@UpdatedBy", dpt.UpdatedBy)); sqlParams.Add(new SQLiteParameter("@UpdatedDate", dpt.UpdatedDate)); ctx.Database.ExecuteSqlCommand(sql, sqlParams.ToArray()); } }
public void Update(Department dpt) { using (var ctx = new LYLQEntities()) { //var dbDpts = from dbDpt in ctx.Departments // where dbDpt.Code == dpt.Code // select dbDpt; //var dbModelDpt = dbDpts.First(); //dbModelDpt.Name = dpt.Name; //dbModelDpt.UpdatedBy = dpt.UpdatedBy; //dbModelDpt.UpdatedDate = DateTime.Now; //ctx.SaveChanges(); string sql = @"UPDATE Department SET Name = @Name, UpdatedBy = @UpdatedBy, UpdatedDate = @UpdatedDate WHERE Code = '" + dpt.Code + "'"; List<SQLiteParameter> sqlParams = new List<SQLiteParameter>(); sqlParams.Add(new SQLiteParameter("@Name", dpt.Name)); sqlParams.Add(new SQLiteParameter("@UpdatedBy", dpt.UpdatedBy)); sqlParams.Add(new SQLiteParameter("@UpdatedDate", dpt.UpdatedDate)); ctx.Database.ExecuteSqlCommand(sql, sqlParams.ToArray()); } }
public DBLayer.Department GetDBModel(Department dpt) { DBLayer.Department dbDpt = null; if (dpt != null) { dbDpt = new DBLayer.Department(); dbDpt.Code = dpt.Code; dbDpt.Name = dpt.Name; dbDpt.CreatedBy = dpt.CreatedBy; dbDpt.CreatedDate = dpt.CreatedDate; dbDpt.UpdatedBy = dpt.UpdatedBy; dbDpt.UpdatedDate = dpt.UpdatedDate; dbDpt.Type = dpt.Type; } return dbDpt; }