public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId) { var req = acceptParam.AnalyzeParam <KeyReq <int> >(); if (req == null || req.Key <= 0) { return(ResultModel.GetParamErrorModel()); } var conn = appSetting.GetMysqlConn(context); var result = await DapperTools.Edit(conn, EntityTools.GetTableName <AttentionInfo>(), new[] { $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))}={req.Key}", $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))}={userId}", $"{nameof(BaseModel.ValidFlag)}={(int)ValidFlagMenu.UnUseFul}" }, new[] { $"{nameof(BaseModel.ValidFlag)}=@{nameof(BaseModel.ValidFlag)}", $"{nameof(BaseModel.UpdateTime)}=@{nameof(BaseModel.UpdateTime)}", }, new { ValidFlag = ValidFlagMenu.UnUseFul, UpdateTime = DateTime.Now, }); return(ResultModel.GetSuccessModel(result)); }
public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId) { var req = acceptParam.AnalyzeParam <KeyReq <long> >(); if (req == null || req.Key <= 0) { return(ResultModel.GetParamErrorModel()); } var dbConnection = appSetting.GetMysqlConn(context); var result = await DapperTools.Edit(dbConnection, EntityTools.GetTableName <ArticleInfo>(), new[] { $"{EntityTools.GetField<BaseModel>(nameof(BaseModel.Id))} = {req.Key} ", $"{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))} = {userId}", }, new[] { $"{nameof(BaseModel.ValidFlag)} = {((int) ValidFlagMenu.UnUseFul)}", $"{nameof(BaseModel.UpdateTime)} = @{nameof(BaseModel.UpdateTime)}" }, new { UpdateTime = DateTime.Now }); // var result = await dbConnection.ExecuteAsync($@" //{SqlCharConst.UPDATE} {EntityTools.GetTableName<ArticleInfo>()} //{SqlCharConst.SET} {EntityTools.GetField<BaseModel>(nameof(BaseModel.ValidFlag))} = {((int) ValidFlagMenu.UseFul)} //{SqlCharConst.WHERE} {EntityTools.GetField<BaseModel>(nameof(BaseModel.Id))} = {req.Key} //{SqlCharConst.AND} {EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))} = {userId} //"); return(ResultModel.GetSuccessModel(result)); }
public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId) { var updateUserDto = acceptParam.AnalyzeParam <UpdateUserReq>(); if (updateUserDto == null) { return(ResultModel.GetNullErrorModel()); } var msg = updateUserDto.ValidInfo(); if (msg != string.Empty) { return(ResultModel.GetParamErrorModel(msg)); } var dbConnection = appSetting.GetMysqlConn(context); var result = await DapperTools.Edit(dbConnection, EntityTools.GetTableName <UserInfo>(), new List <string>() { $"{nameof(BaseModel.Id)} = {userId}" }, null, updateUserDto); // var result = await dbConnection.ExecuteAsync($@" //{SqlCharConst.UPDATE} {EntityTools.GetTableName<UserInfo>()} //{SqlCharConst.SET} {string.Join(",", updateUserDto.GetType().GetProperties().Select(u => $"{u.Name} = @{u.Name}"))} //{SqlCharConst.WHERE} {nameof(BaseModel.Id)} = {userId} //",updateUserDto); return(ResultModel.GetSuccessModel(result)); }
public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context) { var req = acceptParam.AnalyzeParam <KeyReq <long> >(); if (req == null || req.Key <= 0) { return(ResultModel.GetParamErrorModel()); } var conn = appSetting.GetMysqlConn(context); var pageViewField = EntityTools.GetField <ArticleInfo>(nameof(ArticleInfo.PageView)); var result = await DapperTools.Edit(conn, EntityTools.GetTableName <ArticleInfo>(), new[] { $"{nameof(BaseModel.Id)} = {req.Key}" }, new [] { $"{pageViewField} = {pageViewField} + 1" }, null); return(ResultModel.GetSuccessModel(result)); }
public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId) { var req = acceptParam.AnalyzeParam <AttentionUserReq>(); if (req == null) { return(ResultModel.GetNullErrorModel()); } var msg = req.ValidInfo(); if (msg != string.Empty) { return(ResultModel.GetParamErrorModel(msg)); } if (req.AttentionUser == userId) { return(ResultModel.GetParamErrorModel()); } var conn = appSetting.GetMysqlConn(context); AttentionInfo oldInfo = await DapperTools.GetItem <AttentionInfo>(conn, EntityTools.GetTableName <AttentionInfo>(), new[] { $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))} ={req.AttentionUser}", $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))} ={userId}", }, new[] { nameof(BaseModel.Id), }); // var isExists = await DapperTools.IsExists(conn, EntityTools.GetTableName<AttentionInfo>(), // new[] // { // $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))} ={req.AttentionUser}", // $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))} ={userId}", // }); if (oldInfo == null) { var param = (CreateAttentionParam)req; param.UserId = userId; var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName <AttentionInfo>(), param); return(ResultModel.GetSuccessModel(result)); } else { var editParam = new { UpdateTime = DateTime.Now, ValidFlag = (int)ValidFlagMenu.UseFul, req.Description, req.GroupKey, }; var setFieldList = new List <string>(); setFieldList.Add(nameof(BaseModel.UpdateTime)); setFieldList.Add(nameof(BaseModel.ValidFlag)); var result = await DapperTools.Edit(conn, EntityTools.GetTableName <AttentionInfo>(), new[] { $"{nameof(BaseModel.Id)}={oldInfo.Id}" }, null, editParam); return(ResultModel.GetSuccessModel(result)); } }
public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId) { var req = acceptParam.AnalyzeParam <SingleActionArticleReq>(); if (req == null) { return(ResultModel.GetNullErrorModel()); } string msg; if ((msg = req.ValidInfo()) != string.Empty) { return(ResultModel.GetParamErrorModel(msg)); } if (Enum.TryParse(req.ActionKey, true, out ArticleOptMenu opt)) { var conn = appSetting.GetMysqlConn(context); var info = await DapperTools.GetItem <ArticleOptInfo>(conn, EntityTools.GetTableName <ArticleOptInfo>(), new List <string>() { $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int) opt}", $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {req.ArticleId}", $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.ActionUser))} = {userId}", }, new[] { nameof(BaseModel.Id), nameof(BaseModel.ValidFlag) }, null); // var validFlag = await DapperTools.SelectSingle<int?>(conn, EntityTools.GetTableName<ArticleOptInfo>(), // new List<string>() // { // $"{nameof(BaseModel.Id)} = {req.ArticleId}", // $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int) opt}", // $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {req.ArticleId}", // }, nameof(BaseModel.ValidFlag)); if (info != null) { EditValidFlagParam param = new EditValidFlagParam() { Id = info.Id, UpdateTime = DateTime.Now }; if (info.ValidFlag == (int)ValidFlagMenu.UnUseFul) { param.ValidFlag = ValidFlagMenu.UseFul; } else { param.ValidFlag = ValidFlagMenu.UnUseFul; } var result = await DapperTools.Edit(conn, EntityTools.GetTableName <ArticleOptInfo>(), new[] { $"{nameof(BaseModel.Id)} = {info.Id}", $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.ActionUser))} = {userId}", }, null, param); return(ResultModel.GetSuccessModel(null, $"修改成功-{result}")); } else { var param = new CreateArticleOptInfoParam() { ActionKey = opt.ToString(), Count = 1, OptionType = (int)opt, RelationKey = req.ArticleId, ActionUser = userId }; var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName <ArticleOptInfo>(), param); return(ResultModel.GetSuccessModel(null, $"添加成功-{result}")); } // return ResultModel.GetSuccessModel(validFlag); // if (await DapperTools.IsExists(conn, EntityTools.GetTableName<ArticleOptInfo>(), new List<string>() // { // $"{nameof(BaseModel.Id)} = {req.ArticleId}", // $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int)opt}", // $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {req.ArticleId}", // })) // { // return ResultModel.GetDealErrorModel("请勿重复操作!"); // } // else // { // // var param = new CreateArticleOptInfoParam() // { // ActionKey = opt.ToString(), // Count = 1, // OptionType = (int) opt, // RelationKey = req.ArticleId // }; // // var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName<ArticleOptInfo>(), param); // // return ResultModel.GetSuccessModel(result); // // } } else { return(ResultModel.GetDealErrorModel($"操作<{req.ActionKey}>不存在!")); } }