Ejemplo n.º 1
0
        public ActionResult SetClassDiscipline(ClassDisciplineInputModel discipline)
        {
            if (!Context.PersonId.HasValue)
            {
                throw new UnassignedUserException();
            }
            IList <Infraction> infractions = null;

            if (discipline.InfractionsIds != null && discipline.InfractionsIds.Count > 0)
            {
                infractions = SchoolLocator.InfractionService.GetInfractions();
                infractions = infractions.Where(x => discipline.InfractionsIds.Contains(x.Id)).ToList();
            }
            var classDisciplineModel = new ClassDiscipline
            {
                ClassId     = discipline.ClassId,
                Date        = discipline.Date,
                Id          = discipline.Id,
                Description = discipline.Description,
                Infractions = infractions ?? new List <Infraction>(),
                StudentId   = discipline.StudentId
            };
            var res = SchoolLocator.DisciplineService.SetClassDiscipline(classDisciplineModel);

            MasterLocator.UserTrackingService.SetDiscipline(Context.Login,
                                                            classDisciplineModel.ClassId,
                                                            classDisciplineModel.Date,
                                                            classDisciplineModel.Description,
                                                            classDisciplineModel.StudentId);
            return(Json(DisciplineView.Create(res, Context.PersonId.Value)));
        }
        public static DisciplineMonthCalendarViewData Create(DateTime date, bool isCurrentMonth, int currentPersonId, IList <ClassDisciplineDetails> disciplines)
        {
            disciplines = disciplines.Where(x => x.Date.Date == date.Date).ToList();
            var dscViewDataList = DisciplineView.Create(disciplines, currentPersonId);
            var dscTypesList    = new List <DisciplineTypeViewData>();
            var moreCount       = 0;

            foreach (var discipline in dscViewDataList)
            {
                dscTypesList.AddRange(discipline.DisciplineTypes);
            }
            var sortedDisciplineTypes = dscTypesList
                                        .GroupBy(x => x.Id)
                                        .ToDictionary(x => x.Key, x => x.ToList())
                                        .OrderByDescending(x => x.Value.Count)
                                        .Select(x => new DisciplineTypeCalendarItemViewData
            {
                Id    = x.Key,
                Name  = x.Value.First().Name,
                Count = x.Value.Count,
            }).ToList();

            if (sortedDisciplineTypes.Count > DISCIPLINE_COUNT)
            {
                moreCount = sortedDisciplineTypes.Skip(DISCIPLINE_COUNT).Sum(x => x.Count);
            }
            return(new DisciplineMonthCalendarViewData(date, isCurrentMonth)
            {
                HasDisciplineIssues = sortedDisciplineTypes.Count > 1,
                Disciplines = dscViewDataList,
                MoreCount = moreCount,
            });
        }
Ejemplo n.º 3
0
        public ActionResult ClassList(DateTime?date, int classId, int?start, int?count, bool?byLastName)
        {
            start = start ?? 0;
            count = count ?? int.MaxValue;
            var currentDate            = (date ?? SchoolLocator.Context.NowSchoolYearTime).Date;
            var disciplines            = SchoolLocator.DisciplineService.GetClassDisciplineDetails(classId, currentDate);
            IList <DisciplineView> res = new List <DisciplineView>();

            if (disciplines != null)
            {
                res = DisciplineView.Create(disciplines, Context.PersonId ?? 0).ToList();
            }

            if (!byLastName.HasValue || byLastName.Value)
            {
                res = res.OrderBy(x => x.Student.LastName).ThenBy(x => x.Student.FirstName).ToList();
            }
            else
            {
                res = res.OrderBy(x => x.Student.FirstName).ThenBy(x => x.Student.LastName).ToList();
            }
            return(Json(new PaginatedList <DisciplineView>(res, start.Value / count.Value, count.Value)));
        }