public ActionResult CopyLesson(int weekNumber, int sourceGroupId, int sourceDayNumber, int sourceClassNumber,
                                       int targetGroupId, int targetDayNumber, int targetClassNumber)
        {
            var targetLessons = UnitOfWork.Repository <Lesson>()
                                .Get(x => x.GroupId == targetGroupId && x.WeekNumber == weekNumber &&
                                     x.DayNumber == targetDayNumber && x.ClassNumber == targetClassNumber &&
                                     x.DeletedAt == null);

            foreach (var targetLesson in targetLessons)
            {
                targetLesson.DeletedAt = DateTime.Now;
                UnitOfWork.Repository <Lesson>().Update(targetLesson);
                UnitOfWork.Save();
            }

            var sourceLessons = UnitOfWork.Repository <Lesson>()
                                .Get(x => x.GroupId == sourceGroupId && x.WeekNumber == weekNumber &&
                                     x.DayNumber == sourceDayNumber && x.ClassNumber == sourceClassNumber &&
                                     x.DeletedAt == null);

            foreach (var sourceLesson in sourceLessons)
            {
                var targetClassDate = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart,
                                                                   weekNumber, targetDayNumber);
                var targetLesson = new Lesson
                {
                    AuditoriumId = sourceLesson.AuditoriumId,
                    DisciplineId = sourceLesson.DisciplineId,
                    GroupId      = targetGroupId,
                    JobId        = sourceLesson.JobId,
                    LessonTypeId = sourceLesson.LessonTypeId,
                    WeekNumber   = weekNumber,
                    DayNumber    = targetDayNumber,
                    ClassNumber  = targetClassNumber,
                    ClassDate    = targetClassDate,
                    CreatedAt    = DateTime.Now,
                    LessonGuid   = Guid.NewGuid()
                };

                UnitOfWork.Repository <Lesson>().Insert(targetLesson);
                UnitOfWork.Save();

                Logger.Info("Скопировано занятие : SourceLessonId={0}, TargetLessonId={1}", sourceLesson.LessonId, targetLesson.LessonId);
            }

            var lessonCell = GetLessonViewModel(targetGroupId, weekNumber, targetDayNumber, targetClassNumber);

            return(PartialView("_LessonCell", lessonCell));
        }
Exemple #2
0
        public FindFoodDialog(string dialogId) : base(dialogId)
        {
            // ID of the child dialog that should be started anytime the component is started.
            this.InitialDialogId = dialogId;

            this.AddDialog(new ChoicePrompt("choicePrompt"));

            // Define the conversation flow using the waterfall model.
            this.AddDialog(
                new WaterfallDialog(dialogId, new WaterfallStep[]
            {
                async(stepContext, ct) =>
                {
                    return(await stepContext.PromptAsync(
                               "choicePrompt",
                               new PromptOptions
                    {
                        Choices = ChoiceFactory.ToChoices(ScheduleHelpers.GetValidPickupDays()),
                        Prompt = MessageFactory.Text("What day would you like to pickup food?"),
                        RetryPrompt = MessageFactory.Text("That's not a valid day! Please choose a valid day.")
                    },
                               ct
                               ).ConfigureAwait(false));;
                },
                async(stepContext, ct) =>
                {
                    var day = ((FoundChoice)stepContext.Result).Value;
                    var filteredFoodBanks = ScheduleHelpers.FilterFoodBanksByPickup(day);
                    var carousel          = UXHelpers.CreateFoodBankPickupCarousel(filteredFoodBanks).AsMessageActivity();

                    // Create the activity and attach a set of Hero cards.
                    await stepContext.Context.SendActivityAsync(carousel).ConfigureAwait(false);;

                    return(await stepContext.EndDialogAsync().ConfigureAwait(false));;
                }
            }
                                    )
                );
        }
        public ActionResult EditableWeeks(bool showWeekType = true)
        {
            if (Request.IsAjaxRequest())
            {
                var groups = GetEditableGroups()
                             .ToList();

                var yearStartDate = UserProfile.EducationYear.DateStart;
                var currentWeek   = ScheduleHelpers.WeekOfLesson(yearStartDate, DateTime.Now);

                var viewModel = new ChangeWeekViewModel
                {
                    EditedWeek           = UserProfile.WeekNumber,
                    EditedWeekStartDate  = ScheduleHelpers.DateOfLesson(yearStartDate, UserProfile.WeekNumber, 1).ToString("dd.MM.yyyy"),
                    EditedWeekEndDate    = ScheduleHelpers.DateOfLesson(yearStartDate, UserProfile.WeekNumber, 7).ToString("dd.MM.yyyy"),
                    CurrentWeek          = currentWeek,
                    CurrentWeekStartDate = ScheduleHelpers.DateOfLesson(yearStartDate, currentWeek, 1).ToString("dd.MM.yyyy"),
                    CurrentWeekEndDate   = ScheduleHelpers.DateOfLesson(yearStartDate, currentWeek, 7).ToString("dd.MM.yyyy"),
                    Weeks = new List <WeekViewModel>()
                };

                // Необходим график учебного процесса чтобы узнать количество недель
                var courseSchedules = new List <CourseSchedule>();
                foreach (var group in groups)
                {
                    var courseNumber = group.Course.CourseNumber;
                    var academicPlan = group.ProgramOfEducation.AcademicPlans
                                       .OrderByDescending(d => d.UploadedAt)
                                       .FirstOrDefault();

                    if (academicPlan != null)
                    {
                        var courseSchedule = academicPlan.CourseSchedules
                                             .SingleOrDefault(x => x.CourseNumber == courseNumber);

                        courseSchedules.Add(courseSchedule);
                    }
                }

                // Если для всех групп загружен учебный план
                if (groups.Count == courseSchedules.Count && showWeekType)
                {
                    var allEquals = courseSchedules.All(o => o.Schedule == courseSchedules[0].Schedule);
                    if (allEquals)
                    {
                        var courseSchedule = courseSchedules.First();
                        for (int index = 1; index <= courseSchedule.Schedule.Length; index++)
                        {
                            var weekStartDate = ScheduleHelpers.DateOfLesson(yearStartDate, index, 1);
                            var weekEndDate   = ScheduleHelpers.DateOfLesson(yearStartDate, index, 7);

                            var currentAbbr  = courseSchedule.Schedule[index - 1];
                            var scheduleType = ScheduleHelpers.ScheduleTypeByAbbr(currentAbbr);

                            var week = new WeekViewModel
                            {
                                WeekNumber        = index,
                                WeekStartDate     = weekStartDate.ToString("dd.MM.yyyy"),
                                WeekEndDate       = weekEndDate.ToString("dd.MM.yyyy"),
                                ScheduleTypeName  = scheduleType["Name"],
                                ScheduleTypeColor = scheduleType["Color"]
                            };

                            viewModel.Weeks.Add(week);
                        }
                    }
                }
                else
                {
                    int index = 1;
                    while (true)
                    {
                        var weekStartDate = ScheduleHelpers.DateOfLesson(yearStartDate, index, 1);
                        var weekEndDate   = ScheduleHelpers.DateOfLesson(yearStartDate, index, 7);

                        var weekInEducationYear = DateHelpers.DatesIsActual(UserProfile.EducationYear, weekStartDate, weekEndDate);
                        if (!weekInEducationYear)
                        {
                            break;
                        }

                        var week = new WeekViewModel
                        {
                            WeekNumber    = index,
                            WeekStartDate = weekStartDate.ToString("dd.MM.yyyy"),
                            WeekEndDate   = weekEndDate.ToString("dd.MM.yyyy")
                        };

                        viewModel.Weeks.Add(week);

                        index++;
                    }
                }

                return(Json(viewModel));
            }

            return(null);
        }
        public ActionResult EditLesson(EditLessonViewModel viewModel)
        {
            if (!Request.IsAjaxRequest())
            {
                return(new HttpStatusCodeResult(404));
            }

            if (!ModelState.IsValid)
            {
                var allErrors = ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors).ToList();
                foreach (ModelError error in allErrors)
                {
                    var message = error.ErrorMessage;
                }

                return(null);
            }

            // Удаление занятия(ий)
            var viewModelLessonIds = viewModel.Lessons.SelectMany(x => x.LessonParts).Select(p => p.LessonId);
            var lessonsForDelete   = UnitOfWork.Repository <Lesson>()
                                     .Get(x => x.GroupId == viewModel.GroupId && x.WeekNumber == viewModel.WeekNumber &&
                                          x.DayNumber == viewModel.DayNumber && x.ClassNumber == viewModel.ClassNumber &&
                                          x.DeletedAt == null)
                                     .Where(x => !viewModelLessonIds.Contains(x.LessonId));

            foreach (var lesson in lessonsForDelete)
            {
                lesson.DeletedAt = DateTime.Now;
                UnitOfWork.Repository <Lesson>().Update(lesson);
                UnitOfWork.Save();

                Logger.Info("Занятие помечено как удалённое : LessonId=" + lesson.LessonId);
            }

            // Создание и обновление занятий
            foreach (var lessonViewModel in viewModel.Lessons)
            {
                foreach (var lessonPartViewModel in lessonViewModel.LessonParts)
                {
                    var lessonId = lessonPartViewModel.LessonId;
                    var lesson   = UnitOfWork.Repository <Lesson>()
                                   .Get(x => x.LessonId == lessonId)
                                   .SingleOrDefault();

                    // Обновление занятия
                    if (lesson != null)
                    {
                        lesson.LessonTypeId = lessonViewModel.LessonTypeId;
                        lesson.DisciplineId = lessonViewModel.DisciplineId;
                        lesson.AuditoriumId = lessonPartViewModel.AuditoriumId;
                        lesson.JobId        = lessonPartViewModel.TeacherId;
                        // lesson.IsNotActive = lessonPartViewModel.IsNotActive;
                        lesson.UpdatedAt = DateTime.Now;

                        UnitOfWork.Repository <Lesson>().Update(lesson);
                        UnitOfWork.Save();

                        Logger.Info("Обновлено занятие : LessonId=" + lesson.LessonId);
                    }
                    // Создание нового занятия
                    else
                    {
                        var classDate = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart,
                                                                     viewModel.WeekNumber, viewModel.DayNumber);
                        lesson = new Lesson
                        {
                            LessonGuid   = Guid.NewGuid(),
                            WeekNumber   = viewModel.WeekNumber,
                            DayNumber    = viewModel.DayNumber,
                            ClassNumber  = viewModel.ClassNumber,
                            ClassDate    = classDate,
                            GroupId      = viewModel.GroupId,
                            LessonTypeId = lessonViewModel.LessonTypeId,
                            DisciplineId = lessonViewModel.DisciplineId,
                            AuditoriumId = lessonPartViewModel.AuditoriumId,
                            JobId        = lessonPartViewModel.TeacherId,
                            // IsNotActive = lessonPartViewModel.IsNotActive,
                            CreatedAt = DateTime.Now,
                        };

                        UnitOfWork.Repository <Lesson>().Insert(lesson);
                        UnitOfWork.Save();

                        Logger.Info("Создано новое занятие : LessonId=" + lesson.LessonId);
                    }
                }
            }

            var lessonCell = GetLessonViewModel(viewModel.GroupId, viewModel.WeekNumber, viewModel.DayNumber,
                                                viewModel.ClassNumber);

            return(PartialView("_LessonCell", lessonCell));
        }
Exemple #5
0
        public ContactDialog(string dialogId) : base(dialogId)
        {
            const string FOODBANKNAME = "foodBankName";
            const string EMAILADDRESS = "emailAddress";
            const string MESSAGE      = "message";

            // ID of the child dialog that should be started anytime the component is started.
            this.InitialDialogId = dialogId;

            this.AddDialog(new ChoicePrompt("choicePrompt"));
            this.AddDialog(new TextPrompt("textPrompt"));
            this.AddDialog(new ConfirmPrompt("confirmPrompt"));

            // Define the conversation flow using the waterfall model.
            this.AddDialog(
                new WaterfallDialog(dialogId, new WaterfallStep[]
            {
                async(stepContext, ct) =>
                {
                    return(await stepContext.PromptAsync(
                               "choicePrompt",
                               new PromptOptions
                    {
                        Choices = ChoiceFactory.ToChoices(ScheduleHelpers.GetFoodBanks()),
                        Prompt = MessageFactory.Text("Which food bank would you like to contact?"),
                        RetryPrompt = MessageFactory.Text("That's not a valid food bank! Please choose a valid food bank.")
                    },
                               ct
                               ).ConfigureAwait(false));;
                },
                async(stepContext, ct) =>
                {
                    // Persist the food bank name for later waterfall steps to be able to access it
                    stepContext.Values.Add(FOODBANKNAME, ((FoundChoice)stepContext.Result).Value);

                    return(await stepContext.PromptAsync("textPrompt", new PromptOptions
                    {
                        Prompt = MessageFactory.Text($"Please enter an email address where {stepContext.Values[FOODBANKNAME]} can message you back at:")
                    },
                                                         ct
                                                         ).ConfigureAwait(false));;
                },
                async(stepContext, ct) =>
                {
                    // Persist the email address for later waterfall steps to be able to access it
                    stepContext.Values.Add(EMAILADDRESS, (string)stepContext.Result);

                    return(await stepContext.PromptAsync("textPrompt", new PromptOptions
                    {
                        Prompt = MessageFactory.Text($"Please enter the message you'd like to send to {stepContext.Values[FOODBANKNAME]}:")
                    },
                                                         ct
                                                         ).ConfigureAwait(false));;
                },
                async(stepContext, ct) =>
                {
                    // Persist the message for later waterfall steps to be able to access it
                    stepContext.Values.Add(MESSAGE, (string)stepContext.Result);

                    return(await stepContext.PromptAsync("confirmPrompt", new PromptOptions
                    {
                        Prompt = MessageFactory.Text($"Are you sure you'd like to send:\r \"{stepContext.Values[MESSAGE]}\"\r to {stepContext.Values[FOODBANKNAME]}?")
                    },
                                                         ct
                                                         ).ConfigureAwait(false));
                },
                async(stepContext, ct) =>
                {
                    // Simulates sending of a message (nothing is actually being sent anywhere)
                    if ((bool)stepContext.Result)
                    {
                        ScheduleHelpers.SendFoodbankMessage((string)stepContext.Values[FOODBANKNAME], (string)stepContext.Values[EMAILADDRESS], (string)stepContext.Values[MESSAGE]);
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Great! We've sent your message to {stepContext.Values[FOODBANKNAME]}. Expect your response to be sent to {stepContext.Values[EMAILADDRESS]}"), ct).ConfigureAwait(false);;
                    }
                    else
                    {
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"No worries! I won't send your message"), ct).ConfigureAwait(false);
                    }

                    return(await stepContext.EndDialogAsync().ConfigureAwait(false));;
                }
            }
                                    )
                );
        }
Exemple #6
0
        public ActionResult ChartData(int groupId)
        {
            if (!Request.IsAjaxRequest())
            {
                return(null);
            }

            var academicPlan = UnitOfWork.Repository <Domain.Models.AcademicPlan>()
                               .GetQ(filter: x => x.ProgramOfEducation.Groups.Any(g => g.GroupId == groupId))
                               .OrderByDescending(d => d.UploadedAt)
                               .FirstOrDefault();

            if (academicPlan == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            var courseSchedule = academicPlan.CourseSchedules
                                 .SingleOrDefault(x => x.CourseNumber == UserProfile.EducationYear.YearStart - academicPlan.ProgramOfEducation.YearStart + 1);

            if (courseSchedule == null)
            {
                return(new HttpStatusCodeResult(404, "Учебный план загружен некорректно."));
            }

            var chartSeries = new List <ChartSeriesViewModel>();

            // Вычисляем периоды в графике обучения
            int startWeek = 1;

            for (int currentWeek = 1; currentWeek <= courseSchedule.Schedule.Length - 1; currentWeek++)
            {
                var currentAbbr = courseSchedule.Schedule[currentWeek - 1];
                var nextAbbr    = courseSchedule.Schedule[currentWeek];
                if (currentAbbr != nextAbbr || currentWeek == courseSchedule.Schedule.Length - 1)
                {
                    var series = chartSeries.SingleOrDefault(x => x.name == currentAbbr + "");
                    if (series == null)
                    {
                        var scheduleType = ScheduleHelpers.ScheduleTypeByAbbr(currentAbbr);
                        series = new ChartSeriesViewModel
                        {
                            name       = scheduleType["Name"],
                            color      = scheduleType["Color"],
                            pointWidth = 12,
                            pointRange = 24 * 3600 * 1000
                        };
                        chartSeries.Add(series);
                    }

                    if (series.data == null)
                    {
                        series.data = new List <ChartIntervalViewModel>();
                    }

                    // Т.к. индексация массива начинается с 0, чтобы перейти к последней неделе
                    if (currentWeek == courseSchedule.Schedule.Length - 1)
                    {
                        currentWeek++;
                    }

                    var low  = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart, startWeek, 1);
                    var high = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart, currentWeek, 7).AddDays(1).AddSeconds(-1);

                    var interval = new ChartIntervalViewModel
                    {
                        x        = 0,
                        low      = (long)(low - new DateTime(1970, 1, 1)).TotalMilliseconds,
                        high     = (long)(high - new DateTime(1970, 1, 1)).TotalMilliseconds,
                        lowWeek  = startWeek,
                        highWeek = currentWeek
                    };
                    series.data.Add(interval);

                    startWeek   = currentWeek + 1;
                    currentAbbr = nextAbbr;
                }
            }

            return(Json(
                       new
            {
                educationYear = UserProfile.EducationYear.YearStart + "/" + UserProfile.EducationYear.YearEnd,
                chartSeries = chartSeries
            }));
        }
Exemple #7
0
        public ActionResult Info(int groupId)
        {
            var group = UnitOfWork.Repository <Group>()
                        .Get(x => x.GroupId == groupId && x.IsDeleted != true)
                        .SingleOrDefault();

            if (group == null)
            {
                return(new HttpStatusCodeResult(404, "Группы с данным идентификатором не существует."));
            }

            var academicPlan = UnitOfWork.Repository <Domain.Models.AcademicPlan>()
                               .GetQ(filter: x => x.ProgramOfEducation.Groups.Any(g => g.GroupId == groupId))
                               .OrderByDescending(d => d.UploadedAt)
                               .FirstOrDefault();

            if (academicPlan == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            var courseSchedule = academicPlan.CourseSchedules
                                 .SingleOrDefault(x => x.CourseNumber == UserProfile.EducationYear.YearStart - academicPlan.ProgramOfEducation.YearStart + 1);

            if (courseSchedule == null)
            {
                return(new HttpStatusCodeResult(404, "Учебный план загружен некорректно."));
            }

            // Общая информация о группе и график обучения на каждый семестр учебного года
            var viewModel = new GroupInfoViewModel
            {
                GroupId          = groupId,
                GroupName        = group.DivisionName,
                NumberOfStudents = group.NumberOfStudents,
                Profile          = group.ProgramOfEducation.EducationProfile.EducationDirection.EducationDirectionCode
                                   + " " + group.ProgramOfEducation.EducationProfile.EducationProfileName,
                EducationForm     = group.ProgramOfEducation.EducationForm.EducationFormName,
                EducationLevel    = group.ProgramOfEducation.EducationLevel.EducationLevelName,
                NumberOfSemesters = courseSchedule.SemesterSchedules.Count,
                SemesterSchedules = courseSchedule.SemesterSchedules
                                    .Select(x => new SemesterScheduleViewModel
                {
                    SemesterNumber           = x.SemesterNumber,
                    SemesterStartDate        = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart, x.NumberOfFirstWeek, 1),
                    SemesterEndDate          = ScheduleHelpers.DateOfLesson(UserProfile.EducationYear.DateStart, (x.NumberOfFirstWeek - 1) + x.NumberOfLastWeek, 7),
                    TheoreticalTrainingWeeks = x.TheoreticalTrainingWeeks,
                    ExamSessionWeeks         = x.ExamSessionWeeks,
                    WeeksOfHolidays          = x.WeeksOfHolidays,
                    FinalQualifyingWorkWeeks = x.FinalQualifyingWorkWeeks,
                    StudyTrainingWeeks       = x.StudyTrainingWeeks,
                    PracticalTrainingWeeks   = x.PracticalTrainingWeeks,
                    StateExamsWeeks          = x.StateExamsWeeks,
                    ResearchWorkWeeks        = x.ResearchWorkWeeks
                })
                                    .OrderBy(n => n.SemesterNumber)
                                    .ToList()
            };

            // План по каждой дисциплине
            var disciplines = courseSchedule.SemesterSchedules
                              .SelectMany(x => x.DisciplineSemesterPlans)
                              .GroupBy(g => new { g.Discipline })
                              .Select(x => new DisciplineViewModel
            {
                DisciplineId            = x.Key.Discipline.DisciplineId,
                DisciplineName          = x.Key.Discipline.DisciplineName,
                ChairId                 = x.Key.Discipline.ChairId,
                ChairName               = x.Key.Discipline.Chair.DivisionName,
                DisciplineSemesterPlans = x.Select(y =>
                                                   new DisciplineSemesterPlanViewModel
                {
                    HoursOfLaboratory = y.HoursOfLaboratory,
                    HoursOfLectures   = y.HoursOfLectures,
                    HoursOfPractice   = y.HoursOfPractice,
                    //LecturesPerWeek = y.LecturesPerWeek,
                    //LaboratoryPerWeek = y.LaboratoryPerWeek,
                    //PracticePerWeek = y.PracticePerWeek,
                    LecturesPerWeek       = (float)Math.Round((double)(y.HoursOfLectures ?? 0) / y.SemesterSchedule.TheoreticalTrainingWeeks, MidpointRounding.AwayFromZero),
                    LaboratoryPerWeek     = (float)Math.Round((double)(y.HoursOfLaboratory ?? 0) / y.SemesterSchedule.TheoreticalTrainingWeeks, MidpointRounding.AwayFromZero),
                    PracticePerWeek       = (float)Math.Round((double)(y.HoursOfPractice ?? 0) / y.SemesterSchedule.TheoreticalTrainingWeeks, MidpointRounding.AwayFromZero),
                    HoursOfLecturesFilled = y.Discipline.Lessons
                                            .Count(ls => ls.DeletedAt == null && ls.GroupId == groupId && ls.LessonTypeId == (int)LessonTypes.Lection &&
                                                   ls.WeekNumber >= y.SemesterSchedule.NumberOfFirstWeek && ls.WeekNumber <= y.SemesterSchedule.NumberOfLastWeek) * 2,
                    HoursOfPracticeFilled = y.Discipline.Lessons
                                            .Count(ls => ls.DeletedAt == null && ls.GroupId == groupId &&
                                                   (ls.LessonTypeId == (int)LessonTypes.PracticalLesson || ls.LessonTypeId == (int)LessonTypes.Seminar || ls.LessonTypeId == (int)LessonTypes.Training) &&
                                                   ls.WeekNumber >= y.SemesterSchedule.NumberOfFirstWeek && ls.WeekNumber <= y.SemesterSchedule.NumberOfLastWeek) * 2,
                    HoursOfLaboratoryFilled = y.Discipline.Lessons
                                              .Count(ls => ls.DeletedAt == null && ls.GroupId == groupId && ls.LessonTypeId == (int)LessonTypes.LaboratoryWork &&
                                                     ls.WeekNumber >= y.SemesterSchedule.NumberOfFirstWeek && ls.WeekNumber <= y.SemesterSchedule.NumberOfLastWeek) * 2,
                    SemesterNumber = y.SemesterSchedule.SemesterNumber
                })
                                          .OrderBy(n => n.SemesterNumber)
                                          .ToList()
            })
                              .OrderBy(x => x.DisciplineName)
                              .ToList();

            viewModel.Disciplines = disciplines;

            return(View(viewModel));
        }