public JobController(IConfiguration configuration)
 {
     _configuration  = configuration;
     scheduleRepo    = new ScheduleRepo(configuration);
     jobRepo         = new JobRepo(configuration);
     auditLogService = new AuditLogService(HttpContext, configuration);
 }
Example #2
0
        public static void SimulateRound(int round)
        {
            List <(int id, int host, int visitor)> games = ScheduleRepo.GetRound(round);
            Random rnd = new Random();

            foreach (var game in games)
            {
                double visitorLuck = rnd.Next(8, 15) / 10.0;
                double hostLuck    = rnd.Next(8, 15) / 10.0;

                Dictionary <string, double> host    = game.host == ClubStatus.ClubId ? Calculation.GetSquad() : Calculation.GetBotSquad(game.host);
                Dictionary <string, double> visitor = game.visitor == ClubStatus.ClubId ? Calculation.GetSquad() : Calculation.GetBotSquad(game.visitor);

                int hostChances    = (int)((host["mid"] * 2 - visitor["def"]) * 1.1 * hostLuck / 11);
                int visitorChances = (int)((visitor["mid"] * 2 - host["def"]) * visitorLuck / 11);

                double hostGoalChance    = (host["st"] * 2 - visitor["gk"]) * 1.1 * hostLuck / 300;
                double visitorGoalChance = (visitor["st"] * 2 - host["gk"]) * visitorLuck / 300;

                int hostGoals    = (int)(Math.Round((hostChances < 0 ? 0 : hostChances) * (hostGoalChance < 0.20 ? 0 : hostGoalChance)));
                int visitorGoals = (int)(Math.Round((visitorChances < 0 ? 0 : visitorChances) * (visitorGoalChance < 0.20 ? 0 : visitorGoalChance)));

                ScheduleRepo.UpdateGame(game.id, hostGoals, visitorGoals);
                ClubRepo.UpdateTable(game.host, hostGoals, visitorGoals);
                ClubRepo.UpdateTable(game.visitor, visitorGoals, hostGoals);
            }
        }
Example #3
0
        private static async Task RunAsync()
        {
            var stringResp = "";
            HttpResponseMessage response = await client.GetAsync("");

            if (response.IsSuccessStatusCode)
            {
                stringResp = await response.Content.ReadAsStringAsync();
            }
            ScheduleRepo.SaveSchedule(stringResp);
        }
        public List <DisplayShiftVM> GetShiftsForEmployee()
        {
            var token    = Request.Headers["Authorization"].ToString().Replace("Bearer ", "");
            var handler  = new JwtSecurityTokenHandler();
            var tokenStr = handler.ReadJwtToken(token) as JwtSecurityToken;
            var userName = tokenStr.Claims.First(claim => claim.Type == "sub").Value;

            ScheduleRepo          repo   = new ScheduleRepo(context);
            List <DisplayShiftVM> shifts = repo.GetShiftsPerEmployee(userName);

            return(shifts);
        }
        public void PostSchedule([FromBody] List <EmployeeShiftVM> shifts)
        {
            // For more detail and better encapsulation (in a service see day 6 OnAuthorization())
            //This is our check to determine whether or not our user is a manager or not
            var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", "");

            if (PatManagerVerify.CheckIfManager(token, context))
            {
                ScheduleRepo sRepo = new ScheduleRepo(context);
                sRepo.AddScheduleItems(shifts);
            }
        }
        public UnitOfWorkPersonTest()
        {
            var dbInMemory     = DbInMemory.getDbInMemoryOptions(dbName);
            var personRepo     = new PersonRepo(dbInMemory);
            var classRepo      = new ClassRepo(dbInMemory);
            var scheduleRepo   = new ScheduleRepo(dbInMemory);
            var semesterRepo   = new SemesterRepo(dbInMemory);
            var departmentRepo = new DepartmentRepo(dbInMemory);

            db = new TCSContext(dbInMemory);
            mockBannerService = new Mock <IBannerService>();

            unitPerson = new UnitOfWorkPerson(personRepo, scheduleRepo, classRepo, semesterRepo, departmentRepo, mockBannerService.Object);
        }
Example #7
0
        public static List <Matchup> GetMatchupsForWeek(int week, int year)
        {
            var            teams         = TeamRepo.GetTeams();
            var            matchups      = ScheduleRepo.GetMatchupsForWeek(week, year);
            List <Matchup> matchups_copy = new List <Matchup>();

            foreach (var matchup in matchups)
            {
                matchup.HomeTeam   = teams.GetValueOrDefault(matchup.HomeTeamID);
                matchup.AwayTeam   = teams.GetValueOrDefault(matchup.AwayTeamID);
                matchup.Multiplier = 1;
                if (matchup.HomeTeam != null && matchup.AwayTeam != null)
                {
                    matchups_copy.Add(matchup);
                }
            }

            return(matchups_copy.OrderByDescending(x => x.AwayTeam.School == "Michigan" || x.HomeTeam.School == "Michigan")
                   .ThenByDescending(x => x.AwayTeam.School == "Michigan State" || x.HomeTeam.School == "Michigan State")
                   .ThenByDescending(x => x.AwayTeam.School == "Ohio State" || x.HomeTeam.School == "Ohio State").ToList());
        }
 private void SaveSalesAmount(string scheduleId)
 {
     try
     {
         string routeId            = ScheduleRepo.GetRouteId(scheduleId);
         int    ticketPrice        = RouteRepo.GetFare(routeId);
         int    currentSalesAmount = SalesRepo.CurrentSalesAmount(MainControl.cashierId);
         if (currentSalesAmount == 0)
         {
             int amount = ticketPrice * MainControl.selectedSeatCount;
             SalesRepo.Insert(MainControl.cashierId, amount);
         }
         else
         {
             int updatedAmount = currentSalesAmount + (ticketPrice * MainControl.selectedSeatCount);
             SalesRepo.Update(MainControl.cashierId, updatedAmount);
         }
     }catch (Exception e)
     {
         MessageBox.Show("Error!" + e.Message);
     }
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("fdsf");
            //First we have to insert data into route table and then into the schedule table
            this.RouteFill();

            Entity.Schedule schedule = new Entity.Schedule();
            try
            {
                schedule.ScheduleId = ScheduleRepo.GetId();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            schedule.DeptTime    = this.dtpDeparture.Text;
            schedule.ArrivalTime = this.dtpArrival.Text;
            schedule.RouteId     = this.Route.RouteId; //In Schedule table route_id is a foreign key.

            try
            {
                RouteRepo.Insert(this.Route);  //inserting into the route table
                ScheduleRepo.Insert(schedule); //inserting into schedule table

                MessageBox.Show("Created Successfully");

                //After inserting data the route home page will be redirected
                controlRoute route = new controlRoute();
                MainControl.showControl(route, frmAdminDashboard.ActiveForm);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Please Select A Bus No", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        public ActionResult SessionSelection()
        {
            var model = ScheduleRepo.GetSessionsByRange(DateTime.Now, DateTime.Today.AddDays(7).AddMilliseconds(-1));

            return(PartialView(model));
        }
Example #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool idExist;
            bool checkIfBusExistSignal;

            try
            {
                idExist = RouteRepo.SearchRouteId(this.disableBusIdText.Text);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }
            if (idExist) //For Update purpose
            {
                if (!this.RouteFill())
                {
                    return;
                }
                else
                {
                    Route.Status = this.routeStatus.Text;

                    //Following line used to store Route information when a row from data grid view is double clicked.
                    Route singleRouteInfo = RouteRepo.SingleRouteInfo(this.disableBusIdText.Text);

                    //Following line gets the route_id.
                    string secondRouteId = RouteRepo.CheckIfTwoRoutesExist(singleRouteInfo);

                    try
                    {
                        if (secondRouteId != null)//if two routes exist, will get a route_id, else null
                        {
                            //So there is two routes, and now checking if the bus exist to any different route if we select a different
                            //bus and click on save button.
                            checkIfBusExistSignal = RouteRepo.CheckIfBusExistInTwoRoutesForUpdate(this.cmbBus.Text, this.disableBusIdText.Text, secondRouteId);
                        }
                        else
                        {
                            //So there is one route, and now checking if the bus exist to any different route if we select a different
                            //bus and click on save button.
                            checkIfBusExistSignal = RouteRepo.CheckIfBusExistInRouteForUpdate(this.cmbBus.Text, this.disableBusIdText.Text);
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("Something went wrong when check bus exist or not");
                        throw;
                    }

                    //we will check if the bus number exist for particular route_id in route table.
                    //If exist we will not update, else will update.
                    if (checkIfBusExistSignal == false)
                    {
                        try
                        {
                            bool updateRouteSignal = RouteRepo.Update(this.Route);

                            Entity.Schedule schedule = new Entity.Schedule();
                            schedule.ScheduleId  = this.invisibleScheduleIdText.Text;
                            schedule.DeptTime    = this.dateTimePicker1.Text;
                            schedule.ArrivalTime = this.dateTimePicker2.Text;
                            schedule.RouteId     = this.disableBusIdText.Text;

                            bool updateScheduleSignal = ScheduleRepo.Update(schedule);
                            if (secondRouteId != null)
                            {
                                //MessageBox.Show("not null");
                                bool updateSecondRouteSignal = RouteRepo.UpdateSecondRoute(this.Route, secondRouteId);
                            }
                            if (updateRouteSignal && updateScheduleSignal)
                            {
                                MessageBox.Show("Route Updated Successuflly!!");

                                //Once the save button is clicked for edit, new Id, as primary key, will be generated for the route table.
                                this.disableBusIdText.Text = RouteRepo.GetId();
                                this.ClearRouteInput();
                                this.FillRouteDataGridView();
                            }
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine("Something went wrong in Update!\n" + exception);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Bus Number already Exists in different Route!\nCannot Update. Get a new Bus!");
                    }
                }
            }
            if (!idExist) //for insert purpose
            {
                if (!this.RouteFill())
                {
                    return;
                }
                else if (this.RouteFill())
                {
                    try
                    {
                        checkIfBusExistSignal = RouteRepo.CheckIfBusExistInRoute(this.cmbBus.Text);
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("Something went wrong when check bus exist or not");
                        throw;
                    }

                    //we will check if the bus number exist in route table. If exist we will not insert, else will insert.
                    if (!checkIfBusExistSignal)//if return false we will insert, else not
                    {
                        bool insertSignal;
                        try
                        {
                            insertSignal = RouteRepo.Insert(this.Route); //inserting into the route table
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show("Something went wrong when inserting route");
                            throw;
                        }

                        //First we have to insert data into route table and then into the schedule table
                        Entity.Schedule schedule = new Entity.Schedule();
                        try
                        {
                            schedule.ScheduleId = ScheduleRepo.GetId();
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show("Something went wrong when getting schedule Id");
                        }

                        schedule.DeptTime    = this.dateTimePicker1.Text;
                        schedule.ArrivalTime = this.dateTimePicker2.Text;
                        schedule.RouteId     = this.disableBusIdText.Text; //In Schedule table route_id is a foreign key.
                        //this.Route.ScheduleId = schedule.ScheduleId; //In Route table schedule_id is a foreign key.

                        bool insertSignalSchedule;
                        try
                        {
                            insertSignalSchedule = ScheduleRepo.Insert(schedule); //inserting into schedule table
                        }
                        catch (Exception exception)
                        {
                            MessageBox.Show("Something went wrong when inserting schedule");
                            throw;
                        }

                        if (insertSignal && insertSignalSchedule)
                        {
                            MessageBox.Show("Route Created Successuflly!!");

                            //Once the save button is clicked, new Id, as primary key, will be generated for the route table.
                            try
                            {
                                this.disableBusIdText.Text = RouteRepo.GetId();
                            }
                            catch (Exception exception)
                            {
                                Console.WriteLine("Something went wrong in Create!\n" + exception);
                            }

                            this.ClearRouteInput();
                            this.FillRouteDataGridView();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Bus Number already Exists in different Route!\nCannot Insert. Get a new Bus!");
                    }
                }
            }
        }
Example #12
0
        public static ResultsResponse GetResultsForWeek(int week, int year)
        {
            var result     = new ResultsResponse();
            var resultRows = new List <ResultsRow>();

            var users    = UserRepo.GetUsers();
            var games    = GameRepo.GetGamesForWeek(week, year);
            var teams    = TeamRepo.GetTeams();
            var matchups = ScheduleRepo.GetMatchupsForWeek(week, year);

            foreach (var game in games)
            {
                game.HomeTeam = teams.GetValueOrDefault(game.HomeId);
                game.AwayTeam = teams.GetValueOrDefault(game.AwayId);
                game.DateTime = matchups.Where(x => x.HomeTeamID == game.HomeId).Select(x => x.DateTime).FirstOrDefault();
                game.Day      = matchups.Where(x => x.HomeTeamID == game.HomeId).Select(x => x.Day).FirstOrDefault();

                if (game.Outcome == "Home")
                {
                    game.HomeTeam.Outcome = "Win";
                    game.AwayTeam.Outcome = "Lose";
                }
                else if (game.Outcome == "Away")
                {
                    game.AwayTeam.Outcome = "Win";
                    game.HomeTeam.Outcome = "Lose";
                }
            }

            foreach (var user in users)
            {
                if (user.Picks != null)
                {
                    var pick = user.Picks.Where(x => x.WeekNum == week && x.Year == year).FirstOrDefault();
                    if (pick != null)
                    {
                        var prevPick = new Pick();
                        if (week == 1)
                        {
                            prevPick = pick;
                        }
                        else
                        {
                            prevPick = user.Picks.Where(x => x.WeekNum == week - 1 && x.Year == year).FirstOrDefault();
                        }

                        var userTeams = new List <Team>();

                        foreach (var game in pick.Winners)
                        {
                            userTeams.Add(teams[game]);
                        }

                        user.Password = "";
                        user.Picks    = null;

                        resultRows.Add(new ResultsRow()
                        {
                            BestBetId = pick.BestBet,
                            Rank      = prevPick.Rank,
                            Teams     = userTeams,
                            User      = user
                        });
                    }
                }
            }

            result.Rows = resultRows.OrderBy(x => x.Rank).ToList();

            result.Games = games;

            return(result);
        }
Example #13
0
        public IActionResult GenerateSchedule([FromBody] CourseInfoToSchedule courseInfo)
        {
            // Get the current user.
            var user = _userManager.GetUserAsync(User).Result;

            // Check if there are no course ids, if there arn't remove all courses from schedule.
            if (courseInfo.CourseIds?.Length == 0)
            {
                // Remove all user sections for this user.
                var sectionsForUser = _context.UserSections.Where(us => us.UserId == user.Id).ToList();
                _context.UserSections.RemoveRange(sectionsForUser ?? new List <UserSection>());
                _context.SaveChanges();
                return(Json(new ScheduleViewModel()
                {
                    Error = "Please add a class to generate a schedule."
                }));
            }

            Course[] courses = _context.Courses
                               .Include(c => c.Sections)
                               .ThenInclude(s => s.Professor)
                               .Include(c => c.Sections)
                               .ThenInclude(s => s.Meetings)
                               .ThenInclude(m => m.Location)
                               .Include(c => c.Cape)
                               .ThenInclude(ca => ca.Professor)
                               .ThenInclude(p => p.RateMyProfessor)
                               .Where(c => courseInfo.CourseIds.Contains(c.Id)).ToArray();
            Optimization optimization = courseInfo.Optimization;

            var scheduleRepo = new ScheduleRepo();

            // Call the schedule finding algorithm.
            PossibleSchedules schedules = scheduleRepo.FindScheduleForClasses(courses);

            if (!schedules.Any())
            {
                // TODO: return error
                return(Json(new ScheduleViewModel()
                {
                    Error = "No possible schedule for given courses."
                }));
            }


            List <Section> schedule = ScheduleOptimizationFactory.GetOptimization(optimization).Optimize(schedules);

            // Create user sections to add.
            var sectionsToAdd = schedule.Select(s => new UserSection {
                Section = s, User = user
            });
            // Get the schedule sections for this user.
            var sectionsToRemove = _context.UserSections.Where(us => us.User == user);

            // Remove old sections.
            _context.RemoveRange(sectionsToRemove);
            // Add new ones.
            _context.AddRange(sectionsToAdd);
            _context.SaveChanges();

            ScheduleViewModel model = FormatRepo.FormatSectionsToCalendarEvent(schedule);

            model.Error = "";

            return(Json(model));
        }