Exemplo n.º 1
0
        public void GenerateRound()
        {
            var roundNumbers = new List <int>();
            var rnd          = new Random();

            var i = 0;

            while (i < 7)
            {
                var check = rnd.Next(1, 37);
                if (!roundNumbers.Contains(check))
                {
                    roundNumbers.Add(check);
                    i++;
                }
            }

            var numbers = string.Join(";", roundNumbers.OrderBy(x => x));

            var model = _roundRepository.GetAll().FirstOrDefault(r => string.IsNullOrEmpty(r.WinningComination));

            model.WinningComination = numbers;
            model.DateResults       = DateTime.Now;
            model.PayIn             = CalculateProfit(model.Id);
            model.PayOut            = CalculateLoss(model.Id);

            _roundRepository.Update(model);

            _roundRepository.Create(new Round
            {
                CreatedRound = DateTime.Now
            });
        }
        public RoundInfo GetLatestRoundInfo(int userId)
        {//TODO optimize
            GameEntity  lastGame  = _gameRepository.GetLatestGameForUser(userId);
            RoundEntity lastRound = _roundRepository.GetAll().Where(x => x.GameId == lastGame.Id).OrderByDescending(x => x.Id).FirstOrDefault();

            return(GetRoundInfo(lastRound.Id));
        }
Exemplo n.º 3
0
        public async Task <GetAllRoundsResponse> GetAll(int seasonId)
        {
            IEnumerable <Round> rounds = await _roundRepository.GetAll(seasonId);

            IEnumerable <RoundItem> roundItems = _mapper.Map <IEnumerable <RoundItem> >(rounds);
            var response = new GetAllRoundsResponse(roundItems);

            return(response);
        }
        public async Task <RoundListHistoryView> GetRoundsByGameId(int gameId)
        {
            List <Round> rounds = await _roundRepository.GetAll();

            Game game = await _gameRepository.Get(gameId);

            var data = new RoundListHistoryView();

            data.PlayersAmount = game.PlayersAmount;
            data.Rounds        = _maping.MapListRoundToRoundRoundListHistoryViewItem(rounds.Where(x => x.GameId == gameId).ToList());
            return(data);
        }
Exemplo n.º 5
0
        private IEnumerable <GameDataModel> GetResult(int id)
        {
            var data = from g in GameRepository.GetAll().ToList()
                       join p1 in PlayerRepository.GetAll().ToList() on g.playerOneId equals p1.id
                       join p2 in PlayerRepository.GetAll().ToList() on g.playerTwoId equals p2.id
                       where id == 0 || g.id == id
                       select new GameDataModel
            {
                id          = g.id,
                playerOneId = g.playerOneId,
                playerOne   = new PlayerDataModel
                {
                    id    = p1.id,
                    name  = p1.name,
                    score = RoundRepository.FindBy(r => r.gameId == g.id && g.playerOneId == r.roundWinnerId).Count()
                },
                playerTwoId = g.playerTwoId,
                playerTwo   = new PlayerDataModel
                {
                    id    = p2.id,
                    name  = p2.name,
                    score = RoundRepository.FindBy(r => r.gameId == g.id && g.playerTwoId == r.roundWinnerId).Count()
                },
                gameWinnerId = g.gameWinnerId.HasValue ? g.gameWinnerId.Value : 0,
                gameWinner   = (from w in PlayerRepository.FindBy(f => f.id == g.gameWinnerId.Value).ToList()
                                select new PlayerDataModel
                {
                    id = w.id,
                    name = w.name
                }).FirstOrDefault(),
                createdOn = g.createdOn,
                rounds    = (from r in RoundRepository.GetAll().ToList()
                             where r.gameId == g.id
                             select new RoundDataModel
                {
                    id = r.id,
                    gameId = r.gameId,
                    roundWinnerId = r.roundWinnerId.HasValue ? r.roundWinnerId.Value : 0,
                    playerOneMoveId = r.playerOneMoveId,
                    playerTwoMoveId = r.playerTwoMoveId
                })
            };

            return(data);
        }
Exemplo n.º 6
0
        public void CreateTicket(CreateTicketViewModel ticketViewModel, int userId)
        {
            ValidateNumbers(ticketViewModel.Combination);

            var combination = string.Join(";", ticketViewModel.Combination.Split(';').Select(c => int.Parse(c)).OrderBy(x => x));

            var round = _roundRepository.GetAll().FirstOrDefault(r => string.IsNullOrEmpty(r.WinningComination));

            if (round == null)
            {
                throw new Exception("No Active round!");
            }

            round.PayIn = round.PayIn == null ? round.PayIn = 0 + 50 : round.PayIn += 50;

            _roundRepository.Update(round);

            var user = _userRepository.GetById(userId);

            if (user == null)
            {
                throw new Exception("There is no User with that Id");
            }

            user.Balance -= 50;
            if (user.Balance < 0)
            {
                throw new Exception("You don't have money for the Ticket");
            }

            _userRepository.Update(user);

            var model = new Ticket
            {
                Combination = combination,
                UserId      = userId,
                Status      = Status.Pending,
                DateCreated = DateTime.Now,
                Round       = round.Id
            };

            _ticketRepository.Create(model);
        }
Exemplo n.º 7
0
        public ActionResult Index(InterviewSearchViewModel vm)
        {
            ViewBag.CandidateId   = new SelectList(_candidateRepository.GetAll(o => o.OrderByDescending(c => c.Id), "Person").Select(c => new { c.Id, Name = c.Person.Name + "- [" + c.Code + "]" }), "Id", "Name");
            ViewBag.InterviewerId = new SelectList(_userRepository.GetAllBy(u => u.EmployeeStatus != EmployeeStatus.Ex && u.Id != 1, "Person"), "Id", "Person.Name");
            ViewBag.JobOpeningId  = new SelectList(_jobOpeningRepository.GetAll(), "Id", "Title");
            ViewBag.RoundId       = new SelectList(_roundRepository.GetAll(), "Id", "Title");

            Func <IQueryable <InterviewRound>, IQueryable <InterviewRound> > interviewRoundFilter = q =>
            {
                q = q.Include("Candidate.Person")
                    .Include("Interviewer.Person")
                    .Include(i => i.JobOpening)
                    .Include(i => i.Round);


                if (vm.JobId.HasValue)
                {
                    q = q.Where(r => r.JobOpeningId == vm.JobId.Value);
                }

                if (vm.CandidateId.HasValue)
                {
                    q = q.Where(r => r.CandidateId == vm.CandidateId.Value);
                }

                if (vm.InterviewerId.HasValue)
                {
                    q = q.Where(r => r.InterviewerId == vm.InterviewerId.Value);
                }

                if (vm.RoundId.HasValue)
                {
                    q = q.Where(r => r.RoundId == vm.RoundId.Value);
                }

                if (vm.Status.HasValue)
                {
                    q = q.Where(r => r.Status == vm.Status.Value);
                }

                return(q);
            };

            vm.Interviews = _interviewRoundRepository.SearchPage(interviewRoundFilter, o => o.OrderByDescending(c => c.ScheduledOn), vm.GetPageNo(), vm.PageSize);

            return(View(vm));
        }
Exemplo n.º 8
0
        public ActionResult Interviews(InterviewSearchViewModel vm)
        {
            return(RedirectIfNotLoggedIn(() =>
            {
                ViewBag.JobOpeningId = new SelectList(_jobOpeningRepository.GetAll(), "Id", "Title");
                ViewBag.RoundId = new SelectList(_roundRepository.GetAll(), "Id", "Title");
                var candidateId = int.Parse(Session[PortalKeyId].ToString());

                Func <IQueryable <InterviewRound>, IQueryable <InterviewRound> > interviewRoundFilter = q =>
                {
                    q = q.Include("Candidate.Person")
                        .Include(i => i.JobOpening)
                        .Include(i => i.Round);

                    q = q.Where(r => r.CandidateId == candidateId);

                    if (vm.JobId.HasValue)
                    {
                        q = q.Where(r => r.JobOpeningId == vm.JobId.Value);
                    }

                    if (vm.RoundId.HasValue)
                    {
                        q = q.Where(r => r.RoundId == vm.RoundId.Value);
                    }

                    if (vm.Status.HasValue)
                    {
                        q = q.Where(r => r.Status == vm.Status.Value);
                    }

                    return q;
                };

                vm.Interviews = _interviewRoundRepository.SearchPage(interviewRoundFilter, o => o.OrderByDescending(c => c.ScheduledOn), vm.GetPageNo(), vm.PageSize);
                return View(vm);
            }));
        }
Exemplo n.º 9
0
        public ActionResult Details(int id)
        {
            var candidate = _candidateRepository.Get(id, "Person");

            if (candidate == null)
            {
                return(HttpNotFound());
            }

            ViewBag.InterviewerId = new MultiSelectList(_userRepository.GetAllBy(u => u.EmployeeStatus != EmployeeStatus.Ex && u.Id != 1, "Person"), "Id", "Person.Name");
            ViewBag.JobOpeningId  = new SelectList(_jobOpeningRepository.GetAll(), "Id", "Title");
            ViewBag.RoundId       = new SelectList(_roundRepository.GetAll(), "Id", "Title");

            var candidateDocs = _candidateDocumentRepository.GetAllBy(m => m.CandidateId == candidate.Id);
            var rounds        = _interviewRoundRepository.GetAllBy(m => m.CandidateId == candidate.Id, "Interviewer.Person,Round");

            var vm = new CandidateDetailsViewModel(candidate)
            {
                CandidateDocuments = candidateDocs.ToList(),
                InterviewRounds    = rounds.ToList()
            };

            return(View(vm));
        }
 public List <Round> GetRounds(int gameKey)
 {
     return(_roundRepository.GetAll(gameKey));
 }
 public IHttpActionResult Get()
 {
     return(Json(roundRepository.GetAll()));
 }
Exemplo n.º 12
0
        public ActionResult Index()
        {
            var rounds = _roundRepository.GetAll();

            return(View(rounds));
        }
Exemplo n.º 13
0
 public IEnumerable <Round> GetAll()
 {
     return(_roundRepository.GetAll());
 }
Exemplo n.º 14
0
        public JsonResult Index()
        {
            var apiResult = TryExecute(() => _roundRepository.GetAll(), "Interview Rounds Fetched sucessfully");

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }