public JsonResult PermissionChange(int tournamentId, int targetUser, String action)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);

                Dictionary <String, int> permissionChange = tournament.PermissionAction(account.Model.AccountID, targetUser, action);
                if (permissionChange == null)
                {
                    status  = false;
                    message = "An unexpected error occured";
                }
                else
                {
                    data = new
                    {
                        permissions = permissionChange,
                        isCheckedIn = tournament.isUserCheckedIn(targetUser),
                        targetUser  = targetUser
                    };
                    message = "Permissions are updated";
                    status  = true;
                }
            }
            else
            {
                message = "You must be logged in to do this action";
            }

            return(BundleJson());
        }
        public JsonResult AjaxSearch(String searchBy)
        {
            List <object> dataReturned = new List <object>();

            Models.Tournament tournament = new Models.Tournament(service, -1);
            tournament.Search(JsonConvert.DeserializeObject <Dictionary <String, String> >(searchBy));

            foreach (TournamentModel tourny in tournament.searched)
            {
                dataReturned.Add(new
                {
                    id                 = tourny.TournamentID,
                    title              = tourny.Title,
                    game               = tourny.GameType.Title,
                    platform           = tourny.Platform != null ? tourny.Platform.PlatformName : "None",
                    startDate          = tourny.TournamentStartDate.ToShortDateString(),
                    publicRegistration = tourny.PublicRegistration,
                    publicViewing      = tourny.PublicViewing,
                    link               = Url.Action("Tournament", "Tournament", new { guid = tourny.TournamentID })
                });

                data = new
                {
                    search = dataReturned
                };
            }

            return(BundleJson());
        }
        public JsonResult Reset(int tournamentId, int bracketId)
        {
            String redirect = Url.Action("Tournament", "Tournament", new { guid = tournamentId });

            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                Models.Bracket    bracket    = tournament.GetBracket(bracketId);

                if (tournament.IsCreator(account.Model.AccountID))
                {
                    bracket.Reset();

                    status  = true;
                    message = "Bracket was reset";
                }
                else
                {
                    status  = false;
                    message = "You do not have permission to do this";
                }
            }
            else
            {
                status   = false;
                message  = "You must login to do this";
                redirect = Url.Action("Login", "Account");
            }

            Session["Message"]       = message;
            Session["Message.Class"] = status ? ViewError.SUCCESS : ViewError.WARNING;
            data = new { redirect = redirect };

            return(BundleJson());
        }
Exemple #4
0
        public ActionResult Create(Models.Tournament t)
        {
            var customIdentity = User.Identity as CustomIdentity;

            if (customIdentity != null && t.ID != Guid.Empty)
            {
                // todo use Warehouse.CreateTournament()
                var t2 = Cloud.Storage.Tournament.CreateTournament(
                    t.ID,
                    t.MaxPlayers,
                    t.StartTime,
                    customIdentity.Id,
                    t.TournamentName,
                    0x0,
                    "type",
                    t.Description
                    );
                Warehouse.db.AddToTournament(t2);
                for (int i = 0; i < t.StagesCount; i++)
                {
                    var st = Cloud.Storage.Stage.CreateStage(Guid.NewGuid(), 0x0, "TO DO: // ", t.StartTime);
                    st.Tournament = t2;
                    Warehouse.db.AddToStages(st);
                    // Было:

                    /*Guid.NewGuid(),
                     * "Waiting",
                     * "type",
                     * t.StartTime,
                     * t.ID));*/
                }
                Warehouse.db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemple #5
0
        public ActionResult View(Guid id)
        {
            Warehouse.db.Refresh(RefreshMode.StoreWins, Warehouse.db.Tournament);
            var customIdentity = User.Identity as CustomIdentity;
            var tournament     = Warehouse.db.Tournament.First(t => t.Tournament_ID == id);
            var res            = new Models.Tournament()
            {
                // todo
                Creator        = tournament.Creator_ID.ToString(),
                ID             = tournament.Tournament_ID,
                Description    = tournament.Description,
                MaxPlayers     = tournament.MaxPlayers,
                StartTime      = tournament.StartTime,
                TournamentName = tournament.Tournament_Name,
                Players        = new List <string>(from p in tournament.Player select p.Account_Name),
                IsIn           = IsIn(id),
                State          = (State)tournament.State_Code,
                Stages         = new List <Stage>(
                    tournament.Stages.ToArray().Select(s => new Stage
                {
                    StartTime = s.StartTime,
                    State     = (State)s.State_Code,
                    Games     = new List <GameModel>(s.Games.Select(g => new GameModel(g)))
                }
                                                       ))
            };

            List <KeyValuePair <Guid, string> > intellects = Warehouse.db.Intellect.Where(ii => ii.AccountAccount_ID == customIdentity.Id).ToArray().Select(i => new KeyValuePair <Guid, string>(i.Intellect_ID, String.Format("{0}", i.Intellect_Name))).ToList();

            ViewData["intellects"] = intellects;
            return(View(res));
        }
        public ActionResult Update(int tournamentId)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tourny = new Models.Tournament(service, tournamentId);
                if (tourny.IsAdmin(account.Model.AccountID))
                {
                    ViewBag.Create     = false;
                    ViewBag.CanEdit    = tourny.CanEdit();
                    ViewBag.InProgress = tourny.Model.InProgress;
                    tourny.SetFields();
                    return(View("Create", tourny.viewModel));
                }
                else
                {
                    Session["Message"]       = "You do not have permission to do that.";
                    Session["Message.Class"] = ViewError.ERROR;

                    return(RedirectToAction("Tournament", "Tournament", new { guid = tourny.Model.TournamentID }));
                }
            }
            else
            {
                Session["Message"]       = "You need to login to do that";
                Session["Message.Class"] = ViewError.ERROR;

                return(RedirectToAction("Login", "Account"));
            }
        }
        public ActionResult Deregister(TournamentRegisterViewModel userData)
        {
            if (userData.AccountID == account.Model.AccountID)
            {
                Models.Tournament viewModel = new Models.Tournament(service, userData.TournamentID);
                if (viewModel.RemoveUser(account.Model.AccountID))
                {
                    Session["Message"]       = "You have been removed from this tournament.";
                    Session["Message.Class"] = ViewError.SUCCESS;
                }
                else
                {
                    Session["Message"]       = "We could not remove you from the tournament due to an error.";
                    Session["Message.Class"] = ViewError.ERROR;
                }
            }
            else
            {
                Session["Message"]       = "You must login to do this action.";
                Session["Message.Class"] = ViewError.ERROR;
                return(RedirectToAction("Login", "Account"));
            }

            return(RedirectToAction("Tournament", "Tournament", new { guid = userData.TournamentID }));
        }
        public ActionResult Search(Dictionary <String, String> searchBy)
        {
            Models.Tournament model = new Models.Tournament(service, -1);
            model.Search(searchBy);

            return(View("Search", model));
        }
        public ActionResult Register(TournamentRegisterViewModel userData)
        {
            if (userData.AccountID == account.Model.AccountID)
            {
                Models.Tournament viewModel = new Models.Tournament(service, userData.TournamentID);

                if (viewModel.AddUser(account, Permission.TOURNAMENT_STANDARD))
                {
                    Session["Message"]       = "You have been registered to this tournament";
                    Session["Message.Class"] = ViewError.SUCCESS;
                }
                else
                {
                    Session["Message"]       = "We were unable to add you to the tournament";
                    Session["Message.Class"] = ViewError.ERROR;
                }
            }
            else
            {
                Session["Message"]       = "You must login to register for this tournament";
                Session["Message.Class"] = ViewError.ERROR;
                return(RedirectToAction("Login", "Account"));
            }

            return(RedirectToAction("Tournament", "Tournament", new { guid = userData.TournamentID }));
        }
        public async Task <IActionResult> PutTournament(int id, Models.Tournament tournament)
        {
            if (id != tournament.TournamentID)
            {
                return(BadRequest());
            }

            _context.Entry(tournament).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TournamentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public JsonResult CheckIn(int tournamentId, int tournamentUserId = -1)
        {
            Models.Tournament tournament = new Models.Tournament(service, tournamentId);


            if (tournament.IsAdmin(account.Model.AccountID))
            {
                // Check if a userId was provided first before checking an account
                if (tournamentUserId != -1)
                {
                    // An admin is checking in a user
                    status  = tournament.CheckUserIn(tournamentUserId);
                    message = "User is " + (status ? "" : "not") + " checked in";
                }
                else if (account.IsLoggedIn())
                {
                    // A user with an account is checking in.
                    status  = tournament.CheckAccountIn(account.Model.AccountID);
                    message = "Account is " + (status ? "" : "not") + " checked in";
                }
            }
            else
            {
                message = "You can not do this.";
            }

            data = new
            {
                isCheckedIn = tournament.isUserCheckedIn(tournamentUserId),
                targetUser  = tournamentUserId
            };
            return(BundleJson());
        }
 public Models.Tournament Get(int tournamentId)
 {
     Models.Tournament tournament = this._service.Get(tournamentId);
     if (tournament == null)
     {
         return(null);
     }
     return(tournament);
 }
Exemple #13
0
        public void DeleteTournament(Models.Tournament tournament)
        {
            if (tournament == null)
            {
                throw new ArgumentNullException();
            }

            _context.Tournaments.Remove(tournament);
        }
Exemple #14
0
        public void CreateTournament(Models.Tournament tournament)
        {
            if (tournament == null)
            {
                throw new ArgumentNullException(nameof(tournament));
            }

            _context.Tournaments.Add(tournament);
        }
        public async Task <ActionResult <Models.Tournament> > PostTournament(Models.Tournament tournament)
        {
            var list = _context.Tournaments.ToList();

            tournament.TournamentID = list.Any() ? list.Count() + 1 : 1;
            _context.Tournaments.Add(tournament);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
 public ActionResult Create()
 {
     if (!account.IsLoggedIn())
     {
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         Models.Tournament tournament = new Models.Tournament(service, -1);
         ViewBag.Create     = true;
         ViewBag.CanEdit    = tournament.CanEdit();
         ViewBag.InProgress = tournament.Model.InProgress;
         return(View("Create", tournament.viewModel));
     }
 }
        public JsonResult Finalize(int tournamentId, int bracketId, Dictionary <String, Dictionary <String, int> > roundData)
        {
            String redirect = Url.Action("Tournament", "Tournament", new { guid = tournamentId });

            if (account.IsLoggedIn())
            {
                // Load the tournament
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    if (tournament.FinalizeBracket(bracketId, roundData))
                    {
                        status  = true;
                        message = "Your tournament has been finalized. No changes can be made.";

                        Session["Message"]       = message;
                        Session["Message.Class"] = ViewError.SUCCESS;
                    }
                    else
                    {
                        message = "An error occurred while trying to create the matches.";

                        Session["Message"]       = message;
                        Session["Message.Class"] = ViewError.ERROR;
                    }
                }
                else
                {
                    message = "You are not allowed to do that.";

                    Session["Message"]       = message;
                    Session["Message.Class"] = ViewError.ERROR;
                }
            }
            else
            {
                message  = "You must login to do that.";
                redirect = Url.Action("Login", "Account");

                Session["Message"]       = message;
                Session["Message.Class"] = ViewError.ERROR;
            }

            data = new { redirect = redirect };


            return(BundleJson());
        }
Exemple #18
0
        public ActionResult Edit(Guid id)
        {
            Warehouse.db.Refresh(RefreshMode.StoreWins, Warehouse.db.Tournament);
            var tournament = Warehouse.db.Tournament.First(t => t.Tournament_ID == id);
            var res        = new Models.Tournament()
            {
                // todo
                Creator        = tournament.Creator_ID.ToString(),
                ID             = tournament.Tournament_ID,
                Description    = tournament.Description,
                MaxPlayers     = tournament.MaxPlayers,
                StartTime      = tournament.StartTime,
                TournamentName = tournament.Tournament_Name,
                Players        = new List <string>(from p in tournament.Player select p.Account_Name),
                IsIn           = IsIn(id),
                State          = (State)tournament.State_Code
            };

            return(View(res));
        }
        public JsonResult Delete(int tournamentId)
        {
            String redirect = Url.Action("Tournament", "Tournament", new { guid = tournamentId });

            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                if (tournament.IsCreator(account.Model.AccountID))
                {
                    if (tournament.Delete())
                    {
                        status  = true;
                        message = "Tournament was deleted.";
                        data    = new
                        {
                            redirect = Url.Action("Index", "Tournament")
                        };

                        Session["Message"]       = message;
                        Session["Message.Class"] = ViewError.SUCCESS;
                    }
                    else
                    {
                        status  = false;
                        message = "Unable to delete the tournament due to an error.";
                    }
                }
                else
                {
                    status  = false;
                    message = "You do not have permission to do this.";
                }
            }
            else
            {
                status  = false;
                message = "Please login in order to modify a tournament.";
            }

            return(BundleJson());
        }
        public ActionResult Update(TournamentViewModel viewModel, int tournamentId)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tourny = new Models.Tournament(service, tournamentId);

                if (tourny.IsAdmin(account.Model.AccountID))
                {
                    if (tourny.Update(viewModel, account.Model.AccountID))
                    {
                        Session["Message"]       = "Edits to the tournament was successful";
                        Session["Message.Class"] = ViewError.SUCCESS;

                        return(RedirectToAction("Tournament", "Tournament", new { guid = tourny.Model.TournamentID }));
                    }
                    else
                    {
                        Session["Message"]       = "We were unable to update your tournament.";
                        Session["Message.Class"] = ViewError.ERROR;
                    }
                }
                else
                {
                    Session["Message"]       = "You do not have permission to update this tournament";
                    Session["Message.Class"] = ViewError.ERROR;
                }

                ViewBag.Create     = false;
                ViewBag.CanEdit    = tourny.CanEdit();
                ViewBag.InProgress = tourny.Model.InProgress;

                return(View("Create", viewModel));
            }
            else
            {
                Session["Message"]       = "You must login to edit a tournament.";
                Session["Message.Class"] = ViewError.ERROR;
                return(RedirectToAction("Login", "Account"));
            }
        }
        public JsonResult Reset(int tournamentId, int bracketId, int matchNum)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                Models.Bracket    bracket    = tournament.GetBracket(bracketId);

                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    List <int>    matchNumsAffected = bracket.MatchesAffectedList(matchNum);
                    List <object> matchResponse     = new List <object>();

                    bracket.IBracket.ResetMatchScore(matchNum);

                    foreach (int match in matchNumsAffected)
                    {
                        matchResponse.Add(JsonMatchResponse(bracket.GetMatchByNum(match), true));
                    }

                    status  = true;
                    message = "Matches are reset";
                    data    = new
                    {
                        isLocked = bracket.IsLocked,
                        matches  = matchResponse
                    };
                }
                else
                {
                    message = "You do not have permission to do this";
                }
            }
            else
            {
                message = "You must login to do this";
            }

            return(BundleJson());
        }
        public JsonResult NoAccountRegister(int tournamentId, String name, int bracketId)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);

                // Is an Administrator registering a user?
                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    TournamentUserModel model = tournament.AddUser(name);
                    data = new
                    {
                        user = new
                        {
                            Name             = model.Name,
                            Permission       = model.PermissionLevel,
                            TournamentUserId = model.TournamentUserID,
                            Seed             = tournament.GetUserSeed(bracketId, model.TournamentUserID)
                        },
                        actions = tournament.PermissionAction(account.Model.AccountID, model.TournamentUserID, "default")
                    };
                    if (data != null)
                    {
                        status = true;
                    }
                    message = "User was " + (status ? "" : "not") + " added successfully";
                }
                else
                {
                    message = "You are not allowed to register a user.";
                }
            }
            else
            {
                message = "You need to login first.";
            }

            return(BundleJson());
        }
        public JsonResult Lockout(int tournamentId, int bracketId)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);

                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    status = tournament.LockBracket(bracketId, true);

                    if (status)
                    {
                        message = "Bracket is not locked.";
                    }
                    else
                    {
                        message = "Bracket failed to lock.";
                    }
                }
            }
            return(BundleJson());
        }
        public JsonResult RemoveGame(int tournamentId, int bracketId, int matchNum, int gameNum)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);
                Models.Bracket    bracket    = tournament.GetBracket(bracketId);

                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    //Models.Match match = bracket.GetMatchByNum(matchNum);
                    List <int>    matchesAffected     = bracket.MatchesAffectedList(matchNum);
                    List <object> matchesAffectedData = new List <object>();

                    if (bracket.RemoveGame(matchNum, gameNum))
                    {
                        foreach (int matchNumber in matchesAffected)
                        {
                            matchesAffectedData.Add(JsonMatchResponse(bracket.GetMatchByNum(matchNumber), true));
                        }

                        status  = true;
                        message = "Matches were updated";
                        data    = new
                        {
                            bracketFinished = bracket.IBracket.IsFinished,
                            isLocked        = bracket.IsLocked,
                            matches         = matchesAffectedData,
                        };
                    }
                    else
                    {
                        message = "There was an error in deleting the game";
                    }
                }
            }

            return(BundleJson());
        }
        public JsonResult Standings(int tournamentId, int bracketId)
        {
            Models.Tournament tournament = new Models.Tournament(service, tournamentId);
            Models.Bracket    bracket    = tournament.GetBracket(bracketId);

            if (bracket == null)
            {
                status  = false;
                message = "Invalid data";
            }
            else
            {
                status  = true;
                message = "Standings Acquired";
                data    = new
                {
                    ranks     = bracket.IBracket.Rankings,
                    usePoints = bracket.UsePoints()
                };
            }

            return(BundleJson());
        }
        public ActionResult Create(TournamentViewModel viewModel)
        {
            // Verify the user is logged in first
            if (!account.IsLoggedIn())
            {
                Session["Message"]       = "You must login to create a tournament.";
                Session["Message.Class"] = ViewError.WARNING;
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                Models.Tournament tourny = new Models.Tournament(service, -1);
                if (ModelState.IsValid)
                {
                    if (tourny.Create(viewModel, account))
                    {
                        return(RedirectToAction("Tournament", "Tournament", new { guid = tourny.Model.TournamentID }));
                    }
                    else
                    {
                        // Show a success message.
                        Session["Message"]       = "We were unable to create the tournament.";
                        Session["Message.Class"] = ViewError.ERROR;
                    }
                }
                else
                {
                    Session["Message.Class"] = ViewError.ERROR;
                    Session["Message"]       = "Please enter in the required fields listed below.";
                }

                ViewBag.Create     = true;
                ViewBag.CanEdit    = tourny.CanEdit();
                ViewBag.InProgress = tourny.Model.InProgress;
                return(View("Create", tourny.viewModel));
            }
        }
        public JsonResult MatchInfo(int tournamentId, int bracketId, int matchId)
        {
            Models.Tournament tournament = new Models.Tournament(service, tournamentId);
            Models.Bracket    bracket    = tournament.GetBracket(bracketId);
            Models.Match      match      = bracket.GetMatchById(matchId);

            List <object> matches = new List <object>();

            matches.Add(JsonMatchResponse(match, true));

            if (match != null)
            {
                status  = true;
                message = "Match was loaded.";
                data    = new
                {
                    bracketFinished = bracket.IBracket.IsFinished,
                    isLocked        = bracket.IsLocked,
                    matches         = matches
                };
            }

            return(BundleJson());
        }
        public JsonResult SeedChange(int tournamentId, int bracketId, Dictionary <String, int> players)
        {
            if (account.IsLoggedIn())
            {
                Models.Tournament tournament = new Models.Tournament(service, tournamentId);

                if (tournament.IsAdmin(account.Model.AccountID))
                {
                    tournament.UpdateSeeds(players, bracketId);
                    status  = true;
                    message = "Seeds are updated";
                }
                else
                {
                    message = "An error occured. Please try again later";
                }
            }
            else
            {
                message = "You must login first";
            }

            return(BundleJson());
        }
        public ActionResult <Models.Tournament> UpdateTournament(int tournamentId, Models.Tournament tournament)
        {
            this._service.UpdateTournament(tournamentId, tournament);

            return(this._service.Get(tournamentId));
        }
 public ActionResult <Models.Tournament> NewTournament(Models.Tournament tournament)
 {
     return(this._service.AddTournament(tournament));
 }