public bool UpdateAsync(Campus model) { using (var conn = DapperFactory.GetConnection()) { List <string> removeFields = new List <string> { "Id", "CreateTime", "Status" }; var fields = model.ToFields(removeFields: removeFields); if (fields == null || fields.Count == 0) { return(false); } var fieldList = new List <string>(); foreach (var field in fields) { fieldList.Add(string.Format("{0}=@{0}", field)); } model.ModifyTime = DateTime.Now; string sql = string.Format("update [Campus] set {0} where Id=@Id;", string.Join(",", fieldList)); return(conn.Execute(sql, model) > 0); } }
public bool InsertAsync(Campus model) { using (var conn = DapperFactory.GetConnection()) { var fields = model.ToFields(removeFields: new List <string> { "Id" }); if (fields == null || fields.Count == 0) { return(false); } model.CreateTime = DateTime.Now; model.ModifyTime = DateTime.Now; model.Status = 1; string sql = string.Format("insert into [Campus] ({0}) values ({1});", string.Join(",", fields), string.Join(",", fields.Select(n => "@" + n))); return(conn.Execute(sql, model) > 0); } }