public void Create(Filter filter) { if (string.IsNullOrWhiteSpace(filter.Keywords)) { return; } var sql = @"if not exists select * from filter where userid = @userid and keywords = @keywords insert into filter(userid, keywords, importance) values(@userid, @keywords, @importance);"; var parameters = new IDataParameter[] { new MySqlParameter("@userid", filter.UserId), new MySqlParameter("@keywords", filter.Keywords), new MySqlParameter("@importance", filter.Importance), }; var returnCode = this.DbRequest.ExecuteNonQuery(this.ConnectionString, sql, parameters, CommandType.Text); }
public void Update(Filter filter) { if (string.IsNullOrWhiteSpace(filter.Keywords)) { return; } var sql = @"if exists select * from filter where id = @id and userid = @userid and not exists select * from filter where userid = @userid and keywords = @keywords update filter set keywords = @keywords, importance = @importance, updatetime = @updatetime where id = @id and userid = @userid"; var parameters = new IDataParameter[] { new MySqlParameter("@id", filter.Id), new MySqlParameter("@userid", filter.UserId), new MySqlParameter("@keywords", filter.Keywords), new MySqlParameter("@importance", filter.Importance), new MySqlParameter("@updatetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), }; var returnCode = this.DbRequest.ExecuteNonQuery(this.ConnectionString, sql, parameters, CommandType.Text); }