public HouseModel GetHouseById(int id) { House getHouse = TipezeNyumbaUnitOfWork.Repository <House>().Get(u => u.houseID == id); if (getHouse == null) { return(null); } string paymentModeInWords = getHouse.PaymentMode.number + " " + getHouse.PaymentMode.DurationType.type; HouseModel houseToDisplay = new HouseModel() { houseID = getHouse.houseID, districtHouseIsLocated = getHouse.District.name, bedrooms = getHouse.bedrooms, masterBedroomEnsuite = getHouse.masterBedroomEnsuite, selfContained = getHouse.selfContained, numberOfGarages = getHouse.numberOfGarages, fenceType = getHouse.FenceType1.typeOfFence, dateHouseWillBeAvailable = getHouse.dateHouseWillBeAvailable.ToLongDateString(), price = getHouse.price, modeOfPayment = paymentModeInWords, dateUploaded = getHouse.dateUploaded.ToLongDateString(), description = getHouse.description, houseState = getHouse.HouseState.HouseStatus }; return(houseToDisplay); }
public bool UpdateHouseDetails(int id, HouseModel houseDetails) { District checkDistrictHouseIsLocated = GetDistrictByName(houseDetails.districtHouseIsLocated); if (checkDistrictHouseIsLocated == null) { return(false); } LocationsInDistrict checkLocationInDistrict = GetLocationInDistrictByName(checkDistrictHouseIsLocated.districtID, houseDetails.districtHouseIsLocated); if (checkLocationInDistrict == null) { return(false); } HouseState checkHouseState = GetHouseStatesByName(houseDetails.houseState); if (checkHouseState == null) { return(false); } FenceType checkFenceType = GetFenceTypeByName(houseDetails.fenceType); if (checkFenceType == null) { return(false); } House houseToUpdate = TipezeNyumbaUnitOfWork.Repository <House>().Get(u => u.houseID == id); if (houseToUpdate == null) { return(false); } houseToUpdate.districtHouseIsLocated = checkDistrictHouseIsLocated.districtID; houseToUpdate.locationWithInDistrict = checkLocationInDistrict.districtLocationID; houseToUpdate.bedrooms = houseDetails.bedrooms; houseToUpdate.masterBedroomEnsuite = houseDetails.masterBedroomEnsuite; houseToUpdate.selfContained = houseDetails.selfContained; houseToUpdate.numberOfGarages = houseDetails.numberOfGarages; houseToUpdate.fenceType = checkFenceType.fenceTypeID; houseToUpdate.dateHouseWillBeAvailable = Convert.ToDateTime(houseDetails.dateHouseWillBeAvailable); houseToUpdate.price = houseDetails.price; houseToUpdate.modeOfPayment = Convert.ToInt32(houseDetails.modeOfPayment); houseToUpdate.dateUploaded = Convert.ToDateTime(houseDetails.dateUploaded); houseToUpdate.description = houseDetails.description; houseToUpdate.currentHouseState = checkHouseState.houseStateID; houseToUpdate.HouseContactDetail.phoneNumber1 = houseDetails.phoneNumber1; houseToUpdate.HouseContactDetail.phoneNumber2 = houseDetails.phoneNumber2; houseToUpdate.HouseContactDetail.whatsAppContactNumber = houseDetails.whatsAppContactNumber; houseToUpdate.HouseContactDetail.email = houseDetails.email; TipezeNyumbaUnitOfWork.Repository <House>().Attach(houseToUpdate); TipezeNyumbaUnitOfWork.SaveChanges(); return(true); }
public bool AddHouse(HouseModel newHouseModel) { District checkDistrictHouseIsLocated = GetDistrictByName(newHouseModel.districtHouseIsLocated); if (checkDistrictHouseIsLocated == null) { return(false); } LocationsInDistrict checkLocationInDistrict = GetLocationInDistrictByName(checkDistrictHouseIsLocated.districtID, newHouseModel.locationInDistrict); if (checkLocationInDistrict == null) { return(false); } HouseState checkHouseState = GetHouseStatesByName(newHouseModel.houseState); if (checkHouseState == null) { return(false); } FenceType checkFenceType = GetFenceTypeByName(newHouseModel.fenceType); if (checkFenceType == null) { return(false); } int activatedState = _fieldStateManagement.GetActivatedState().fieldStateID; House newHouse = new House() { districtHouseIsLocated = checkDistrictHouseIsLocated.districtID, locationWithInDistrict = checkLocationInDistrict.districtLocationID, bedrooms = newHouseModel.bedrooms, masterBedroomEnsuite = newHouseModel.masterBedroomEnsuite, selfContained = newHouseModel.selfContained, numberOfGarages = newHouseModel.numberOfGarages, fenceType = checkFenceType.fenceTypeID, dateHouseWillBeAvailable = Convert.ToDateTime(newHouseModel.dateHouseWillBeAvailable), price = newHouseModel.price, modeOfPayment = Convert.ToInt32(newHouseModel.modeOfPayment), dateUploaded = DateTime.Now, description = newHouseModel.description, currentHouseState = checkHouseState.houseStateID, state = activatedState }; HouseContactDetail houseContactDetail = new HouseContactDetail() { houseID = newHouse.houseID, phoneNumber1 = newHouseModel.phoneNumber1, phoneNumber2 = newHouseModel.phoneNumber2, whatsAppContactNumber = newHouseModel.whatsAppContactNumber, email = newHouseModel.email, state = activatedState }; HouseOwner setHouseOwner = new HouseOwner() { userID = newHouseModel.userId, houseID = newHouseModel.houseID, status = activatedState }; TipezeNyumbaUnitOfWork.Repository <House>().Add(newHouse); TipezeNyumbaUnitOfWork.Repository <HouseContactDetail>().Add(houseContactDetail); TipezeNyumbaUnitOfWork.Repository <HouseOwner>().Add(setHouseOwner); TipezeNyumbaUnitOfWork.SaveChanges(); return(true); }