Example #1
0
 public IQueryable <AdditionalGame> GetAllAdditionalGamesAsIQueryable(BranchOfficeEnum branchOffice)
 {
     return(context.AdditionalGames
            .Include(b => b.Barmaid)
            .Include(i => i.Instructor)
            .Include(gt => gt.GameType)
            .Include(u => u.ApplicationUser)
            .Where(ag => ag.BranchOffice == branchOffice)
            .OrderByDescending(ad => ad.Date));
 }
Example #2
0
        // metoda pro přeuspořádání dat a výpočet provizí z přemluvených her pro jednotlivé zaměstnance
        private EmployeeGamesModel GetEmployeeGames(Employee employee, DateTime month, IEnumerable <GameType> gameTypes, BranchOfficeEnum branchOffice)
        {
            EmployeeGamesModel    employeeGames       = new EmployeeGamesModel();
            List <SimplifiedGame> simplifiedSoloGames = new List <SimplifiedGame>();
            List <SimplifiedGame> simplifiedDuoGames  = new List <SimplifiedGame>();

            // přemluvené hry v roli instruktor
            if (employee.Role == EmployeeRoleEnum.Instruktor)
            {
                foreach (AdditionalGame game in employee.InstuctorAdditionalGames.Where(ig => ig.Date.Month == month.Month && ig.BranchOffice == branchOffice))
                {
                    SimplifiedGame simplifiedGame = new SimplifiedGame(game);

                    if (game.BarmaidId.HasValue)
                    {
                        simplifiedDuoGames.Add(simplifiedGame);
                    }
                    else
                    {
                        simplifiedSoloGames.Add(simplifiedGame);
                    }
                }
            }
            // přemluvené hry v roli hlavní barmanka
            else if (employee.Role == EmployeeRoleEnum.Hlavni_barmanka)
            {
                foreach (AdditionalGame game in employee.BarmaidAdditionalGames.Where(bg => bg.Date.Month == month.Month && bg.BranchOffice == branchOffice))
                {
                    SimplifiedGame simplifiedGame = new SimplifiedGame(game);

                    if (game.InstructorId.HasValue)
                    {
                        simplifiedDuoGames.Add(simplifiedGame);
                    }
                    else
                    {
                        simplifiedSoloGames.Add(simplifiedGame);
                    }
                }
            }

            List <SummedGame> summedDuoGames  = new List <SummedGame>();
            List <SummedGame> summedSoloGames = new List <SummedGame>();

            //Dictionary<int, int> soloGamesSummedByType = new Dictionary<int, int>();
            //Dictionary<int, int> duoGamesSummedByType = new Dictionary<int, int>();

            // součet počtů přemluvených her podle typů her
            foreach (GameType gameType in gameTypes)
            {
                int sumSolo = simplifiedSoloGames.Where(g => g.GameTypeId == gameType.Id).Sum(game => game.Count);
                summedSoloGames.Add(new SummedGame(gameType.Id, gameType.SoloCommision, sumSolo));

                if (employee.Role == EmployeeRoleEnum.Instruktor)
                {
                    int sumDuo = simplifiedDuoGames.Where(g => g.GameTypeId == gameType.Id).Sum(game => game.Count);
                    summedDuoGames.Add(new SummedGame(gameType.Id, gameType.InstruktorCommision, sumDuo));
                }
                if (employee.Role == EmployeeRoleEnum.Hlavni_barmanka)
                {
                    int sumDuo = simplifiedDuoGames.Where(g => g.GameTypeId == gameType.Id).Sum(game => game.Count);
                    summedDuoGames.Add(new SummedGame(gameType.Id, gameType.BarmaidCommision, sumDuo));
                }
            }

            // výpočet provize ze "sólo" přemluvených her
            int totalSoloCommision = 0;

            summedSoloGames.ForEach(g => {
                totalSoloCommision += g.Commision * g.Count;
            });
            // výpořet provize ze "společných" přemluvených her
            int totalDuoCommision = 0;

            summedDuoGames.ForEach(g => {
                totalDuoCommision += g.Commision * g.Count;
            });

            employeeGames.Employee        = employee;
            employeeGames.SummedSoloGames = summedSoloGames;
            employeeGames.SummedDuoGames  = summedDuoGames;
            employeeGames.TotalCommision  = totalSoloCommision + totalDuoCommision;

            return(employeeGames);
        }