Ejemplo n.º 1
0
        private ActionResult UpdateTournament(viewModels.EditTournamentViewModel Model, int TournamentID = -1)
        {
            try
            {
                Tournament tournament = repository.Tournaments.FirstOrDefault(t => t.TournamentID == TournamentID);

                if (tournament == null)
                {
                    logger.Warn("Problem with id = " + TournamentID + " not found");
                    throw new HttpException(404, "Tournament not found");
                }

                tournament.Name   = Model.Name;
                tournament.Format = (TournamentFormats)Model.TournamentFormatsListID;
                tournament.Type   = (TournamentTypes)Model.TournamentTypesListID;

                tournament.ShowSolutionSendingTime = Model.ShowSolutionSendingTime;
                tournament.ShowTimer = Model.ShowTimer;

                tournament.StartDate = Model.StartDate.Add(Model.StartTime.TimeOfDay);
                tournament.EndDate   = Model.EndDate.Add(Model.EndTime.TimeOfDay);

                repository.AddTournament(tournament);

                if (tournament.Type == TournamentTypes.Close)
                {
                    repository.BindUserToTournament(tournament.TournamentID, WebSecurity.GetUserId(User.Identity.Name));
                }

                TempData["SuccessMessage"] = "Турнир успешно обновлен!";

                logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                            " \"" + User.Identity.Name + "\" update tournament \"" + TournamentID + "\"");
            }
            catch (Exception ex)
            {
                TempData["ErrorMessage"] = "Произошла ошибка при обновлении турнира.";
                logger.Error("Error occured on user " + WebSecurity.GetUserId(User.Identity.Name) +
                             " \"" + User.Identity.Name + "\" updating tournament \"" + TournamentID + "\": ", ex);
            }

            return(RedirectToAction("Update", new { TournamentID = TournamentID }));
        }
Ejemplo n.º 2
0
        public ActionResult Update(viewModels.EditTournamentViewModel Model, int TournamentID = -1, string Update = null, string Delete = null, string Cancel = null)
        {
            if (TournamentID == -1)
            {
                logger.Warn("Tournament with id = " + TournamentID + " not found");
                throw new HttpException(404, "Tournament not found");
            }

            if (Delete != null)
            {
                return(DeleteTournament(TournamentID));
            }
            if (Cancel != null)
            {
                return(CancelTournament());
            }
            if (Update != null)
            {
                return(UpdateTournament(Model, TournamentID));
            }

            return(CancelTournament());
        }
Ejemplo n.º 3
0
        public ActionResult Update(int TournamentID = -1)
        {
            logger.Debug("User " + WebSecurity.GetUserId(User.Identity.Name) +
                " \"" + User.Identity.Name + "\" visited TournamentsManagement/Tournament/Update");

            Tournament tournament = repository.Tournaments.Where(t => t.TournamentID == TournamentID).FirstOrDefault();

            if (tournament == null)
            {
                logger.Warn("Tournament with id = " + TournamentID + " not found");
                throw new HttpException(404, "Tournament not found");
            }

            EditTournamentViewModel viewModel = new EditTournamentViewModel()
                {
                    TournamentID = tournament.TournamentID,
                    Name = tournament.Name,
                    TournamentTypesListID = (int)tournament.Type,
                    TournamentFormatsListID = (int)tournament.Format,

                    ShowSolutionSendingTime = tournament.ShowSolutionSendingTime,
                    ShowTimer = tournament.ShowTimer,

                    StartDate = tournament.StartDate,
                    StartTime = tournament.StartDate,
                    EndDate = tournament.EndDate,
                    EndTime = tournament.EndDate,
                    Problems = tournament.Problems.Select(p => p.Name)
                };

            return View(viewModel);
        }