/// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <int> InsertAsync(KeywordsEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into Keywords (" +
                            "KeywordText," +
                            "KeywordType," +
                            "Priority," +
                            "Hits," +
                            "LastUseTime," +
                            "GeneralID," +
                            "QuoteTimes) " +
                            "values(" +
                            "@KeywordText," +
                            "@KeywordType," +
                            "@Priority," +
                            "@Hits," +
                            "@LastUseTime," +
                            "@GeneralID," +
                            "@QuoteTimes)";

            return(await Task.Run(() => _DB.ReturnID(strSQL, dict)));
        }
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Add(KeywordsEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into Keywords (" +
                            "KeywordText," +
                            "KeywordType," +
                            "Priority," +
                            "Hits," +
                            "LastUseTime," +
                            "GeneralID," +
                            "QuoteTimes) " +
                            "values(" +
                            "@KeywordText," +
                            "@KeywordType," +
                            "@Priority," +
                            "@Hits," +
                            "@LastUseTime," +
                            "@GeneralID," +
                            "@QuoteTimes)";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Example #3
0
        public Task <int> DeleteKeyWords(string id, string currentUserId, string appid, string tenantId)
        {
            KeywordsEntity entity = repo.FindEntityASync(t => t.Id == id && t.AppId == appid && t.TenantId == tenantId).Result;

            entity.DeleteMark   = true;
            entity.DeleteTime   = DateTime.Now;
            entity.DeleteUserId = currentUserId;
            return(repo.UpdateAsync(entity));
        }
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(KeywordsEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("KeywordID", entity.KeywordID);
     dict.Add("KeywordText", entity.KeywordText);
     dict.Add("KeywordType", entity.KeywordType);
     dict.Add("Priority", entity.Priority);
     dict.Add("Hits", entity.Hits);
     dict.Add("LastUseTime", entity.LastUseTime);
     dict.Add("GeneralID", entity.GeneralID);
     dict.Add("QuoteTimes", entity.QuoteTimes);
 }
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static KeywordsEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            KeywordsEntity info = new KeywordsEntity();

            info.KeywordID   = rdr.GetInt32("KeywordID");
            info.KeywordText = rdr.GetString("KeywordText");
            info.KeywordType = rdr.GetInt32("KeywordType");
            info.Priority    = rdr.GetInt32("Priority");
            info.Hits        = rdr.GetInt32("Hits");
            info.LastUseTime = rdr.GetNullableDateTime("LastUseTime");
            info.GeneralID   = rdr.GetInt32("GeneralID");
            info.QuoteTimes  = rdr.GetInt32("QuoteTimes");
            return(info);
        }
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <KeywordsEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            KeywordsEntity obj    = null;
            string         strSQL = "select top 1 * from Keywords where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(KeywordsEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Keywords SET " +
                            "KeywordText = @KeywordText," +
                            "KeywordType = @KeywordType," +
                            "Priority = @Priority," +
                            "Hits = @Hits," +
                            "LastUseTime = @LastUseTime," +
                            "GeneralID = @GeneralID," +
                            "QuoteTimes = @QuoteTimes" +
                            " WHERE " +

                            "KeywordID = @KeywordID";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Example #8
0
 public Task <int> UpdateKeyWords(KeywordsEntity entity)
 {
     return(repo.UpdateAsync(entity));
 }
Example #9
0
 public Task <int> AddKeyWords(KeywordsEntity entity)
 {
     return(repo.InsertAsync(entity));
 }
Example #10
0
 /// <summary>
 /// 增加或更新一条记录(异步方式)
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual async Task <bool> AddOrUpdateAsync(KeywordsEntity entity, bool IsSave)
 {
     return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity));
 }
Example #11
0
 /// <summary>
 /// 增加或更新一条记录
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual bool AddOrUpdate(KeywordsEntity entity, bool IsSave)
 {
     return(IsSave ? Add(entity) : Update(entity));
 }