Esempio n. 1
0
        public async Task <VetProfileResponse> DeleteAsync(int id)
        {
            var existingVetProfile = await _vetProfileRepository.FindById(id);

            if (existingVetProfile == null)
            {
                return(new VetProfileResponse("VetProfile not found"));
            }
            try
            {
                _vetProfileRepository.Remove(existingVetProfile);
                await _unitOfWork.CompleteAsync();

                return(new VetProfileResponse(existingVetProfile));
            }
            catch (Exception ex)
            {
                return(new VetProfileResponse($"An error ocurred while deleting VetProfile: {ex.Message}"));
            }
        }
Esempio n. 2
0
        public async Task <AppointmentResponse> SaveAsync(int ownerId, int veterinaryId, int vetId, int petId, Appointment appointment)
        {
            var existingOwner = await _ownerProfileRepository.FindById(ownerId);

            var existingVeterinary = await _veterinaryProfileRepository.FindById(veterinaryId);

            var existingVet = await _vetProfileRepository.FindById(vetId);

            var existingPet = await _petProfileRepository.FindById(petId);

            var existingScheduleVet = await _scheduleRepository.FindByProfileId(veterinaryId);

            var existingScheduleOwner = await _scheduleRepository.FindByProfileId(ownerId);

            if (existingOwner == null)
            {
                return(new AppointmentResponse("Owner not found"));
            }
            if (existingPet == null)
            {
                return(new AppointmentResponse("Pet not found"));
            }
            if (existingVet == null)
            {
                return(new AppointmentResponse("Vet not found"));
            }
            if (existingVeterinary == null)
            {
                return(new AppointmentResponse("Veterinary not found"));
            }
            try
            {
                bool differentDate = true;
                IEnumerable <Appointment> appointments = await _appointmentRepository.ListByScheduleId(existingScheduleVet.First().Id);

                appointments.ToList().ForEach(appoint => {
                    if ((appoint.Date == appointment.Date) && appoint.Accepted == true)
                    {
                        differentDate = false;
                    }
                });
                if (differentDate == false)
                {
                    return(new AppointmentResponse("The vet already have an appointment at the date, please try a different date"));
                }

                appointment.OwnerId      = ownerId;
                appointment.VeterinaryId = veterinaryId;
                appointment.VetId        = vetId;
                appointment.PetId        = petId;
                appointment.ScheduleId   = existingScheduleOwner.First().Id;
                await _appointmentRepository.AddAsync(appointment);

                await _unitOfWork.CompleteAsync();

                appointment.ScheduleId = existingScheduleVet.First().Id;
                await _appointmentRepository.AddAsync(appointment);

                await _unitOfWork.CompleteAsync();

                return(new AppointmentResponse(appointment));
            }
            catch (Exception ex)
            {
                return(new AppointmentResponse($"An error ocurred while updating appointment: {ex.Message}"));
            }
        }
        public async Task <RecordatoryResponse> SaveVetAsync(int vetId, int ownerId, int scheduleId, int recordyTypeId, int petId, Recordatory recordatory)
        {
            var existingOwner = await _ownerProfileRepository.FindById(ownerId);

            var existingSchedule = await _scheduleRepository.FindById(scheduleId);

            var existingRecordatoryType = await _recordatoryTypeRepository.FindById(recordyTypeId);

            var existingPet = await _petProfileRepository.FindById(petId);

            var existingVet = await _vetProfileRepository.FindById(vetId);

            if (existingOwner == null)
            {
                return(new RecordatoryResponse("Owner not found"));
            }
            if (existingSchedule == null)
            {
                return(new RecordatoryResponse("Schedule not found"));
            }
            if (existingRecordatoryType == null)
            {
                return(new RecordatoryResponse("Recordatory Type not found"));
            }
            if (existingPet == null)
            {
                return(new RecordatoryResponse("Pet not found"));
            }
            if (existingVet == null)
            {
                return(new RecordatoryResponse("Vet not found"));
            }

            bool attended = false;
            IEnumerable <Appointment> appointments = await _appointmentRepository.ListByScheduleId(existingVet.ScheduleId);

            appointments.ToList().ForEach(appointment => {
                if (appointment.PetId == petId)
                {
                    attended = true;
                }
            });

            if (!attended)
            {
                return(new RecordatoryResponse("Solo puedes poner recordatorios sobre mascotas las cuales usted haya atendido"));
            }

            try
            {
                recordatory.OwnerId           = ownerId;
                recordatory.PetId             = petId;
                recordatory.ScheduleId        = scheduleId;
                recordatory.RecordatoryTypeId = recordyTypeId;
                recordatory.VetId             = vetId;
                await _recordatoryRepository.AddAsync(recordatory);

                await _unitOfWork.CompleteAsync();

                return(new RecordatoryResponse(recordatory));
            }
            catch (Exception ex)
            {
                return(new RecordatoryResponse($"An error ocurred while saving recordatory: {ex.Message}"));
            }
        }