public async Task <RecordatoryResponse> SaveOwnerAsync(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);

            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"));
            }
            try
            {
                recordatory.OwnerId           = ownerId;
                recordatory.PetId             = petId;
                recordatory.ScheduleId        = scheduleId;
                recordatory.RecordatoryTypeId = recordyTypeId;
                recordatory.VetId             = 0;
                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}"));
            }
        }
        public async Task <OwnerProfileResponse> DeleteAsync(int id)
        {
            var existingOwnerProfile = await _ownerProfileRepository.FindById(id);

            if (existingOwnerProfile == null)
            {
                return(new OwnerProfileResponse("Owner Profile not found"));
            }
            try
            {
                _ownerProfileRepository.Remove(existingOwnerProfile);
                await _unitOfWork.CompleteAsync();

                return(new OwnerProfileResponse(existingOwnerProfile));
            }
            catch (Exception ex)
            {
                return(new OwnerProfileResponse($"An error ocurred while deleting owner profile; {ex.Message}"));
            }
        }
Example #3
0
        public async Task <CommentResponse> SaveAsync(int ownerId, int veterinaryId, Comment comment)
        {
            var existingOwner = await _ownerProfileRepository.FindById(ownerId);

            var existingVeterinary = await _veterinaryProfileRepository.FindById(veterinaryId);

            if (existingOwner == null)
            {
                return(new CommentResponse("Owner not found"));
            }
            if (existingVeterinary == null)
            {
                return(new CommentResponse("Veterinary not found"));
            }
            try
            {
                bool attended = false;
                IEnumerable <Appointment> appointments = await _appointmentRepository.ListByScheduleId(ownerId);

                if (appointments != null)
                {
                    appointments.ToList().ForEach(appointment => {
                        if (appointment.VeterinaryId == veterinaryId && appointment.OwnerId == ownerId)
                        {
                            attended = true;
                        }
                    });
                }

                if (!attended)
                {
                    return(new CommentResponse("Solo puedes calificar una veterinaria en la cual tu mascota haya sido atendida"));
                }

                comment.OwnerProfileId      = ownerId;
                comment.VeterinaryProfileId = veterinaryId;

                await _commentRepository.AddAsync(comment);

                await _unitOfWork.CompleteAsync();

                return(new CommentResponse(comment));
            }
            catch (Exception ex)
            {
                return(new CommentResponse($"An error ocurred while saving comment: {ex.Message}"));
            }
        }
Example #4
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}"));
            }
        }