Example #1
0
     public static string Edit(HttpContext context) {
         if (string.IsNullOrEmpty(App.UserID))
             throw new AuthenticationException("用户未登录");
         string id = context.Request.Form["_id"].ToStringExt();
         if (string.IsNullOrEmpty(id))
             throw new ArgumentNullException("id", "缺少参数_id");
      
         string name = context.Request.Form["name"];
         string sex = context.Request.Form["sex"];
         string birthday = context.Request.Form["birthday"];
         string email = context.Request.Form["email"];
         Where @where = new Where(new Where.Item("ID", "=", id));
 
         FreedomDB.Bridge.Update update = new Update();
         update.Dic = new Dictionary<string, dynamic>() {
             {"Email", email},
             {"Birthday", birthday.StrToDateTime(DateTime.MaxValue)},
             {"Name", name},
             {"Sex", sex.ToInt(0)}
         };
         update.WhereCore = where;
         bool success = Bll.User_Bll.UpdateUser(update);
         ApiInfo apiInfo = new ApiInfo(SystemCode.Error, "更新失败");
         if (success) {
             apiInfo = new ApiInfo(SystemCode.Success, "更新成功");
         }
         return apiInfo.ToJson();
     }
Example #2
0
        public bool Update(Update update) {
            Dictionary<string, dynamic> dic = update.Dic;
            string where = update.WhereCore.Result;
            string fv = string.Join(",", dic.Select(pair => $"{pair.Key}=@{pair.Key}"));


            string sql = $"update {Table} set {fv} where {where};";
            using (SqlCommand command = new DbHelper().Command) {
                command.CommandText = sql;
                int ret = command.ExecuteNonQueryExt(sql, update);
                return ret > 0;
            }
        }
Example #3
0
 public static async Task<bool> UpdateUser(Update update) {
     return await Task<bool>.Factory.StartNew(() => Dal.Update(update));
 }
Example #4
0
 /// <summary>
 /// 生成 update sqlparameter参数
 /// </summary>
 /// <param name="command"></param>
 /// <param name="update"></param>
 /// <returns></returns>
 public static SqlParameter[] CreateUpdateSqlParams(this IDbCommand command,Update update) {
     Dictionary<string, dynamic> dic = update.Dic;
     List<SqlParameter> parameters = dic.Select(pair => new SqlParameter($"@{pair.Key}", pair.Value)).ToList();
     Where where = update.WhereCore;
     List<Where.Item> items = where.WhereItems;
     parameters.AddRange(items.Select(item => new SqlParameter($"@{item.Field}", item.Value)));
     return parameters.ToArray();
 }
Example #5
0
 public static bool UpdateUser(Update update) {
     return Dal.Update(update);
 }