Пример #1
0
        public async Task <VisitForDateListVM> GetVisitsForDate(DateTime date)
        {
            var visits = _visitRepository.GetForDate(date).OrderBy(v => v.VisitDate.TimeOfDay)
                         .ProjectTo <VisitForDateVM>(_mapper.ConfigurationProvider)
                         .ToList();

            foreach (var visit in visits)
            {
                visit.Dentist = _mapper.Map <DentistBasicInfoVM>(_dentistRepository.GetById(visit.DentistId));
                visit.Patient = _mapper.Map <PatientBasicInfoVM>(_patientRepository.GetById(visit.PatientId));
                if (date >= visit.VisitDate && date < visit.VisitDate.AddMinutes(30) && visit.VisitStatus != Status.Canceled)
                {
                    visit.VisitStatus = Status.InProgress;
                    var v = _mapper.Map <Visit>(visit);
                    await _visitRepository.Update(v);
                }
                else if (date >= visit.VisitDate.AddMinutes(30) && visit.VisitStatus != Status.Canceled)
                {
                    visit.VisitStatus = Status.Done;
                    var v = _mapper.Map <Visit>(visit);
                    await _visitRepository.Update(v);
                }
            }
            return(new VisitForDateListVM()
            {
                Visits = visits,
                Count = visits.Count(),
                DoneVisits = visits.Count(v => v.VisitStatus == Domain.Models.Status.Done),
                CurrentDate = DateTime.Now.Date
            });
        }