public IActionResult Dashboard(int classId)
        {
            ClassStudentVM dashboardNeeds = new ClassStudentVM();
            var            instructorList = _classDataAccess.GetInstructorsConnectedToClass(classId, GetCurrentStudioId());
            var            studentsIdList = _classDataAccess.GetStudentsConnectedToClass(classId, GetCurrentStudioId());
            var            _class         = _classDataAccess.SearchClass(classId, GetCurrentStudioId());

            foreach (var idsIns in instructorList)
            {
                var instructor = _instructorDataAccess.GetInstructorById(idsIns);
                dashboardNeeds.InstructorsList.Add(instructor);
            }

            foreach (var idsStu in studentsIdList)
            {
                var student = _studentDataAccess.GetStudentById(idsStu);
                dashboardNeeds.StudentsList.Add(student);
            }

            dashboardNeeds.PricePerHour = _class.PricePerHour;
            dashboardNeeds.Level        = _class.Level;
            dashboardNeeds.ClassId      = classId;
            var shedule = _classDataAccess.GetClassShedule(classId);

            foreach (var s in shedule)
            {
                dashboardNeeds.SheduleDays.Add($" {s.Day} - {s.Hour} ");
            }

            return(Json(dashboardNeeds));
        }
        public List <CalendarData> GetAllClassesShedule(CalendarSearchVM calendarSearch, int studioId)
        {
            var calData = new List <CalendarData>();

            List <Class> classes = classDataAccess.GetAllClasses(studioId);

            foreach (var _class in classes)
            {
                List <Shedule>    shedules      = classDataAccess.GetClassShedule(_class.Id);
                List <int>        idInstructors = classDataAccess.GetInstructorsConnectedToClass(_class.Id, studioId);
                List <Instructor> instructors   = new List <Instructor>();

                foreach (var id in idInstructors)
                {
                    instructors.Add(instructorDataAccess.GetInstructorById(id));
                }

                foreach (var s in shedules)
                {
                    List <DayVM> classesDays = new List <DayVM>();
                    foreach (var day in calendarSearch.Days)
                    {
                        if ((day.Day.DayOfWeek.ToString() == s.Day) && _class.StartDay.Date < day.Day.Date)
                        {
                            classesDays.Add(new DayVM {
                                Day = day.Day.Date, WorkDay = day.WorkDay
                            });
                        }
                    }
                    calData.Add(new CalendarData {
                        Hour = s.Hour, Level = _class.Level, Name = _class.Genre, SheduleDays = classesDays, Instructors = instructors, NumberOfStudents = _class.NumberOfStudents
                    });
                }
            }

            return(calData);
        }
        public IActionResult SearchProfitForPeriod(DateTime dateFrom, DateTime dateTo, string classGenre, string level, string type)
        {
            List <Profit> finalProfit     = new List <Profit>();
            var           _class          = new List <Class>();
            DateTime      defaultDatetime = default(DateTime);
            var           firstDayOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            if (dateFrom != defaultDatetime && dateTo != defaultDatetime || classGenre != null || level != null)
            {
                _class = _classDataAccess.SearchClass(classGenre, level, type, GetCurrentStudioId());
            }
            else
            {
                _class   = _classDataAccess.GetAllClasses(GetCurrentStudioId());
                dateFrom = firstDayOfMonth;
                dateTo   = DateTime.Now.Date;
            }
            if (_class.Count > 0)
            {
                foreach (var c in _class)
                {
                    Profit profit      = new Profit();
                    var    attendances = _attendanceDataAccess.SearchAttendancesByClassId(c.Id);

                    profit.ProfitForPeriod  = 0;
                    profit.NumberOfStudents = 0;
                    profit.Attendances      = 0;
                    profit.Level            = c.Level;
                    profit.ClassGenre       = c.Genre;
                    profit.Type             = c.ClassType;
                    profit.DateFrom         = dateFrom.ToString("MM-dd-yyyy");
                    profit.DateTo           = dateTo.ToString("MM-dd-yyyy");

                    for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1))
                    {
                        foreach (var at in attendances)
                        {
                            double sum = 0;
                            var    numberOfStudents = 0;

                            if (at.Date == date)
                            {
                                double instructorPay = 0;
                                double procent       = 0;

                                numberOfStudents += _classDataAccess.GetStudentsConnectedToClass(at.ClassId, GetCurrentStudioId()).Count;
                                foreach (var i in _classDataAccess.GetInstructorsConnectedToClass(at.ClassId, GetCurrentStudioId()))
                                {
                                    var instructor = _instructorDataAccess.GetInstructorById(i);
                                    procent += instructor.procentOfProfit;
                                }

                                sum           = numberOfStudents * (_classDataAccess.SearchClass(at.ClassId, GetCurrentStudioId()).PricePerHour);
                                instructorPay = sum * (procent / 100);
                                sum           = sum - instructorPay;
                                profit.Attendances++;
                            }
                            profit.ProfitForPeriod += Math.Round(sum);
                        }
                    }
                    profit.NumberOfStudents = _classDataAccess.GetStudentsConnectedToClass(c.Id, GetCurrentStudioId()).Count;
                    finalProfit.Add(profit);
                }
            }
            else
            {
                string classError = "A class with this genre, level or type does not exists!";
                return(RedirectToAction("Profit", new { classError }));
            }

            return(Json(finalProfit));
        }