Exemple #1
0
        public IActionResult GetAll(string tenantId)
        {
            //var pagination = Request.Headers["Pagination"];
            var d = _repository.GetAll(tenantId).Select(x => new { x.Id, x.Name, x.Specialty });

            if (d.Count() >= 1)
            {
                return(Ok(d));
            }
            else
            {
                return(NotFound());
            }
        }
Exemple #2
0
        public async Task <VisitInfoForIndexListVM> GetAllVisits(string sortOrder, int?pageNumber, DateTime?dateMin, DateTime?dateMax, int?dentistId, bool?inFuture)
        {
            sortOrder = String.IsNullOrEmpty(sortOrder) ? "" : sortOrder;
            var temporaryVisits = _visitRepository.GetAll().ProjectTo <VisitInfoForIndexVM>(_mapper.ConfigurationProvider);

            switch (sortOrder)
            {
            case "":
                temporaryVisits = temporaryVisits.OrderBy(v => v.VisitDate.Date)
                                  .ThenBy(v => v.VisitDate.TimeOfDay);
                break;

            case "descending":
                temporaryVisits = temporaryVisits.OrderByDescending(v => v.VisitDate.Date)
                                  .ThenBy(v => v.VisitDate.TimeOfDay);
                break;
            }

            if (inFuture.HasValue && inFuture.Value == true)
            {
                temporaryVisits = temporaryVisits.Where(v => v.VisitDate > DateTime.Now);
            }
            if (dateMax.HasValue && dateMin.HasValue)
            {
                temporaryVisits = dateMin < dateMax?temporaryVisits.Where(v => v.VisitDate >= dateMin && v.VisitDate <= dateMax.Value.AddDays(1)) :
                                      temporaryVisits.Where(v => v.VisitDate >= dateMax && v.VisitDate <= dateMin.Value.AddDays(1));
            }
            else if (dateMax.HasValue)
            {
                temporaryVisits = temporaryVisits.Where(v => v.VisitDate <= dateMax.Value.AddDays(1));
            }
            else if (dateMin.HasValue)
            {
                temporaryVisits = temporaryVisits.Where(v => v.VisitDate >= dateMin);
            }

            if (dentistId.HasValue && dentistId.Value != 0)
            {
                temporaryVisits = temporaryVisits.Where(v => v.DentistId == dentistId);
            }

            var visits = temporaryVisits.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 (DateTime.Now >= visit.VisitDate && DateTime.Now < visit.VisitDate.AddMinutes(30) && visit.VisitStatus != Status.Canceled && visit.VisitStatus != Status.InProgress)
                {
                    visit.VisitStatus = Status.InProgress;
                    var v = _mapper.Map <Visit>(visit);
                    await _visitRepository.Update(v);
                }
                else if (DateTime.Now >= visit.VisitDate.AddMinutes(30) && visit.VisitStatus != Status.Canceled && visit.VisitStatus != Status.Done)
                {
                    visit.VisitStatus = Status.Done;
                    var v = _mapper.Map <Visit>(visit);
                    await _visitRepository.Update(v);
                }
            }
            var dentists = _dentistRepository.GetAll().ProjectTo <DentistBasicInfoVM>(_mapper.ConfigurationProvider);
            var dent     = dentists.Select(s => new SelectListItem {
                Text = s.Name + " " + s.LastName, Value = s.Id.ToString()
            }).ToList();

            dent.Insert(0, new SelectListItem {
                Text = "Any", Value = "0"
            });
            var pageSize = 2;
            var dates    = PaginatedList <DateTime> .Create(visits.GroupBy(d => d.VisitDate.Date).Select(d => d.Key).AsQueryable(), pageNumber ?? 1, pageSize);

            var min_date = string.IsNullOrEmpty(sortOrder) ? visits.Select(v => v.VisitDate).FirstOrDefault() : visits.Select(v => v.VisitDate).LastOrDefault();
            var max_date = string.IsNullOrEmpty(sortOrder) ? visits.Select(v => v.VisitDate).LastOrDefault() : visits.Select(v => v.VisitDate).FirstOrDefault();

            return(new VisitInfoForIndexListVM()
            {
                Visits = visits,
                PaginatedDates = dates,
                Dentists = dent,
                DentistId = dentistId.GetValueOrDefault(0),
                DateMax = dateMax.GetValueOrDefault(max_date).Date,
                DateMin = dateMin.GetValueOrDefault(min_date).Date,
                InFuture = inFuture.GetValueOrDefault(false),
                SortOrder = sortOrder
            });
        }