public ActionResult DeleteTournament(int id)
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login", new { area = "" }));
            }

            if (loggedUser.Role == Role.Player)
            {
                return(RedirectToAction("GetAllTournaments", "Tournament", new { area = "" }));
            }

            var tournamentModelFromRepository = _repository.GetTournamentById(id);

            if (tournamentModelFromRepository == null)
            {
                return(NotFound());
            }

            if (_matchRepository.IsAnyMatchInTheTournament(id))
            {
                TempData["CantDelete"] = tournamentModelFromRepository.Name;
                return(RedirectToAction(nameof(GetAllTournaments)));
            }

            _repository.DeleteTournament(tournamentModelFromRepository);
            _repository.SaveChanges();
            TempData["deleted"] = tournamentModelFromRepository.Name;
            return(RedirectToAction(nameof(GetAllTournaments))); //return to GetAllTournaments
        }
        public ActionResult GetIncomingTournament()
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            IEnumerable <TournamentReadDto> tournamentsReadDto =
                _mapper.Map <IEnumerable <TournamentReadDto> >(_repository.GetIncomingTournament());

            List <TournamentParticipants> tournamentUserReadDtos = new List <TournamentParticipants>();

            foreach (var tournamentDto in tournamentsReadDto)
            {
                var usersDto     = _mapper.Map <List <UserReadDto> >(_userRepository.GetUsersByTournament(tournamentDto.Id));
                var isRegistered = loggedUser != null && _userRepository.IsUserRegisteredForTournamentById(loggedUser.Id,
                                                                                                           tournamentDto.Id);

                if (!_matchRepository.IsAnyMatchInTheTournament(tournamentDto.Id))
                {
                    tournamentUserReadDtos.Add(new TournamentParticipants(tournamentDto, usersDto, isRegistered));
                }
            }

            //return View((_mapper.Map<IEnumerable<TournamentReadDto>>(tournaments)));
            return(View(tournamentUserReadDtos));
        }
        public ActionResult UpdateTournamentView(int id /*[FromForm] TournamentCreateDto tournamentCreateDto*/)
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login", new { area = "" }));
            }

            if (loggedUser.Role == Role.Player)
            {
                return(RedirectToAction("GetAllTournaments", "Tournament", new { area = "" }));
            }
            var tournamentModelFromRepository = _repository.GetTournamentById(id);

            if (tournamentModelFromRepository == null)
            {
                return(NotFound());
            }

            TournamentCreateDto tournamentCreateDto = _mapper.Map <TournamentCreateDto>(tournamentModelFromRepository);

            //_mapper.Map(tournamentCreateDto, tournamentModelFromRepository); //updating

            //_repository.UpdateTournament(tournamentModelFromRepository);
            //_repository.SaveChanges();

            return(View("CreateTournamentView", tournamentCreateDto));
        }
        public IActionResult MyMatches()
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login", new { area = "" }));
            }

            if (loggedUser.Role == Role.TournamentDirector)
            {
                return(RedirectToAction("GetAllTournaments", "Tournament", new { area = "" }));
            }

            var matches    = _matchRepository.GetMatchesByUserId(loggedUser.Id);
            var matchesDto = _mapper.Map <List <MatchDto> >(matches);

            //problem with autoMapper (not mapping tournament)
            for (int i = 0; i < matchesDto.Count; i++)
            {
                matchesDto[i].TournamentDto = _mapper.Map <TournamentReadDto>(matches[i].Tournament);
            }

            return(matchesDto.Count == 0 ?
                   View("NoMatches", loggedUser) : View("/Views/UserAchievements/PlayerMatches.cshtml", new UserMatchesDto(matchesDto, loggedUser)));
        }
        public ActionResult MyTournaments()
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login", new { area = "" }));
            }

            if (loggedUser.Role == Role.TournamentDirector)
            {
                return(RedirectToAction("GetAllTournaments", "Tournament", new { area = "" }));
            }

            List <TournamentReadDto> tournaments = _mapper.Map <List <TournamentReadDto> >(
                _tournamentRepository.GetTournamentByUserId(loggedUser.Id).ToList());

            foreach (var tournament in tournaments.Where(tournament => !tournament.Completed))
            {
                tournament.Started = _tournamentRepository.IsTournamentStarted(tournament.Id);
            }
            return(tournaments.Any()
                ? View("/Views/Tournament/GetAllTournaments.cshtml",
                       _mapper.Map <IEnumerable <TournamentReadDto> >(tournaments))
                : View("NoTournaments", loggedUser));
        }
Esempio n. 6
0
        public ActionResult EditAccountView()
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login", new { area = "" }));
            }
            User user = _repository.GetUserById(loggedUser.Id);

            return(View(_mapper.Map <UserEditDto>(user)));
        }
        public ActionResult CreateTournamentView()
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login"));
            }
            if (loggedUser.Role == Role.Player)
            {
                return(RedirectToAction("GetAllTournaments", "Tournament", new { area = "" }));
            }
            return(View());
        }
Esempio n. 8
0
        public IActionResult WithdrawTournament(int id)
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login", new { area = "" }));
            }

            var enrolment = _repository.FindEnrolment(loggedUser.Id, id);

            _repository.DeleteEnrolment(enrolment);
            _repository.SaveChanges();

            return(RedirectToAction("GetIncomingTournament", "Tournament"));
        }
Esempio n. 9
0
        public IActionResult EnrolTournament(int id)
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser == null)
            {
                return(RedirectToAction("LoginView", "Login", new { area = "" }));
            }

            var enrolmentDto   = new EnrolmentDto(id, loggedUser.Id);
            var enrolmentModel = _mapper.Map <Enrolment>(enrolmentDto);

            _repository.SaveEnrolment(enrolmentModel);
            _repository.SaveChanges();

            return(RedirectToAction("GetIncomingTournament", "Tournament"));
        }
Esempio n. 10
0
        public ActionResult EditAccount([FromForm] UserEditDto userEditDto, IFormFile upload)
        {
            DeserializeUser deserializable = new DeserializeUser(new HttpContextAccessor());
            UserReadDto     loggedUser     = deserializable.GetLoggedUser();

            if (loggedUser != null)
            {
                User user = _repository.GetUserById(loggedUser.Id);
                user.FirstName = userEditDto.FirstName;
                user.LastName  = userEditDto.LastName;
                user.EMail     = userEditDto.EMail;

                if (userEditDto.Password != null)
                {
                    user.Password = userEditDto.Password;
                }


                if (upload != null)
                {
                    var image = Image.Load(upload.OpenReadStream());
                    //image.Mutate(x => x.Resize(256, 256));

                    MemoryStream stream = new MemoryStream();
                    image.SaveAsPng(stream);
                    user.Photo = stream.ToArray();
                }

                _repository.SaveChanges();
                var userSession = _mapper.Map <UserReadDto>(user);
                userSession.AvatarPhoto();
                HttpContext.Session.SetString("SessionUser", JsonConvert.SerializeObject(userSession));
            }

            return(RedirectToAction("GetAllTournaments", "Tournament", new { area = "" }));
        }