public ActionResult UpdateScores([Bind(Include = "userId,gameId,score")] UserMatch userMatch)
        {
            if (Session["currentUser"] == null)
            {
                TempData["message"] = "Please login to continue.";
                return(RedirectToAction("VerifyLogin"));
            }
            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(userMatch).State = EntityState.Modified;
                    db.SaveChanges();
                    CalculateWinners(userMatch.gameId);
                    return(RedirectToAction("Index", new { id = ((TotalSquashNext.Models.User)Session["currentUser"]).id }));
                }
            }

            catch
            {
                TempData["Message"] = "ERROR - Please try again";
                return(View());
            }

            ViewBag.user = db.Users.Find(userMatch.userId).username;
            return(View());
        }
示例#2
0
        public bool UpdateUserMatchScore(UserMatch model)
        {
            bool   written            = false;
            string updateNullScoreSql = @"update users_matches set (score = @score) where (userid = @userid) and (matchid = @matchid);";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(updateNullScoreSql, conn);
                try
                {
                    cmd.Parameters.AddWithValue("@score", model.Score);
                    cmd.Parameters.AddWithValue("@userid", model.User.Id);
                    cmd.Parameters.AddWithValue("@matchid", model.MatchId);

                    written = cmd.ExecuteNonQuery() > 0;
                }
                catch (SqlException sqlEx)
                {
                    Console.Write(sqlEx.Message);
                }
                conn.Close();
            }

            return(written);
        }
示例#3
0
        // må oppdateres
        public List <SimilarResearcher> GetUserData(string cristinID, CancellationToken cancellationToken)
        {
            if (cristinID == "10" || cristinID == "20" || cristinID == "100" || cristinID == "1000")
            {
                UserMatch um = new UserMatch()
                {
                    cristinID    = "99",
                    similarities = 5,
                    quality      = "3",
                    publications = "100"
                };

                UserMatch um2 = new UserMatch()
                {
                    cristinID    = "97",
                    similarities = 3,
                    quality      = "2",
                    publications = "20"
                };

                return(null);
                //return new List<UserMatch> { um, um2 };
            }
            else
            {
                return(null);
            }
        }
示例#4
0
 public async Task <IActionResult> Edit([Bind("UserMatchId,MatchId,UserId")] UserMatch userMatch)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _context.Update(userMatch);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!UserMatchExists(userMatch.MatchId))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["MatchId"] = new SelectList(_context.Match, "MatchId", "MatchId", userMatch.MatchId);
     ViewData["UserId"]  = new SelectList(_context.User, "UserId", "UserId", userMatch.UserId);
     return(View(userMatch));
 }
        // GET: UserMatch/Edit/5
        public ActionResult Edit(int?id)
        {
            if (Session["currentUser"] == null)
            {
                TempData["message"] = "Please login to continue.";
                return(RedirectToAction("VerifyLogin"));
            }
            if (((TotalSquashNext.Models.User)Session["currentUser"]).accountId != 1)
            {
                TempData["message"] = "You must be an administrator to access this page.";
                return(RedirectToAction("VerifyLogin", "Login"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserMatch userMatch = db.UserMatches.Find(id);

            if (userMatch == null)
            {
                return(HttpNotFound());
            }
            ViewBag.gameId = new SelectList(db.Matches, "matchId", "matchId", userMatch.gameId);
            ViewBag.userId = new SelectList(db.Users, "id", "username", userMatch.userId);
            return(View(userMatch));
        }
示例#6
0
        public int CalculateRoundForUser(Round round, User user)
        {
            int correctMatchesGuessed = 0;
            int totalRoundPoints      = 0;

            foreach (Match match in round.Matches)
            {
                if (DateTime.Compare(match.StartDate, DateTime.Now) <= 0)
                {
                    UserMatch tips = match.Tips.FirstOrDefault(t => t.UserId == user.Id);
                    if (tips != null)
                    {
                        tips.TotalPoints = CalculateTips(tips, match);
                        if (tips.TotalPoints > CalculateBonusTierPoints(_defaultRightPoints))
                        {
                            correctMatchesGuessed++;
                        }
                        totalRoundPoints += tips.TotalPoints;
                    }
                }
            }

            totalRoundPoints += CalculatePointsForTotalMatchesCorrect(correctMatchesGuessed);
            return(totalRoundPoints);
        }
        public ActionResult Edit([Bind(Include = "userId,gameId,score")] UserMatch userMatch)
        {
            if (Session["currentUser"] == null)
            {
                TempData["message"] = "Please login to continue.";
                return(RedirectToAction("VerifyLogin"));
            }
            if (((TotalSquashNext.Models.User)Session["currentUser"]).accountId != 1)
            {
                TempData["message"] = "You must be an administrator to access this page.";
                return(RedirectToAction("VerifyLogin", "Login"));
            }

            try
            {
                if (ModelState.IsValid)
                {
                    db.Entry(userMatch).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            catch
            {
                TempData["Message"] = "ERROR - Please try again";
                return(View());
            }

            ViewBag.gameId = new SelectList(db.Matches, "matchId", "matchId", userMatch.gameId);
            ViewBag.userId = new SelectList(db.Users, "id", "username", userMatch.userId);
            return(View(userMatch));
        }
示例#8
0
        /// <summary>
        /// This creates a new match.
        /// </summary>
        public void NewMatch()
        {
            match = new UserMatch(configuration);
            user  = new Player(match, NAME);
            match.AddUser(user);

            var bots = ControllerSkeleton.LoadControllerFolder(Environment.CurrentDirectory + "\\..\\bots");

            foreach (ControllerSkeleton bot in bots)
            {
                if (bot.Controller.Name == BOTNAME)
                {
                    computer = match.PlayerCreate(bot);
                    break;
                }
            }

            match.OnEvent += UpdateShot;
            match.OnEvent += UpdateShotHit;
            match.OnEvent += UpdateWinner;
            match.OnEvent += RoundEnd;
            match.OnEvent += UpdateShipDestroyed;

            match.Play();
        }
示例#9
0
    public void saveResults()
    {
        lock (players) {
            Matches newMatch = new Matches();
            newMatch.TypeOfMatch = (int)this.room.RoomPropertes.GameMode;
            newMatch.GameSeed    = this.room.RoomPropertes.seed;
            newMatch.TargetsUsed = (int)this.room.RoomPropertes.TargetTypesAllowed;
            newMatch.CursorUsed  = (int)this.room.RoomPropertes.CursorType;
            List <Tuple <User, UserMatch> > usersAndReuslts = new List <Tuple <User, UserMatch> >();

            DataBaseAPI db = new DataBaseAPI();
            foreach (var player in players)
            {
                User user = db.getUser(player.Value.username);
                user.Elo += getEarnedElo(user.Username);
                UserMatch match = new UserMatch();
                match.Match   = newMatch;
                match.NumHits = player.Value.numberOfHits;
                match.NumMiss = player.Value.numbeerOfMisses;
                match.Points  = 100;
                match.Rank    = 1;
                match.User    = user;

                usersAndReuslts.Add(new Tuple <User, UserMatch>(user, match));
            }

            db.UpdateUsers(usersAndReuslts, newMatch);
        }
    }
示例#10
0
        public async Task <IActionResult> DeleteConfirmed(int?id, [Bind("UserMatchId,MatchId,UserId")] UserMatch userMatch)
        {
            var matchUser = _context.UserMatch.Find(userMatch.MatchId, userMatch.UserId);

            _context.UserMatch.Remove(matchUser);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
示例#11
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            UserMatch user    = input.Inputs[0] as UserMatch;
            string    message = $"ID:{user.Id},Accout:{user.Account},Email:{user.Email}";

            Console.WriteLine($"插入前日志:{message},发生时间:{DateTime.Now}");


            return(getNext()(input, getNext));
        }
        public UserMatch CheckUserData(int id, int matchid)
        {
            UserMatch objuser = new UserMatch();

            try
            {
                objuser = CommanClass.GetConnection().UserMatches.Where(a => a.UserId == id).Where(b => b.MatchId == matchid).FirstOrDefault();
            }
            catch (Exception ex)
            {
            }
            return(objuser);
        }
示例#13
0
        public async Task <IActionResult> Create([Bind("UserMatchId,MatchId,UserId")] UserMatch userMatch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userMatch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MatchId"] = new SelectList(_context.Match, "MatchId", "MatchId", userMatch.MatchId);
            ViewData["UserId"]  = new SelectList(_context.User, "UserId", "UserId", userMatch.UserId);
            return(View(userMatch));
        }
示例#14
0
        public ActionResult AcceptRequest(int Id)
        {
            int userId = Int32.Parse(Session["UserId"].ToString());

            using (SussexDBEntities db = new SussexDBEntities())
            {
                UserMatch match = db.UserMatches
                                  .Where(w => w.UserMatchRequestUserId == Id &&
                                         w.UserMatchRecievedUserId == userId).FirstOrDefault();
                match.UserMatchIsAccepted = true;
                db.SaveChanges();
            }
            return(Redirect("/User/MyFriends"));
        }
示例#15
0
        private int CalculateTotalGoalsThisRoundByUser(Round round, User user)
        {
            int totalGoals = 0;

            foreach (Match match in round.Matches)
            {
                UserMatch tips = match.Tips.FirstOrDefault(t => t.UserId == user.Id);
                if (tips != null)
                {
                    totalGoals += (tips.GuestTip + tips.HomeTip);
                }
            }
            return(totalGoals);
        }
示例#16
0
        public async Task AddUsersMatches(User user, Match match)
        {
            UserMatch userMatches = new UserMatch
            {
                //adding current user to usersMatches
                User  = user,
                Match = match
            };

            user.MatchedUsers.Add(userMatches);
            match.MatchedUsers.Add(userMatches);

            _context.Update(match);
            _context.Update(user);
            await _context.SaveChangesAsync();
        }
示例#17
0
        public async Task <int> PlayNow(int userId)
        {
            var activeMatch = await this.GetActiveMatch(userId);

            var randomNumber = new Random().Next(1, 100);
            var newMatch     = new UserMatch()
            {
                UserId      = userId,
                MatchId     = activeMatch.MatchId,
                NumberInput = randomNumber,
                CreatedDate = DateTime.Now
            };

            await this.userMatchRepo.AddUserMatch(newMatch);

            return(randomNumber);
        }
示例#18
0
        public static void Show(UserMatch user)
        {
            IUnityContainer container = new UnityContainer(); //声明一个容器

            container.RegisterType <IDBHelper, SqlHelper>();  ////声明SqlHelper并注册IDBHelper
            IDBHelper dbHelper = container.Resolve <IDBHelper>();

            //   dbHelper.Insert(user);//调用

            container.AddNewExtension <Interception>().Configure <Interception>()
            .SetInterceptorFor <IDBHelper>(new InterfaceInterceptor());

            IDBHelper dbHelperWithIsVaild = container.Resolve <IDBHelper>();

            Console.WriteLine($"==============={user.Account}==如下运行通过UnityAop带检验================");
            dbHelperWithIsVaild.Insert(user);
        }
示例#19
0
        public ActionResult AddFriend(int Id)
        {
            int userId = Int32.Parse(Session["UserId"].ToString());

            using (SussexDBEntities db = new SussexDBEntities())
            {
                UserMatch match = new UserMatch();
                match.UserMatchRequestUserId  = userId;
                match.UserMatchRecievedUserId = Id;
                match.UserMatchDate           = DateTime.Now;
                match.UserMatchIsAccepted     = false;
                match.UserMatchIsDeleted      = false;

                db.UserMatches.Add(match);
                db.SaveChanges();
            }
            return(Redirect("/User/MyFriends"));
        }
示例#20
0
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            UserMatch user = input.Inputs[0] as UserMatch;

            if (!user.IsMatch <UserMatch>())
            {
                Console.WriteLine($"显示如下错误信息,发生时间:{DateTime.Now}");
                StringBuilder sb = new StringBuilder();
                foreach (var item in user.MatchesWarnInfo <UserMatch>())
                {
                    var message = $"报错名:{item.Key},数据值:{item.Value}";
                    sb.AppendLine(message);
                    Console.WriteLine(message);
                }
                return(input.CreateExceptionMethodReturn(new Exception(sb.ToString())));
            }
            return(getNext()(input, getNext));
        }
        public void TestCalculateTips()
        {
            User user1 = new User()
            {
                Id          = 1,
                Firstname   = "Karl",
                Lastname    = "Bielsen",
                IsAdmin     = false,
                Email       = "*****@*****.**",
                Tips        = new List <UserMatch>(),
                Tournaments = new List <UserTour>(),
                RoundPoints = new List <UserRound>()
            };
            Match match1 = new Match()
            {
                Id         = 1,
                HomeTeam   = "Home",
                HomeScore  = 3,
                GuestTeam  = "Guest",
                GuestScore = 1,
                StartDate  = new DateTime(2019, 11, 27),
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            UserMatch tips1 = new UserMatch()
            {
                Id       = 1,
                User     = user1,
                UserId   = 1,
                Match    = match1,
                MatchId  = 1,
                HomeTip  = 3,
                GuestTip = 1,
                Rating   = 1
            };

            user1.Tips.Add(tips1);
            PointCalculator pointCalc      = new PointCalculator();
            int             expectedResult = 38;
            int             actualResult   = pointCalc.CalculateTips(tips1, match1);

            Assert.Equal(expectedResult, actualResult);
        }
        // GET: UserMatch/Details/5
        public ActionResult Details(int?id)
        {
            if (Session["currentUser"] == null)
            {
                TempData["message"] = "Please login to continue.";
                return(RedirectToAction("VerifyLogin"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserMatch userMatch = db.UserMatches.Find(id);

            if (userMatch == null)
            {
                return(HttpNotFound());
            }
            return(View(userMatch));
        }
        public void UpdateThisBall_InningsOver_Negative()
        {
            //Arrange
            var matchService = new UserMatchService("muid");
            var currentmatch = new UserMatch()
            {
                HomeTeam = new Innings {
                    TeamName = "BattingTeamName", InningStatus = true, Balls = 1
                },
                AwayTeam = new Innings {
                    TeamName = "BowlingTeamName", InningStatus = false
                }
            };

            //Act
            var match = matchService.UpdateThisBall(currentmatch, "battingTeamName", new Ball());

            //Assert
            match.Should().BeNull();
        }
示例#24
0
        public ActionResult PostScore(UserMatch model, int score)
        {
            model.Score = score;
            bool scoreWritten = false;

            if (model.Score > 0)
            {
                scoreWritten = dal.UpdateUserMatchScore(model);
            }

            if (scoreWritten)
            {
                SetMessage("Score logged!", MessageType.Success);
            }
            else
            {
                SetMessage("There was an error updating the score.", MessageType.Error);
            }

            return(RedirectToAction("Index", "Home"));
        }
 public MatchServiceTest()
 {
     _match = new UserMatch
     {
         Id           = "MatchId",
         TournamentId = "TournamentId",
         AddDate      = DateTime.Today,
         HomeTeam     = new Innings {
             TeamId  = "HomeTeamId", TeamName = "HomeTeamName", Balls = 100, Byes = 3, LegByes = 3,
             NoBalls = 2, Runs = 80, Wickets = 4, Wides = 6
         },
         AwayTeam = new Innings {
             TeamId = "AwayTeamId", TeamName = "AwayTeamName"
         },
         Location   = "Richmond, VA",
         TotalOvers = 20,
         Umpires    = new List <string> {
             "umpireA", "umpireB"
         }
     };
 }
示例#26
0
        public int CalculateTips(UserMatch tip, Match match)
        {
            int pointsForMatch = 0;

            if ((tip.HomeTip > tip.GuestTip && match.HomeScore > match.GuestScore) ||
                (tip.HomeTip < tip.GuestTip && match.HomeScore < match.GuestScore) ||
                (tip.HomeTip == tip.GuestTip && match.HomeScore == match.GuestScore))
            {
                pointsForMatch += CalculateBonusTierPoints(_defaultRightWin) +
                                  CalculateBonusTierPoints(CalculateRatingBonus(tip.Rating));
            }
            if (tip.HomeTip == match.HomeScore && tip.GuestTip == match.GuestScore)
            {
                pointsForMatch += CalculateBonusTierPoints(_defaultRightResult);
            }
            if (tip.HomeTip == match.GuestScore && tip.GuestTip == match.HomeScore)
            {
                pointsForMatch += CalculateBonusTierPoints(_defaultRightPoints);
            }

            return(pointsForMatch);
        }
        public ActionResult CreateFromChallenge(int gameId)
        {
            if (Session["currentUser"] == null)
            {
                TempData["message"] = "Please login to continue.";
                return(RedirectToAction("VerifyLogin"));
            }

            int currentUser    = ((TotalSquashNext.Models.User)Session["currentUser"]).id;
            int challengee     = ((TotalSquashNext.Models.User)Session["userToChallenge"]).id;
            int chosenLadderId = (int)Session["ladderId"];

            var userOnLadder = from x in db.UserLadders
                               where x.userId == currentUser
                               select x;

            var challengeLower = (from x in db.LadderRules
                                  select x.challengeLower).Single();

            var challengeRange = (from x in db.LadderRules
                                  select x.challengeRange).Single();

            var usersLadder = (from x in db.UserLadders
                               where x.userId == currentUser
                               where x.ladderId == chosenLadderId
                               select x).Count();

            var challengeeLadders = (from x in db.UserLadders
                                     where x.userId == challengee
                                     where x.ladderId == chosenLadderId
                                     select x).Count();

            var allUsersOnLadder = db.UserLadders.Include(x => x.User)
                                   .Where(x => x.ladderId == chosenLadderId).OrderByDescending(x => x.User.wins)
                                   .ThenBy(x => x.User.losses).ToList();

            int userPosition       = allUsersOnLadder.FindIndex(x => x.userId == currentUser);
            int challengeePosition = allUsersOnLadder.FindIndex(x => x.userId == challengee);


            if (userOnLadder.Count() == 0)
            {
                TempData["message"] = "You must be registered for at least one ladder to challenge another player.";
                return(RedirectToAction("Index", "Ladder"));
            }
            if (usersLadder == 0 || challengeeLadders == 0)
            {
                TempData["message"] = "You must both be registered on the same ladder to challenge this player.";
                return(RedirectToAction("Index", "Ladder"));
            }

            if ((userPosition > challengeePosition) && (challengeLower = true))
            {
                TempData["message"] = "Current rules do not allow you to challenge a user who is in a lower position on the ladder.";
                return(RedirectToAction("Index", "Ladder"));
            }
            if (challengeePosition - userPosition > challengeRange)
            {
                TempData["message"] = "Current rules do not allow you to challenge a user who is greater than" + challengeRange + " spaces above you on the ladder.";
                return(RedirectToAction("Index", "Ladder"));
            }
            if ((userPosition - challengeePosition > challengeRange) && (challengeLower = false))
            {
                TempData["message"] = "Current rules do not allow you to challenge a user who is greater than" + challengeRange + " spaces above you on the ladder.";
                return(RedirectToAction("Index", "Ladder"));
            }


            int[] userIds = new int[2];
            userIds[0] = ((TotalSquashNext.Models.User)Session["currentUser"]).id;
            userIds[1] = ((TotalSquashNext.Models.User)Session["userToChallenge"]).id;
            for (int i = 0; i < userIds.Length; i++)
            {
                UserMatch user = new UserMatch();
                user.userId = userIds[i];
                user.gameId = gameId;
                user.score  = -1;
                db.UserMatches.Add(user);
                db.SaveChanges();
            }


            return(RedirectToAction("Index", new { id = currentUser }));
        }
示例#28
0
        public void Seed(BetzerLigaContext ctx)
        {
            string password = "******";

            Byte[] passwordHashUser, passwordSaltUser;

            authenticationHelper.CreatePasswordHash(password, out passwordHashUser, out passwordSaltUser);

            User user1 = new User
            {
                Firstname    = "Mads",
                Lastname     = "Madsen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                Following    = new List <Follower>(),
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user2 = new User
            {
                Firstname    = "Lars",
                Lastname     = "Lars",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user3 = new User
            {
                Firstname    = "Frederik",
                Lastname     = "Frederiksen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = false,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user4 = new User
            {
                Firstname    = "Ole",
                Lastname     = "Olsen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user5 = new User
            {
                Firstname    = "John",
                Lastname     = "Johnsen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };

            User user6 = new User
            {
                Firstname    = "Erik",
                Lastname     = "Eriksen",
                Email        = "*****@*****.**",
                PasswordHash = passwordHashUser,
                PasswordSalt = passwordSaltUser,
                IsAdmin      = true,
                RoundPoints  = new List <UserRound>(),
                Tournaments  = new List <UserTour>(),
                Tips         = new List <UserMatch>()
            };
            Tournament tour1 = new Tournament
            {
                Name           = "TournaTest",
                NumberOfRounds = 12,
                IsDone         = false,
                StartDate      = new DateTime(2019, 12, 4),
                EndDate        = new DateTime(2019, 12, 24),
                Rounds         = new List <Round>(),
                Participants   = new List <UserTour>()
            };
            Tournament tour2 = new Tournament
            {
                Name           = "Testing",
                NumberOfRounds = 12,
                IsDone         = false,
                StartDate      = new DateTime(2019, 11, 30),
                EndDate        = new DateTime(2020, 1, 24),
                Rounds         = new List <Round>(),
                Participants   = new List <UserTour>()
            };

            Round round1 = new Round
            {
                RoundNumber     = 1,
                Tournament      = tour1,
                TotalGoals      = 0,
                TippingDeadLine = new DateTime(2019, 11, 26),
                Matches         = new List <Match>(),
                RoundPoints     = new List <UserRound>()
            };
            Round round2 = new Round
            {
                RoundNumber     = 1,
                Tournament      = tour2,
                TotalGoals      = 0,
                TippingDeadLine = new DateTime(2019, 12, 20),
                Matches         = new List <Match>(),
                RoundPoints     = new List <UserRound>()
            };

            UserRound userRound1 = new UserRound
            {
                User       = user1,
                Round      = round1,
                UserPoints = 0
            };
            UserRound userRound2 = new UserRound
            {
                User       = user2,
                Round      = round1,
                UserPoints = 0
            };
            UserRound userRound3 = new UserRound
            {
                User       = user3,
                Round      = round1,
                UserPoints = 0
            };
            UserRound userRound4 = new UserRound
            {
                User       = user4,
                Round      = round2,
                UserPoints = 0
            };
            UserRound userRound5 = new UserRound
            {
                User       = user2,
                Round      = round2,
                UserPoints = 0
            };
            UserRound userRound6 = new UserRound
            {
                User       = user3,
                Round      = round2,
                UserPoints = 0
            };
            UserRound userRound7 = new UserRound
            {
                User       = user1,
                Round      = round2,
                UserPoints = 0
            };

            UserTour usertour1 = new UserTour
            {
                User            = user1,
                TotalUserPoints = 0
            };
            UserTour usertour2 = new UserTour
            {
                User            = user2,
                TotalUserPoints = 0
            };
            UserTour usertour3 = new UserTour
            {
                User            = user3,
                TotalUserPoints = 0
            };
            UserTour usertour4 = new UserTour
            {
                User            = user4,
                TotalUserPoints = 0
            };
            UserTour usertour5 = new UserTour
            {
                User            = user5,
                TotalUserPoints = 0
            };
            UserTour usertour6 = new UserTour
            {
                User            = user6,
                TotalUserPoints = 0
            };

            Match match1 = new Match()
            {
                HomeTeam   = "BIF",
                HomeScore  = 3,
                GuestTeam  = "FCK",
                GuestScore = 1,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match2 = new Match()
            {
                HomeTeam   = "OB",
                HomeScore  = 1,
                GuestTeam  = "FCK",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match3 = new Match()
            {
                HomeTeam   = "FCM",
                HomeScore  = 2,
                GuestTeam  = "FCK",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 11, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match4 = new Match()
            {
                HomeTeam   = "BIF",
                HomeScore  = 3,
                GuestTeam  = "FCM",
                GuestScore = 1,
                StartDate  = new DateTime(2019, 12, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match5 = new Match()
            {
                HomeTeam   = "OB",
                HomeScore  = 1,
                GuestTeam  = "BIF",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 12, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };
            Match match6 = new Match()
            {
                HomeTeam   = "FCM",
                HomeScore  = 2,
                GuestTeam  = "OB",
                GuestScore = 2,
                StartDate  = new DateTime(2019, 12, 27),
                Round      = round1,
                RoundId    = 1,
                Tips       = new List <UserMatch>()
            };

            UserMatch tips1 = new UserMatch()
            {
                User        = user1,
                Match       = match1,
                HomeTip     = 3,
                GuestTip    = 1,
                Rating      = 1,
                TotalPoints = 0
            };
            UserMatch tips2 = new UserMatch()
            {
                User        = user1,
                Match       = match2,
                HomeTip     = 2,
                GuestTip    = 1,
                Rating      = 2,
                TotalPoints = 0
            };
            UserMatch tips3 = new UserMatch()
            {
                User        = user1,
                Match       = match3,
                HomeTip     = 3,
                GuestTip    = 3,
                Rating      = 3,
                TotalPoints = 0
            };
            UserMatch tips4 = new UserMatch()
            {
                User        = user2,
                Match       = match1,
                HomeTip     = 2,
                GuestTip    = 3,
                Rating      = 1,
                TotalPoints = 0
            };
            UserMatch tips5 = new UserMatch()
            {
                User        = user2,
                Match       = match2,
                HomeTip     = 1,
                GuestTip    = 1,
                Rating      = 2,
                TotalPoints = 0
            };
            UserMatch tips6 = new UserMatch()
            {
                User        = user2,
                Match       = match3,
                HomeTip     = 2,
                GuestTip    = 3,
                Rating      = 3,
                TotalPoints = 0
            };
            UserMatch tips7 = new UserMatch()
            {
                User        = user3,
                Match       = match1,
                HomeTip     = 4,
                GuestTip    = 5,
                Rating      = 1,
                TotalPoints = 0
            };
            UserMatch tips8 = new UserMatch()
            {
                User        = user3,
                Match       = match2,
                HomeTip     = 4,
                GuestTip    = 4,
                Rating      = 2,
                TotalPoints = 0
            };
            UserMatch tips9 = new UserMatch()
            {
                User        = user3,
                Match       = match3,
                HomeTip     = 5,
                GuestTip    = 4,
                Rating      = 3,
                TotalPoints = 0
            };

            tour1.Participants.Add(usertour1);
            tour1.Participants.Add(usertour2);
            tour1.Participants.Add(usertour3);
            tour2.Participants.Add(usertour1);
            tour2.Participants.Add(usertour2);
            tour2.Participants.Add(usertour3);
            tour2.Participants.Add(usertour4);


            round1.RoundPoints.Add(userRound1);
            round1.RoundPoints.Add(userRound2);
            round1.RoundPoints.Add(userRound3);
            round2.RoundPoints.Add(userRound4);
            round2.RoundPoints.Add(userRound5);
            round2.RoundPoints.Add(userRound6);
            round2.RoundPoints.Add(userRound7);

            match1.Tips.Add(tips1);
            match1.Tips.Add(tips4);
            match1.Tips.Add(tips7);
            match2.Tips.Add(tips2);
            match2.Tips.Add(tips5);
            match2.Tips.Add(tips8);
            match3.Tips.Add(tips3);
            match3.Tips.Add(tips6);
            match3.Tips.Add(tips9);

            user1 = ctx.Users.Add(user1).Entity;
            user2 = ctx.Users.Add(user2).Entity;
            user3 = ctx.Users.Add(user3).Entity;
            user4 = ctx.Users.Add(user4).Entity;
            user5 = ctx.Users.Add(user5).Entity;
            user6 = ctx.Users.Add(user6).Entity;

            ctx.Tournaments.Add(tour1);
            ctx.Tournaments.Add(tour2);

            ctx.Rounds.Add(round1);
            ctx.Rounds.Add(round2);

            ctx.Matches.Add(match1);
            ctx.Matches.Add(match2);
            ctx.Matches.Add(match3);
            ctx.Matches.Add(match4);
            ctx.Matches.Add(match5);
            ctx.Matches.Add(match6);



            ctx.SaveChanges();
        }
        public Matches UpdateUserMatch(int teamid, Matches val)
        {
            var objuser = CommanClass.GetConnection().UserMatches.Where(a => a.MatchId == val.Id && a.TeamId == teamid && a.UserId == val.UserId).FirstOrDefault();

            if (objuser == null)
            {
                //  CommanClass.GetConnection().Users.Add(val);
            }
            else
            {
                foreach (FabricApplication.Models.BAL.MatchPlayer item in val.MatchPlayers)
                {
                    var userPlayerPoints = CommanClass.GetConnection().UserMatches.Where(a => a.PlayerId == item.PlayerId && a.MatchId == item.MatchId).FirstOrDefault();
                    if (objuser == null && userPlayerPoints == null)
                    {
                        //  dbcontext.Users.Add(objuser);
                    }
                    else
                    {
                        using (var db = CommanClass.GetConnection())
                        {
                            if (item.IsSelected == true)
                            {
                                UserMatch usermatch = new UserMatch()
                                {
                                    Id       = item.Id,
                                    UserId   = val.UserId,
                                    MatchId  = item.MatchId,
                                    PlayerId = item.PlayerId,
                                    TeamId   = teamid
                                };
                                db.UserMatches.Attach(usermatch);
                                var usermatchs = db.Entry(usermatch);
                                usermatchs.Property(x => x.MatchId).IsModified  = true;
                                usermatchs.Property(x => x.UserId).IsModified   = true;
                                usermatchs.Property(x => x.PlayerId).IsModified = true;
                                usermatchs.Property(x => x.TeamId).IsModified   = true;

                                var         PlayerscoreId = db.PlayerScores.AsNoTracking().Where(a => a.PlayerId == item.PlayerId && a.MatchId == item.MatchId).FirstOrDefault();
                                PlayerScore playerscore   = new PlayerScore()
                                {
                                    PlayerId = item.PlayerId,
                                    MatchId  = item.MatchId,
                                    Id       = PlayerscoreId.Id,
                                    Points   = item.Points,
                                    Credits  = item.Credits
                                };
                                db.PlayerScores.Attach(playerscore);
                                var playerscores = db.Entry(playerscore);
                                playerscores.Property(x => x.PlayerId).IsModified = true;
                                playerscores.Property(x => x.MatchId).IsModified  = true;
                                playerscores.Property(x => x.Points).IsModified   = true;
                                playerscores.Property(x => x.Credits).IsModified  = true;
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
            return(val);
        }
示例#30
0
        static void Main(string[] args)
        {
            Console.WriteLine(People.Chinese.GetRemark());

            People.Otherbody.GetALLRemark().ShowList();

            #region 测试模仿课程方法
            {
                User user1 = new User()
                {
                    Id      = 963,
                    Account = "LaoYang",
                    Email   = "*****@*****.**",
                    Mobile  = "13566626562"
                };
                string errorName;
                Console.WriteLine($"状态{user1.IsValidate(out errorName)},报错属性名:{errorName}");
            }
            #endregion

            List <UserMatch> users = new List <UserMatch>();
            #region 学习Attribute类发现有自带虚方法Match
            {
                UserMatch user1 = new UserMatch()
                {
                    Id      = 963,
                    Account = "yang",
                    Email   = "#[email protected]",
                    Mobile  = "13566625632错误"
                };
                users.Add(user1);
                string errorName;
                Console.WriteLine($"状态{user1.IsMatch(out errorName)},报错属性名:{errorName}");

                foreach (var kvEnity in user1.MatchesWarnInfo())
                {
                    Console.WriteLine($"报错名:{kvEnity.Key},报错值:{kvEnity.Value}");
                }
            }
            #endregion

            #region UnityAop实现Parallel并发调用
            UserMatch user2 = new UserMatch()
            {
                Id      = 963,
                Account = "loayang",
                Email   = "*****@*****.**",
                Mobile  = "13566625632"
            };

            users.Add(user2);
            Console.WriteLine("***********************演示UnityAOP多线程并发***************************");
            try
            {
                Parallel.ForEach(users, user =>
                {
                    UnityAop.UnityAOP.Show(user);
                });
            }
            catch (AggregateException aex)
            {
                Console.WriteLine("################捕获到异常反馈如下:##################");
                foreach (var iex in aex.InnerExceptions)
                {
                    Console.WriteLine(iex.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #endregion

            Console.ReadKey();
        }