public Accommodation GetAccommodationByUsername(string username) { try { GetAccommodationRequestDTO getAccommodationRequestDTO = new GetAccommodationRequestDTO(username); GetAccommodationResponseDTO getAccommodationResponseDTO = new GetAccommodationResponseDTO(accommodationPortClient.getAccommodationByUser(getAccommodationRequestDTO.getAccommodationByUserRequest)); Core.Model.Accommodation accommodation = getAccommodationResponseDTO.Accommodation; Accommodation accommodationDB = unitOfWork.Accommodations.SingleOrDefault(a => a.Id == accommodation.Id); if (accommodationDB != null) { accommodationDB = accommodation; accommodationDB.AccommodationType = accommodation.AccommodationType; accommodationDB.Name = accommodation.Name; accommodationDB.Description = accommodation.Description; accommodationDB.Category = accommodation.Category; if (unitOfWork.Addresses.SingleOrDefault(a => a.Id == accommodation.Address.Id) == null) { unitOfWork.Addresses.Add(accommodation.Address); unitOfWork.Complete(); } accommodationDB = unitOfWork.Accommodations.SingleOrDefault(a => a.Id == accommodation.Id); accommodationDB.Address = unitOfWork.Addresses.SingleOrDefault(a => a.Id == accommodation.Address.Id); unitOfWork.Complete(); } else { User user = unitOfWork.Users.Find(x => x.Username == username).First(); user.AgentOfAccommodation = accommodation; accommodation.Agents.Add(user); unitOfWork.Accommodations.Add(accommodation); unitOfWork.Complete(); } return(accommodation); } catch { return(null); } }
public GetAccommodationResponseDTO(getAccommodationByUserResponse getAccommodationByUserResponse) { Accommodation = new Core.Model.Accommodation() { Id = getAccommodationByUserResponse.accommodation.Id, Description = getAccommodationByUserResponse.accommodation.Description, Name = getAccommodationByUserResponse.accommodation.Name, Category = getAccommodationByUserResponse.accommodation.Category, AccommodationType = (Core.Model.AccommodationType)Enum.Parse(typeof(Core.Model.AccommodationType), getAccommodationByUserResponse.accommodation.AccommodationType.ToString(), true), Address = new Core.Model.Address() { Id = getAccommodationByUserResponse.accommodation.Address.Id, Country = getAccommodationByUserResponse.accommodation.Address.Country, City = getAccommodationByUserResponse.accommodation.Address.City, Street = getAccommodationByUserResponse.accommodation.Address.Street, Number = getAccommodationByUserResponse.accommodation.Address.Number, ApartmentNumber = getAccommodationByUserResponse.accommodation.Address.Apartment_number, Longitude = getAccommodationByUserResponse.accommodation.Address.Longitude, Latitude = getAccommodationByUserResponse.accommodation.Address.Latitude, PostalCode = getAccommodationByUserResponse.accommodation.Address.Postal_code } }; }