Ejemplo n.º 1
0
        public List <DateTime> GetAllAvailablesFromDay([FromBody] GetAppointmentDto getAppointmentDto)
        {
            using (var dbContext = new ApplicationDbContext())
            {
                var userId = GetUserId();

                Clinic_Doctor doctor = dbContext.Clinic_Doctors.FirstOrDefault(d => d.Id == getAppointmentDto.DoctorId && d.UserId == userId);

                if (doctor == null)
                {
                    throw new BadRequestException(ExceptionMessages.BadRequest);
                }

                var res = new List <DateTime>();
                for (int i = 0; i < 15; i++)
                {
                    foreach (var datetime in doctor.GetAllAvailablesForDay(getAppointmentDto.Day.AddDays(i)))
                    {
                        res.Add(datetime);
                    }
                }

                return(res);
            }
        }
Ejemplo n.º 2
0
        private Clinic_Doctor CreateDoctor(string firstName, string lastName, uint consultationLength, Clinic_Specialty specialty, Clinic_Subspecialty subspecialty, DoctorStateEnum state, List <Clinic_WorkingHours> workingHours, Clinic clinic)
        {
            Clinic_Doctor doctor;

            using (var dbContext = new ApplicationDbContext())
            {
                doctor = new Clinic_Doctor
                {
                    FirstName          = firstName,
                    LastName           = lastName,
                    PhoneNumber        = string.Empty,
                    Email              = string.Empty,
                    ConsultationLength = consultationLength,
                    SpecialtyId        = specialty.Id,
                    SubspecialtyId     = subspecialty?.Id,
                    State              = state,
                    WorkingHours       = workingHours,
                    UserId             = clinic.UserId
                };

                dbContext.Clinic_Doctors.Add(doctor);
                dbContext.SaveChanges();
            }

            return(doctor);
        }
Ejemplo n.º 3
0
        public void Add([FromBody] AddDoctorDto doctorDto)
        {
            using (var dbContext = new ApplicationDbContext())
            {
                var userId = GetUserId();

                ValidateDoctorData(dbContext, userId, doctorDto.SpecialtyId, doctorDto.SubspecialtyId, doctorDto.WorkingHours);

                var doctor = new Clinic_Doctor
                {
                    FirstName          = doctorDto.FirstName,
                    LastName           = doctorDto.LastName,
                    Email              = doctorDto.Email,
                    PhoneNumber        = doctorDto.PhoneNumber,
                    SpecialtyId        = doctorDto.SpecialtyId,
                    SubspecialtyId     = doctorDto.SubspecialtyId,
                    ConsultationLength = doctorDto.ConsultationLength,
                    WorkingHours       = new List <Clinic_WorkingHours>(),
                    State              = DoctorStateEnum.Active,
                    UserId             = userId
                };

                dbContext.Clinic_Doctors.Add(doctor);
                dbContext.SaveChanges();

                doctor.WorkingHours = doctorDto.WorkingHours.Select(wh => new Clinic_WorkingHours {
                    DayNumber = wh.DayNumber, Start = wh.Start, End = wh.End
                }).ToList();
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public void Vacation([FromBody] EnableDisableDoctorDto doctorDto)
        {
            using (var dbContext = new ApplicationDbContext())
            {
                var userId = GetUserId();

                Clinic_Doctor doctor = dbContext.Clinic_Doctors.FirstOrDefault(d => d.Id == doctorDto.Id && d.UserId == userId);

                if (doctor == null)
                {
                    throw new BadRequestException(ExceptionMessages.BadRequest);
                }

                doctor.State = DoctorStateEnum.Vacation;
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        private Clinic_Appointment CreateAppointment(DateTime dateTime, Clinic_Doctor doctor, Clinic_Patient patient, AppointmentStateEnum state, Clinic_Rating rating, Clinic clinic)
        {
            Clinic_Appointment appointment;

            using (var dbContext = new ApplicationDbContext())
            {
                appointment = new Clinic_Appointment
                {
                    DateTime  = dateTime,
                    DoctorId  = doctor.Id,
                    PatientId = patient.Id,
                    State     = state,
                    RatingId  = rating?.Id ?? 0,
                    UserId    = clinic.UserId
                };

                dbContext.Clinic_Appointments.Add(appointment);
                dbContext.SaveChanges();
            }

            return(appointment);
        }
Ejemplo n.º 6
0
        public void Edit([FromBody] EditDoctorDto doctorDto)
        {
            using (var dbContext = new ApplicationDbContext())
            {
                var userId = GetUserId();

                Clinic_Doctor doctorToUpdate = dbContext.Clinic_Doctors.FirstOrDefault(d => d.Id == doctorDto.Id && d.UserId == userId);

                if (doctorToUpdate == null)
                {
                    throw new BadRequestException(ExceptionMessages.BadRequest);
                }

                ValidateDoctorData(dbContext, userId, doctorDto.SpecialtyId, doctorDto.SubspecialtyId, doctorDto.WorkingHours);

                doctorToUpdate.FirstName          = doctorDto.FirstName;
                doctorToUpdate.LastName           = doctorDto.LastName;
                doctorToUpdate.Email              = doctorDto.Email;
                doctorToUpdate.PhoneNumber        = doctorDto.PhoneNumber;
                doctorToUpdate.SpecialtyId        = doctorDto.SpecialtyId;
                doctorToUpdate.SubspecialtyId     = doctorDto.SubspecialtyId;
                doctorToUpdate.ConsultationLength = doctorDto.ConsultationLength;
                doctorToUpdate.WorkingHours.ForEach(wh => dbContext.Entry(wh).State = EntityState.Deleted);

                var newWorkingHours = doctorDto.WorkingHours.Select(wh => new Clinic_WorkingHours
                {
                    DayNumber = wh.DayNumber,
                    Start     = wh.Start,
                    End       = wh.End
                }).ToList();

                doctorToUpdate.WorkingHours = newWorkingHours;

                dbContext.SaveChanges();
            }
        }