Exemplo n.º 1
0
        public void DeleteTournament(Tournament Tournament)
        {
            context.Entry(Tournament).State = EntityState.Deleted;

            context.SaveChanges();

            return;
        }
Exemplo n.º 2
0
        public ActionResult Create(viewModels.NewTournamentViewModel Model)
        {
            if (ModelState.IsValid)
            {
                int tournamentID = -1;

                // Attempt to create new tournament
                try
                {
                    Tournament tournament = new Tournament
                    {
                        Name = Model.Name,
                        Type = (TournamentTypes)Model.TournamentTypesListID,
                        Format = (TournamentFormats)Model.TournamentFormatsListID,

                        ShowSolutionSendingTime = Model.ShowSolutionSendingTime,
                        ShowTimer = Model.ShowTimer,

                        StartDate = Model.StartDate.Add(Model.StartTime.TimeOfDay),
                        EndDate = Model.EndDate.Add(Model.EndTime.TimeOfDay)
                    };
                    int userID = WebSecurity.CurrentUserId;
                    if (userID != 1)
                    {
                        UserProfile user = repository.Users.FirstOrDefault(u => u.UserId == userID);
                        tournament.UsersCanModify = new List<UserProfile>();
                        tournament.UsersCanModify.Add(user);
                    }
                    tournamentID = repository.AddTournament(tournament);

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

                    logger.Info("User " + WebSecurity.GetUserId(User.Identity.Name) +
                        " \"" + User.Identity.Name + "\" create tournament " + tournamentID + " \"" + Model.Name + "\"");

                    return RedirectToAction("BindProblemsToTournament", new { tournamentID = tournament.TournamentID });
                }
                catch (Exception ex)
                {
                    logger.Error("Error occurred on user " + WebSecurity.GetUserId(User.Identity.Name) +
                        " \"" + User.Identity.Name + "\" creating tournament " + tournamentID + " \"" + Model.Name + "\": ", ex);

                    ModelState.AddModelError("", "Произошла ошибка при создании турнира");
                }
            }

            return View(Model);
        }
Exemplo n.º 3
0
        public int AddTournament(Tournament Tournament)
        {
            if (Tournament.TournamentID == 0)
            {
                context.Tournaments.Add(Tournament);
            }
            else
            {
                context.Entry(Tournament).State = EntityState.Modified;
            }
            context.SaveChanges();
            context.Entry(Tournament).Reload();

            return Tournament.TournamentID;
        }