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 <PetProfileResponse> DeleteAsync(int id) { var existingPetProfile = await _petProfileRepository.FindById(id); if (existingPetProfile == null) { return(new PetProfileResponse("Pet Profile not found")); } try { _petProfileRepository.Remove(existingPetProfile); await _unitOfWork.CompleteAsync(); return(new PetProfileResponse(existingPetProfile)); } catch (Exception ex) { return(new PetProfileResponse($"An error ocurred while deleting Pet Profile: {ex.Message}")); } }
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 <ChatResponse> SaveAsync(int senderId, int receiverId, int petId) { var existingSender = await _profileRepository.FindByIdAsync(senderId); var existingReceiver = await _profileRepository.FindByIdAsync(receiverId); var existingPet = await _petProfileRepository.FindById(petId); bool attended = false; if (existingSender == null) { return(new ChatResponse("Sender not found")); } if (existingReceiver == null) { return(new ChatResponse("Receiver not found")); } if (existingPet == null) { return(new ChatResponse("Pet not found")); } var possibleOwner1 = await _petOwnerRepository.FindByPetIdAndOwnerId(petId, senderId); var possibleOwner2 = await _petOwnerRepository.FindByPetIdAndOwnerId(petId, receiverId); if (possibleOwner1 == null && possibleOwner2 == null) { return(new ChatResponse("Pet not associated with the owner")); } try { bool exist = false; IEnumerable <Chat> chatsReceiver = await _chatRepository.ListBySenderId(receiverId); if (chatsReceiver != null) { chatsReceiver.ToList().ForEach(chat => { if (chat.ReceiverProfileId == senderId && chat.PetId == petId) { exist = true; } }); } Chat chat = new Chat(); if (!exist) { chat.ReceiverProfileId = senderId; chat.SenderProfileId = receiverId; chat.PetId = petId; await _chatRepository.AddAsync(chat); await _unitOfWork.CompleteAsync(); } chat.ReceiverProfileId = receiverId; chat.SenderProfileId = senderId; chat.PetId = petId; await _chatRepository.AddAsync(chat); await _unitOfWork.CompleteAsync(); return(new ChatResponse(chat)); } catch (Exception ex) { return(new ChatResponse($"An error ocurred while saving chat: {ex.Message}")); } }