public static bool SaveMatchToDb(GameInfoModel gameInfoModel, ApplicationDbContext dbContext) { //计分 Int16[] points = new Int16[] { 6, 3, 1, 0 }; //如果已经结束,则标记计分 if (gameInfoModel.round != 7) { return(false); //continue; ; } //玩家情况 List <GameFactionModel> gameFactionModels = dbContext.GameFactionModel.Where(item => item.gameinfo_id == gameInfoModel.Id).OrderByDescending(item => item.scoreTotal).ToList(); //玩家依次加分 for (int i = 0; i < 4; i++) { MatchJoinModel matchJoinModel = dbContext.MatchJoinModel.SingleOrDefault(item => item.matchInfo_id == gameInfoModel.matchId && item.username == gameFactionModels[i].username); if (matchJoinModel == null) { continue; } switch (i) { case 0: matchJoinModel.first++; break; case 1: matchJoinModel.second++; break; case 2: matchJoinModel.third++; break; case 3: matchJoinModel.fourth++; break; } matchJoinModel.Score += points[i]; //玩家信息保存 dbContext.MatchJoinModel.Update(matchJoinModel); } return(true); }
public async Task <JsonResult> ExitMatch(int id) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); //比赛信息 MatchInfoModel matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == id); if (matchInfoModel != null) { if (matchInfoModel.RegistrationEndTime < DateTime.Now) { jsonData.info.state = 0; jsonData.info.message = "报名时间截止"; } else if (matchInfoModel.State != 0) { jsonData.info.state = 0; jsonData.info.message = "已经开始,无法退出"; } else { MatchJoinModel matchJoinModel = this.dbContext.MatchJoinModel.SingleOrDefault(item => item.matchInfo_id == matchInfoModel.Id && item.username == HttpContext.User.Identity .Name); if (matchJoinModel != null) { //删除 this.dbContext.MatchJoinModel.Remove(matchJoinModel); //报名人数-1 matchInfoModel.NumberNow--; this.dbContext.MatchInfoModel.Update(matchInfoModel); this.dbContext.SaveChanges(); jsonData.info.state = 200; } else { jsonData.info.state = 0; jsonData.info.message = "没有报名"; } } } return(new JsonResult(jsonData)); }
public async Task <JsonResult> AddUserToMatch(int id, string username) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); var matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == id); if (matchInfoModel != null) { ApplicationUser applicationUser = this.dbContext.Users.SingleOrDefault(item => item.UserName == username); if (applicationUser != null) { MatchJoinModel matchJoinModel = new MatchJoinModel(); matchJoinModel.matchInfo_id = id; //id matchJoinModel.Name = matchInfoModel.Name; //name matchJoinModel.AddTime = DateTime.Now; //时间 matchJoinModel.username = applicationUser.UserName; matchJoinModel.userid = applicationUser.Id; matchJoinModel.Rank = 0; matchJoinModel.Score = 0; //用户数量 matchInfoModel.NumberNow++; this.dbContext.MatchInfoModel.Update(matchInfoModel); this.dbContext.MatchJoinModel.Add(matchJoinModel); this.dbContext.SaveChanges(); this.AutoCreateMatch(matchInfoModel); jsonData.info.state = 200; return(new JsonResult(jsonData)); } else { jsonData.info.message = "用户不存在"; } } else { jsonData.info.message = "比赛不存在"; } jsonData.info.state = 0; return(new JsonResult(jsonData)); }
public IActionResult MatchJoinModify(MatchJoinModel model) { if (ModelState.IsValid) { if (model.Id > 0) { MatchJoinModel matchJoinModel = this.dbContext.MatchJoinModel.SingleOrDefault(item => item.Id == model.Id); matchJoinModel.first = model.first; matchJoinModel.second = model.second; matchJoinModel.third = model.third; matchJoinModel.fourth = model.fourth; matchJoinModel.Score = model.Score; matchJoinModel.Rank = model.Rank; this.dbContext.MatchJoinModel.Update(matchJoinModel); } this.dbContext.SaveChanges(); return(Redirect("/MatchInfo/Index")); } return(View(model)); }
public IActionResult MatchJoinModify(int id) { MatchJoinModel matchJoinModel = this.dbContext.MatchJoinModel.SingleOrDefault(item => item.Id == id); return(View(matchJoinModel)); }
public async Task <JsonResult> JoinMatch(int id) { Models.Data.UserFriendController.JsonData jsonData = new Models.Data.UserFriendController.JsonData(); var user = await _userManager.GetUserAsync(HttpContext.User); if (user.isallowmatch != 1) { jsonData.info.state = 0; jsonData.info.message = "你被禁止参加群联赛,请联系管理员查询原因!"; } else { var matchInfoModel = this.dbContext.MatchInfoModel.SingleOrDefault(item => item.Id == id); //比赛信息不为空 if (matchInfoModel != null) { if (this.dbContext.MatchJoinModel.Any( item => item.matchInfo_id == matchInfoModel.Id && item.username == user.UserName)) { jsonData.info.state = 0; jsonData.info.message = "已经报名"; } else { //是否已经满足报名 if (matchInfoModel.NumberMax != 0 && matchInfoModel.NumberNow == matchInfoModel.NumberMax) { jsonData.info.state = 0; jsonData.info.message = "报名人员已满"; } else if (matchInfoModel.RegistrationEndTime < DateTime.Now) { jsonData.info.state = 0; jsonData.info.message = "报名时间截止"; } else { //报名人数+1 matchInfoModel.NumberNow++; this.dbContext.MatchInfoModel.Update(matchInfoModel); //报名信息 MatchJoinModel matchJoinModel = new MatchJoinModel(); matchJoinModel.matchInfo_id = id; //id matchJoinModel.Name = matchInfoModel.Name; //name matchJoinModel.AddTime = DateTime.Now; //时间 matchJoinModel.username = user.UserName; matchJoinModel.userid = user.Id; matchJoinModel.Rank = 0; matchJoinModel.Score = 0; this.dbContext.MatchJoinModel.Add(matchJoinModel); this.dbContext.SaveChanges(); jsonData.info.state = 200; this.AutoCreateMatch(matchInfoModel); } } } } return(new JsonResult(jsonData)); }