예제 #1
0
        public ServiceResult <PeriodDto> CreatePeriod(bool save, Guid schoolId, string name, DateTime startDateTime, DateTime endDateTime)
        {
            Period period = new Period()
            {
                SchoolId      = schoolId,
                StartDateTime = startDateTime,
                Day           = startDateTime.DayOfWeek.ToString(),
                EndDateTime   = endDateTime,
                Name          = name
            };

            flytDexContext.Periods.Add(period);

            if (save)
            {
                if (flytDexContext.SaveChanges() == -1)
                {
                    return(errorService.Error <PeriodDto>("Error adding period"));
                }
            }

            PeriodDto periodDto = mapper.Map <PeriodDto>(period);

            return(new ServiceResult <PeriodDto>(periodDto));
        }
예제 #2
0
        public ServiceResult <List <HomeworkDto> > GetPastHomework(Guid schoolId, Guid employeeId, Guid subjectId, Guid studentGroupId, params Expression <Func <HomeworkDto, object> >[] includes)
        {
            if (schoolId == Guid.Empty)
            {
                return(errorService.Error <List <HomeworkDto> >("An error occurred: SchoolId is invalid"));
            }

            DateTime now = DateTime.Now;

            if (!flytDexContext.Homeworks.Any(h => h.SchoolId == schoolId && h.Lesson.Event.EmployeeId == employeeId))
            {
                return(errorService.Warn <List <HomeworkDto> >("No Homework found."));
            }

            List <HomeworkDto> homeworkDtos = flytDexContext.Homeworks
                                              .Where(h =>
                                                     h.SchoolId == schoolId &&
                                                     h.Lesson.Event.EmployeeId == employeeId &&
                                                     h.Lesson.Event.EndDateTime.Date <= now &&
                                                     h.Lesson.Event.Subject.Id == subjectId &&
                                                     h.Lesson.Event.LinkEventStudentGroups.Any(sg => sg.StudentGroupId == studentGroupId))
                                              .ProjectTo(mapper.ConfigurationProvider, includes)
                                              .ToList();

            List <PeriodDto> cachedPeriods = flytDexContext.Periods
                                             .Where(h => h.SchoolId == schoolId && h.PeriodInstanceId != 0)
                                             .ProjectTo <PeriodDto>(mapper.ConfigurationProvider)
                                             .ToList();

            foreach (HomeworkDto homeworkDto in homeworkDtos)
            {
                homeworkDto.PeriodId = cachedPeriods
                                       .Where(p =>
                                              p.StartDateTime == homeworkDto.EventStartDateTime &&
                                              p.EndDateTime == homeworkDto.EventEndDateTime)
                                       .Select(p => p.PeriodId).SingleOrDefault();
            }

            return(new ServiceResult <List <HomeworkDto> >(homeworkDtos));
        }
예제 #3
0
        public ServiceResult <List <AlexaUserDto> > GetAlexaUsersForDevice(string deviceId)
        {
            if (string.IsNullOrEmpty(deviceId))
            {
                return(errorService.Error <List <AlexaUserDto> >("Please provide a valid Alexa Device ID."));
            }

            if (!flytDexContext.UserDevices.Any(ud => ud.DeviceId == deviceId))
            {
                return(errorService.Warn <List <AlexaUserDto> >("This device is not registered on the system."));
            }

            List <User> users = flytDexContext.Users.Include(u => u.UserDevices).Where(u => u.UserDevices.Any(ud => ud.DeviceId == deviceId)).ToList();

            if (users.Count <= 0)
            {
                return(errorService.Warn <List <AlexaUserDto> >("This device is recognised but is not currently associated to any users."));
            }

            List <AlexaUserDto> alexaUserDtos = mapper.Map <List <User>, List <AlexaUserDto> >(users);

            return(new ServiceResult <List <AlexaUserDto> >(alexaUserDtos, ResultType.Success, "Success"));
        }