public void TestWtkProfileMapToScheduleCorrectly(int count, int year, int month, int day)
        {
            var data = new List <PayRule>();

            for (int i = 1; i <= count; i++)
            {
                data.Add(
                    new PayRule
                {
                    PersonNumber = "PersonNumber" + i
                });
            }

            var mapper   = new ScheduleMapper();
            var criteria = new GroupScheduleCriteria
            {
                PayRules  = data,
                StartDate = new DateTime(year, month, day),
                EndDate   = new DateTime(year, month, day + 1)
            };
            var result = mapper.Map(criteria);

            Assert.NotNull(result);
            Assert.AreEqual(count, result.Count);
            for (int i = 1; i <= count; i++)
            {
                Assert.AreEqual(new DateTime(year, month, day), result[i - 1].StartDate);
                Assert.AreEqual(new DateTime(year, month, day + 1), result[i - 1].EndDate);
                Assert.AreEqual("PersonNumber" + i, result[i - 1].PersonNumber);
            }
        }
        public ActionResult <IEnumerable <ScheduleViewModel> > GetSchedule(int affiliateId)
        {
            if (!_affiliateService.Exist(affiliateId))
            {
                return(NotFound());
            }

            return(_scheduleService.GetAffiliateSchedule(affiliateId).Select(s => ScheduleMapper.DTOtoScheduleVM(s)).ToArray());
        }
Beispiel #3
0
        public List <ScheduleDTO> GetAll()
        {
            var scheduleDTOs = _context.Schedule
                               .Include(s => s.Patient)
                               .Where(s => s.UserId.Equals(_userProviderService.GetUserId()))
                               .Select(s => ScheduleMapper.ScheduleToDTO(s))
                               .ToList();

            return(scheduleDTOs);
        }
Beispiel #4
0
        public List <ScheduleDAO> GetSchedules()
        {
            var s = new List <ScheduleDAO>();

            foreach (var schedules in ef.GetSchedules())
            {
                s.Add(ScheduleMapper.MapToScheduleDAO(schedules));
            }

            return(s);
        }
Beispiel #5
0
        public List <ScheduleDTO> GetAffiliateSchedule(int affiliateId)
        {
            var scheduleDTOs = _context.Schedule
                               .Include(s => s.Patient)
                               .Include(s => s.User)
                               .Where(u => u.User.AffiliateId.Equals(affiliateId))
                               .Select(s => ScheduleMapper.ScheduleToDTO(s))
                               .ToList();

            return(scheduleDTOs);
        }
Beispiel #6
0
        public async Task <GetScheduleModel> GetSchedule(int userId, int scheduleId)
        {
            var schedule = await _scheduleRepository.GetSchedule(scheduleId);

            if (schedule == null || schedule.UserId != userId)
            {
                throw new NotFoundException();
            }

            return(ScheduleMapper.MapToGetScheduleModel(schedule));
        }
Beispiel #7
0
        public void Create(ScheduleDTO scheduleDTO)
        {
            var schedule = ScheduleMapper.DTOtoSchedule(scheduleDTO);
            var patient  = _context.Patients.Find(scheduleDTO.PatientId);
            var user     = _context.ApplicationUsers.Find(scheduleDTO.UserId);

            schedule.Patient = patient;
            schedule.User    = user;

            _context.Schedule.Add(schedule);
            _context.SaveChanges();
        }
Beispiel #8
0
        public async Task UpdateSchedule(int userId, int scheduleId, UpdateScheduleModel scheduleModel)
        {
            var schedule = await _scheduleRepository.GetSchedule(scheduleId);

            if (schedule == null || schedule.UserId != userId)
            {
                throw new NotFoundException();
            }

            var updatedSchedule = ScheduleMapper.MapFromUpdateScheduleModel(userId, scheduleId, scheduleModel);

            await _scheduleRepository.UpdateSchedule(updatedSchedule);
        }
        public IActionResult CreateSchedule([FromBody] CreateScheduleViewModel createSchedule)
        {
            if (!_patientService.Exist(createSchedule.PatientId) && !_userService.Exist(createSchedule.UserId))
            {
                return(NotFound());
            }

            var scheduleDTO = ScheduleMapper.CreateScheduleVMtoDTO(createSchedule);

            _scheduleService.Create(scheduleDTO);

            return(Ok(ModelState));
        }
        public Schedule GetScheduleForToday()
        {
            var getTimePlanEvents =
                new TimePlanEventsService(_housePrefix, DateTime.Today, DateTime.Today.AddDays(1));
            var timeTable = getTimePlanEvents.GetFullTimePlan().Result;

            getTimePlanEvents.Dispose();

            var schedule = ScheduleMapper.MapFromDto(timeTable.ToList(), DateTime.Today);

            schedule.WeekNumber = GetWeekNumber.GetCurrentWeekNumberAsync().Result;

            return(schedule);
        }
Beispiel #11
0
        public ScheduleDTO Get(int id)
        {
            var schedule = _context.Schedule
                           .Include(s => s.Patient)
                           .Where(s => s.Id.Equals(id))
                           .Where(s => s.UserId.Equals(_userProviderService.GetUserId()))
                           .SingleOrDefault();

            if (schedule is null)
            {
                return(null);
            }

            return(ScheduleMapper.ScheduleToDTO(schedule));
        }
Beispiel #12
0
        public async void GetSchedulesByUserId_Should_Return_Null_WhenUserDoesNotExist(int userId, List <Schedule> expectedSchedules)
        {
            _mockScheduleRepository
            .Setup(m => m.QuerySchedules(It.IsAny <Func <Schedule, bool> >()))
            .Returns((Func <Schedule, bool> whereClause) =>
            {
                return(Task.FromResult(new List <Schedule> {
                    _mockSchedule
                }.Where(whereClause).ToList()));
            });

            var scheduleService = new ScheduleService(_mockScheduleRepository.Object);


            var schedules = await scheduleService.GetSchedulesByUserId(userId);

            schedules.Should().BeEquivalentTo(expectedSchedules.Select(schedule => ScheduleMapper.MapToGetScheduleModel(schedule)));
        }
        public IActionResult UpdateSchedule(int id, [FromBody] UpdateScheduleViewModel updateSchedule)
        {
            if (id != updateSchedule.Id)
            {
                return(BadRequest());
            }

            if (!_scheduleService.Exist(id) && !_userService.Exist(updateSchedule.UserId))
            {
                return(NotFound());
            }

            var scheduleDTO = ScheduleMapper.UpdateScheduleVMToDTO(updateSchedule);

            _scheduleService.Update(scheduleDTO);

            return(NoContent());
        }
        public List <Schedule> GetScheduleForPeriod(DateTime timetableStarts, DateTime timetableEnds)
        {
            var schedulesList = new List <Schedule>();

            var getTimePlanEvents =
                new TimePlanEventsService(_housePrefix, timetableStarts, timetableEnds);

            var timeTable = getTimePlanEvents.GetFullTimePlan().Result;

            for (int i = 0; i <= (timetableEnds - timetableStarts).TotalDays; i++)
            {
                schedulesList.Add(ScheduleMapper.MapFromDto(
                                      timeTable.Where(e => e.StartDateTime >= timetableStarts.AddDays(i) && e.EndDateTime < timetableStarts.AddDays(i + 1)).ToList(),
                                      timetableStarts.AddDays(i))
                                  );
            }

            getTimePlanEvents.Dispose();

            return(schedulesList);
        }
Beispiel #15
0
 public ScheduleCrud()
 {
     Mapper = new ScheduleMapper();
     Dao    = SqlDao.GetInstance();
 }
Beispiel #16
0
        public async Task <List <GetScheduleModel> > GetSchedulesByUserId(int userId)
        {
            var schedules = await _scheduleRepository.QuerySchedules(item => item.UserId == userId);

            return(schedules.Select(item => ScheduleMapper.MapToGetScheduleModel(item)).ToList());
        }
Beispiel #17
0
        public async Task CreateSchedule(int userId, CreateScheduleModel scheduleModel)
        {
            var schedule = ScheduleMapper.MapFromCreateScheduleModel(userId, scheduleModel);

            await _scheduleRepository.AddSchedule(schedule);
        }
        public static async Task GetAndSaveScheduleForScreen(IBLLApp bll, string userId, Screen screen)
        {
            var timeplanGettingSystem = new GetTimePlanFromInformationSystem(screen.Prefix);
            var schedule = timeplanGettingSystem.GetScheduleForToday();

            var bllSchedule =
                ScheduleMapper.MapFromInternal(DAL.App.Mappers.ScheduleMapper.MapFromDomain(schedule));

            bllSchedule.Prefix = screen.Prefix;

            var scheduleGuid = await bll.Schedules.AddAsync(bllSchedule);

            await bll.SaveChangesAsync();

            var scheduleIdAfterSaveChanges = bll.Schedules.GetUpdatesAfterUowSaveChanges(scheduleGuid).Id;

            var subjects = schedule.SubjectsInSchedules;

            if (subjects != null)
            {
                foreach (var subjectInSchedule in subjects)
                {
                    int subjectInScheduleId;
                    var subjectInScheduleThatAlreadyExists =
                        await bll.SubjectInSchedules.FindByUniqueIdentifierAsync(subjectInSchedule.UniqueIdentifier);

                    if (subjectInScheduleThatAlreadyExists != null)
                    {
                        subjectInScheduleThatAlreadyExists.ScheduleId = scheduleIdAfterSaveChanges;
                        bll.SubjectInSchedules.Update(subjectInScheduleThatAlreadyExists);
                        await bll.SaveChangesAsync();

                        subjectInScheduleId = subjectInScheduleThatAlreadyExists.Id;
                    }
                    else
                    {
                        var bllSubjectInSchedule = new SubjectInSchedule
                        {
                            CreatedAt        = DateTime.Now,
                            CreatedBy        = userId,
                            Rooms            = subjectInSchedule.Rooms,
                            Groups           = subjectInSchedule.Groups,
                            UniqueIdentifier = subjectInSchedule.UniqueIdentifier,
                            StartDateTime    = subjectInSchedule.StartDateTime,
                            EndDateTime      = subjectInSchedule.EndDateTime,
                            SubjectType      = subjectInSchedule.SubjectType,
                            ScheduleId       = scheduleIdAfterSaveChanges
                        };

                        var subject = await bll.Subjects
                                      .FindBySubjectNameAndCodeAsync(subjectInSchedule.Subject.SubjectName,
                                                                     subjectInSchedule.Subject.SubjectCode);

                        if (subject != null)
                        {
                            bllSubjectInSchedule.SubjectId = subject.Id;
                            bllSubjectInSchedule.Subject   = null;
                        }
                        else
                        {
                            var bllSubject = new Subject
                            {
                                CreatedAt   = DateTime.Now,
                                CreatedBy   = userId,
                                SubjectCode = subjectInSchedule.Subject.SubjectCode,
                                SubjectName = subjectInSchedule.Subject.SubjectName
                            };
                            var subjectGuid = await bll.Subjects.AddAsync(bllSubject);

                            await bll.SaveChangesAsync();

                            bllSubjectInSchedule.SubjectId = bll.Subjects.GetUpdatesAfterUowSaveChanges(subjectGuid).Id;
                        }
                        var subjInScheduleGuid = await bll.SubjectInSchedules.AddAsync(bllSubjectInSchedule);

                        await bll.SaveChangesAsync();

                        subjectInScheduleId =
                            bll.SubjectInSchedules.GetUpdatesAfterUowSaveChanges(subjInScheduleGuid).Id;
                    }

                    var teachers = new List <Teacher>();

                    if (subjectInSchedule.TeacherInSubjectEvents != null)
                    {
                        foreach (var teacherInSubjectEvent in subjectInSchedule.TeacherInSubjectEvents)
                        {
                            var teacher = await bll.Teachers
                                          .FindTeacherByNameAndRoleAsync(teacherInSubjectEvent.Teacher.FullName,
                                                                         teacherInSubjectEvent.Teacher.Role);

                            if (teacher != null)
                            {
                                teachers.Add(teacher);
                            }
                            else
                            {
                                var newTeacher = new Teacher
                                {
                                    CreatedAt   = DateTime.Now,
                                    CreatedBy   = userId,
                                    TeacherName = teacherInSubjectEvent.Teacher.FullName,
                                    TeacherRole = teacherInSubjectEvent.Teacher.Role
                                };
                                var teacherGuid = await bll.Teachers.AddAsync(newTeacher);

                                await bll.SaveChangesAsync();

                                teachers.Add(bll.Teachers.GetUpdatesAfterUowSaveChanges(teacherGuid));
                            }
                        }
                    }

                    foreach (var teacher in teachers)
                    {
                        bll.TeacherInSubjectEvents.Add(new TeacherInSubjectEvent
                        {
                            CreatedAt           = DateTime.Now,
                            CreatedBy           = userId,
                            TeacherId           = teacher.Id,
                            SubjectInScheduleId = subjectInScheduleId
                        });
                    }
                    await bll.SaveChangesAsync();
                }
            }

            await bll.ScheduleInScreens.AddAsync(new ScheduleInScreen
            {
                CreatedAt  = DateTime.Now,
                CreatedBy  = userId,
                ScreenId   = screen.Id,
                ScheduleId = scheduleIdAfterSaveChanges
            });

            var futureEvents = await bll.Events.GetAllFutureEventsAsync(DateTime.Now);

            foreach (var futureEvent in futureEvents)
            {
                if (futureEvent.ShowStartDateTime <= DateTime.Now && futureEvent.ShowEndDateTime > DateTime.Now)
                {
                    await bll.EventInSchedules.AddAsync(new EventInSchedule
                    {
                        CreatedAt  = DateTime.Now,
                        CreatedBy  = userId,
                        ScheduleId = scheduleIdAfterSaveChanges,
                        EventId    = futureEvent.Id
                    });
                }
            }

            await bll.SaveChangesAsync();
        }
 public ActionResult <IEnumerable <ScheduleViewModel> > GetSchedule()
 {
     return(_scheduleService.GetAll().Select(s => ScheduleMapper.DTOtoScheduleVM(s)).ToArray());
 }