Ejemplo n.º 1
0
        public async Task <int> AddVisit_Post(TemporaryVisitVM newVisit)
        {
            newVisit.VisitDate = newVisit.VisitDate + newVisit.TimeOfVisit;
            var visits = _visitRepository.GetForDateTime(newVisit.VisitDate);

            if (newVisit.DentistId == 0)
            {
                if (visits.Any())
                {
                    if (visits.Select(v => v.PatientId).Contains(newVisit.PatientId))
                    {
                        return(1);
                    }
                    var dentists = _dentistRepository.GetAll().Select(d => d.Id).ToList();
                    foreach (var v in visits)
                    {
                        if (dentists.Contains(v.DentistId))
                        {
                            dentists.Remove(v.DentistId);
                        }
                    }
                    if (dentists.Any())
                    {
                        newVisit.DentistId = dentists.First();
                    }
                }
                else
                {
                    newVisit.DentistId = _dentistRepository.GetAll().Select(d => d.Id).First();
                }
            }

            var visit = _mapper.Map <Visit>(newVisit);
            await _visitRepository.Add(visit);

            return(0);
        }