Пример #1
0
        public ActionResult AssignUserToTournament(List <UserTournamentVM> ListUserTournament, int TournamentId)
        {
            var tournament = _context.Tournaments.Find(TournamentId);

            if (tournament == null)
            {
                return(View("NotFound"));
            }
            List <UserTournament> userTournaments = new List <UserTournament>();

            for (int i = 0; i < ListUserTournament.Count; i++)
            {
                // check if has users assign already to this tournament
                if (UserAssigned(ListUserTournament[i].UserId, TournamentId))
                {
                    // get this record
                    UserTournament userTournament = _context.UserTournaments.Where(o => o.UserId == ListUserTournament[i].UserId && o.TournamentId == TournamentId).SingleOrDefault();
                    // if not selected i remove this assignment
                    if (!ListUserTournament[i].IsSelected)
                    {
                        _context.UserTournaments.Remove(userTournament);
                    }
                }
                // if user has no assignment to tournament
                else
                {
                    // if selected i create object of UserTournament and insert it to UserTournaments table
                    if (ListUserTournament[i].IsSelected)
                    {
                        UserTournament userTournament = new UserTournament();

                        // this user is never assign to a tournament
                        if (!UserAssigned(ListUserTournament[i].UserId))
                        {
                            userTournament.UserId       = ListUserTournament[i].UserId;
                            userTournament.TournamentId = TournamentId;
                        }
                        else
                        {
                            TempData["message"] = NotificationSystem.AddMessage("لا يمكن تعيين دور لمستخدم لأكثر من دورة", NotificationType.Danger.Value);
                            return(RedirectToAction("AssignUserToTournament", new { id = TournamentId }));
                        }

                        _context.UserTournaments.Add(userTournament);
                    }
                }
            }
            _context.SaveChanges();
            return(RedirectToAction("Index", "Tournaments"));
        }
Пример #2
0
        public async Task Signout(int id, string userId)
        {
            var tournament = this.context
                             .Tournaments
                             .Where(t => t.Id == id)
                             .Include(u => u.Players)
                             .FirstOrDefault();

            UserTournament ut = tournament.Players
                                .FirstOrDefault(x => x.UserId == userId);

            tournament.Players.Remove(ut);
            await this.context.SaveChangesAsync();
        }
Пример #3
0
    private void OnProcessPluginMessage(string command, string action, EsObject Parameters)
    {
        WaitingView.Instance.Close();
        if (command == Fields.REQUEST.COMMAND_REGISTERTOURNAMENT)
        {
            string message = "";
            if (Parameters.variableExists("message"))
            {
                message = Parameters.getString("message");
            }
            if (Parameters.getBoolean("result"))
            {
                TournamentView.Instance.btnRegister.gameObject.SetActive(false);
                TournamentView.Instance.detail.lblTournamentStatus.gameObject.SetActive(true);
                TournamentView.Instance.currentShow.info.isRegister = true;
                GameObject.Destroy(gameObject);
                //      NGUITools.SetActive(TableTournament, true);
                //      NGUITools.SetActive(RegisterForm, false);
                //      GameManager.Server.DoRequestPlugin(Utility.SetEsObject(Fields.REQUEST.COMMAND_GETGENERAL,
                //new object[] { "id", this.tournamentInfo.tournamentId }));
            }
            if (!string.IsNullOrEmpty(message))
            {
                NotificationView.ShowMessage(message);
            }
        }
        if (command == Fields.REQUEST.COMMAND_GETLISTREGISTER)
        {
            EsObject[] esObject = Parameters.getEsObjectArray("users");
            for (int i = 0; i < esObject.Length; i++)
            {
                users.Add(UserTournament.Create(esObject[i], gridUser.transform, userTournamentPrefab));
            }
            gridUser.Reposition();
        }
        if (command == Fields.REQUEST.COMMAND_GETGENERAL)
        {
            EsObject[] esObject = Parameters.getEsObjectArray("rounds");
            round1.SetData(esObject[0]);
            round2.SetData(esObject[1]);
            roud3.SetData(esObject[2]);
            round4.SetData(esObject[3]);
        }

        if (command == Fields.REQUEST.COMMAND_MATCH_LIST)
        {
            PopupTournament.Create(Parameters);
        }
    }
        public void AddUserTournamentTest()
        {
            //Arrange
            var model = new UserTournament()
            {
                TournamentId   = "UniqueTournamentId",
                TournamentName = "TournamentName",
                Status         = "Open"
            };

            //Act
            var val = _service.CreateWithId(model.TournamentId, model).Result;

            //Assert
            val.Should().NotBeNull();
        }
        public void CheckExistingTournamentTest()
        {
            //Arrange
            var model = new UserTournament()
            {
                TournamentId   = "UniqueTournamentId",
                TournamentName = "TournamentName",
                Status         = "Open"
            };
            var val = _service.CreateWithId(model.TournamentId, model).Result;

            //Act
            var teams = _service.ExistingUserTournaments;


            //Assert
            teams.Should().NotBeNull();
            teams.First().Should().BeEquivalentTo(model);
        }
        public void ImportUserTournamentTest()
        {
            //Arrange
            var model = new UserTournament()
            {
                TournamentId   = "UniqueTournamentId",
                TournamentName = "TournamentName",
                Status         = "Open"
            };

            //Act
            var service = new UserTournamentService("UniqueUserId", true);
            var val     = service.CreateWithId(model.TournamentId, model).Result;


            //Assert
            val.Should().NotBeNull();
            var drop = service.DropTable().Result;
        }
Пример #7
0
    public static UserTournament Create(EsObject es, Transform parent, GameObject prefab)
    {
        GameObject     obj  = NGUITools.AddChild(parent.gameObject, prefab);
        UserTournament tour = obj.GetComponent <UserTournament>();

        if (es.variableExists("userId"))
        {
            tour.userId = es.getInteger("userId");
        }
        obj.name = "userTournament" + tour.userId;
        if (es.variableExists("userName"))
        {
            tour.userName = es.getString("userName");
        }
        if (es.variableExists("timeRegister"))
        {
            tour.timeRegister = es.getString("timeRegister");
        }
        if (es.variableExists("fullName"))
        {
            tour.fullName = es.getString("fullName");
        }
        if (es.variableExists("level"))
        {
            tour.level = es.getInteger("level");
        }
        if (es.variableExists("avatar"))
        {
            tour.avatarUrl = es.getString("avatar");
        }
        if (es.variableExists("result"))
        {
            tour.result = es.getString("result");
        }
        tour.SetData();
        return(tour);
    }
 public void AssignPlayersToTournament(int tournamentId, IEnumerable<string> playerLogins)
 {
     try
     {
         using (var context = _contextFactory.Create())
         {
             var userTournaments = new List<UserTournament>();
             foreach (var playerLogin in playerLogins)
             {
                 var userTournament = new UserTournament()
                 {
                     TournamentId = tournamentId,
                     UserName = playerLogin
                 };
                 userTournaments.Add(userTournament);
             }
             context.UserTournaments.AddRange(userTournaments);
             context.SaveChanges();
         }
     }
     catch (Exception exception)
     {
         throw new Exception("Failed to add users to a tournament", exception.InnerException);
     }
     
 }