public async Task <ContentResult> Finish([FromBody] dynamic json) { Game game = DynamicJson.Parse(json).Deserialize <Game>(); using (var trans = new TransactionScope()) { var scores = await DbEntityManager.Select <GameScore>("gid", game.Id); foreach (var player in game.Players) { var score = scores.SingleOrDefault(s => s.pidx == player.Index); if (score != null) { //integral var oid = score.oid; var integral = await DbEntityManager.SelectOne <UserIntegral>("wx_openid", oid); if (player.State == 1) { score.score = 1; integral.mc_integral += 10; integral.total_integral += 10; } else { score.score = -1; integral.mc_integral += 1; integral.total_integral += 1; } //update GameScore & integral await DbEntityManager.Update <GameScore>(score); await DbEntityManager.Update <UserIntegral>(integral); } } trans.Complete(); } return(new ContentResult() { StatusCode = 200 }); }
public async Task <ContentResult> Post(string signature, string timestamp, string nonce, string openid) { //验证微信签名 if (!WxBase.CheckSignature(signature, timestamp, nonce)) { Console.WriteLine($"receive error check signature:{signature} with {timestamp},{nonce}"); return(new ContentResult() { StatusCode = 401 }); } //初始化菜单 await WxBase.InitMenu(); using (Stream stream = Request.Body) { byte[] buffer = new byte[Request.ContentLength.Value]; await stream.ReadAsync(buffer, 0, buffer.Length); string xml = Encoding.UTF8.GetString(buffer); Console.WriteLine($"收到:{xml}"); var msg = WxTextMsg.FromXml(xml); if (msg.MsgType.Contains("text") && msg.Content.Contains("磁芯大战")) { WxUser user = null; if (await DbEntityManager.Exist <WxUser>("openid", openid)) { //get user from db user = await DbEntityManager.SelectOne <WxUser>("openid", openid); //update salt only user.ResetSalt(); await DbEntityManager.Update(user); } else { // var info = await WxBase.GetUserInfo(openid); Console.WriteLine($"获取:{info.nickname} 信息"); user = WxUser.CreateFromWxUserInfo(info); await DbEntityManager.Insert(user); } // var article = new WxArticle("MagCore - 磁芯大战", "进入房间创建游戏", HelperConfig.Current.WxInterfaceHost + "assets/images/icon.png", HelperConfig.Current.WxInterfaceHost + "pages/creator.html" + "?t=" + DateTime.Now.Ticks.ToString() + "&oid=" + openid + $"&name={user.nickname}({HashManager.Md5(openid).Substring(12, 4)})" + "&s=" + user.salt); var reply = new WxArticleMsg(msg.FromUserName, msg.ToUserName, msg.CreateTime, new WxArticle[] { article }); string text = reply.ToXml(); Console.WriteLine($"回复:{text}"); return(new ContentResult() { StatusCode = 200, Content = text }); } else { // var defaultReply = new WxTextMsg(msg.FromUserName, msg.ToUserName, msg.CreateTime, "未正确识别,磁芯大战比赛期间,其他回复暂时停止服务"); return(new ContentResult() { StatusCode = 200, Content = defaultReply.ToXml() }); } } }
public virtual async Task <IActionResult> Put(int id, dynamic json) { if (!(json is DynamicJson)) { json = DynamicJson.Parse(json.ToString()); } var entity = await DbEntityManager.SelectOne <T>(DbType, Db, nameof(Entity.Id), id); var ps = entity.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in ps) { var attrEditor = property.GetCustomAttribute(typeof(EditorAttribute)) as EditorAttribute; if (attrEditor != null && attrEditor.Editable) { if (json.TryGetValue(property.Name, out object value)) { if (property.PropertyType.IsEnum) { value = Enum.Parse(property.PropertyType, value.ToString()); } else if (property.PropertyType == typeof(bool)) { value = Convert.ToBoolean(value); } else if (property.PropertyType == typeof(short)) { value = Convert.ToInt16(value); } else if (property.PropertyType == typeof(int)) { value = Convert.ToInt32(value); } else if (property.PropertyType == typeof(long)) { value = Convert.ToInt64(value); } else if (property.PropertyType == typeof(float)) { value = Convert.ToSingle(value); } else if (property.PropertyType == typeof(double)) { value = Convert.ToDouble(value); } else if (property.PropertyType == typeof(decimal)) { value = Convert.ToDecimal(value); } else if (property.PropertyType == typeof(DateTime)) { value = Convert.ToDateTime(value); } property.SetValue(entity, value); } } } await DbEntityManager.Update(DbType, Db, entity); return(Ok(entity)); }