private void InsertData() { CityStateZip csz = new CityStateZip(); csz.City = facCity.Text; csz.State = facState.Text; csz.ZipCode = facZipCode.Text; CityStateZipLogic cszLogic = new CityStateZipLogic(); csz = cszLogic.InsertCityStateZip(csz); ListingType listingType = new ListingType(); listingType.ListingTypeName = facListingType.Text; ListingTypeLogic ltLogic = new ListingTypeLogic(); listingType = ltLogic.InsertListingType(listingType); Facility facility = new Facility(); facility.ClientGuid = Guid.Parse(clientGuidTxt.Text); facility.FacilityName = facFacilityName.Text; facility.Exerpt = facExcerpt.Text; facility.Description = facDescription.Text; facility.PhoneNumber = facPhoneNumber.Text; facility.Address = facAddress.Text; facility.CityStateZipGuid = csz.CityStateZipGuid; facility.Email = facEmail.Text; facility.Website = facWebsite.Text; facility.ListingTypeGuid = listingType.ListingTypeGuid; facility.PublicPhotoFileUri = facPhotoUri.Text; FacilityLogic facilityLogic = new FacilityLogic(); facilityLogic.InsertFacility(facility); }
public bool Delete(Guid facilityGuid, string email) { bool success = false; FacilityLogic facilityLogic = new FacilityLogic(); BE.Facility facility = facilityLogic.GetFacilityByFacilityGuid(facilityGuid); ClientLogic clientLogic = new ClientLogic(); BE.Client client = clientLogic.GetClientByClientGuid(facility.ClientGuid); if (client.Email == email) { // to delete facility first delete related records in FacilityPhoto and FacilityOffering // !!! in the existing business model transaction scope is hard to implement !!! FacilityOfferingLogic facilityOfferingLogic = new FacilityOfferingLogic(); FacilityPhotoLogic facilityPhotoLogic = new FacilityPhotoLogic(); OfferingLogic offeringLogic = new OfferingLogic(); // delete related offerings var facilityOfferings = offeringLogic.GetOfferingsForFacility(facilityGuid); if (facilityOfferings.Count > 0) { facilityOfferings.ForEach(fo => { facilityOfferingLogic.DeleteFacilityOffering( new BE.FacilityOffering { FacilityGuid = facilityGuid, OfferingGuid = fo.OfferingGuid } ); }); } // delete related photos var facilityPhotos = facilityPhotoLogic.GetFacilityPhotosForFacilityByFacilityGuid(facilityGuid); if (facilityPhotos.Count > 0) { facilityPhotos.ForEach(fp => facilityPhotoLogic.DeleteFacilityPhoto(fp)); } facilityLogic.DeleteFacility(facility); success = true; } return success; }
// general search by all criteria private SearchResultsViewModel SearchFacilities(SearchFilterViewModel filter, int? page) { var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1) int pageminus1 = pageNumber - 1; int totalCount = 0; IList<SearchResultViewModel> results = new List<SearchResultViewModel>(); FacilityLogic flogic = new FacilityLogic(); var allFound = filter.SearchType == Enums.SearchTypes.Distance ? this.SearchByDistance(filter, flogic, pageminus1, PAGESIZE, out totalCount ) : filter.SearchType == Enums.SearchTypes.Filtered ? this.SearchByFilter(filter, flogic, pageminus1, PAGESIZE, out totalCount) : this.SearchByDistanceFilter(filter, flogic, pageminus1, PAGESIZE, out totalCount); allFound.ForEach(f => { var csz = this.CityStateZipAll.FirstOrDefault(c => c.CityStateZipGuid == f.CityStateZipGuid); results.Add(f.ToSearchResult(csz)); }); var resultsPage = new StaticPagedList<SearchResultViewModel>(results, pageNumber, PAGESIZE, totalCount); filter.Page = pageNumber; return new SearchResultsViewModel { CurrentFilter = filter, CurrentResults = resultsPage }; }
private ListingViewModelEdit SaveListing(ListingViewModelEdit listing, bool insert) { // try to find first city record and if not found insert new CityStateZipLogic cszLogic = new CityStateZipLogic(); CityStateZip csz = cszLogic.GetCityStateZipByCityStateZipGuid(listing.CityStateZipGuid); csz = new CityStateZip(listing.CityStateZipGuid, listing.City, listing.State, listing.ZipCode); csz = cszLogic.InsertCityStateZip(csz); listing.CityStateZipGuid = csz.CityStateZipGuid; //price ListingTypeLogic listingTypeLogic = new ListingTypeLogic(); ListingType listingType = listingTypeLogic.GetListingTypeByListingTypeGuid(listing.ListingTypeGuid); Facility facility = listing.ToFacility(); FacilityLogic facilityLogic = new FacilityLogic(); if (insert) { //Add Facility Price from listing list facility.Price = listingType.ListingTypePrice; facility = facilityLogic.InsertFacility(facility); listing.FacilityGuid = facility.FacilityGuid; listing.FacilityID = facility.FacilityID; //// add facilityguid to photos listing.FacilityPhotos.ToList().ForEach(ff => ff.FacilityGuid = listing.FacilityGuid); } else { facility.FacilityGuid = listing.FacilityGuid; // if listing type change then price from listing list Facility oldfacility = facilityLogic.GetFacilityByFacilityGuid(listing.FacilityGuid); if (oldfacility.ListingTypeGuid != facility.ListingTypeGuid) facility.Price = listingType.ListingTypePrice; else facility.Price = oldfacility.Price; facilityLogic.UpdateFacility(facility); } this.SaveTypesOfCare(listing); this.SaveListingPhotos(listing.FacilityPhotos.ToList()); return listing; }
private List<Facility> SearchByDistanceFilter(SearchFilterViewModel filter, FacilityLogic flogic, int page, int pageSize, out int totalCount) { // distance radius is in miles var allFound = flogic.GetAllFacilityByDistanceFilter( new DistanceParameters { Latitude = filter.Latitude.Value, Longitude = filter.Longitude.Value, DistanceRadius = RADIUS }, filter.TypeOfCareFilter.ToOfferingListCheckedOnly(), false, page, pageSize, out totalCount ); return allFound; }
private List<Facility> SearchByFilter(SearchFilterViewModel filter, FacilityLogic flogic, int page, int pageSize, out int totalCount) { var allFound = flogic.GetAllFacilityFilter( new CityStateZip { City = filter.CityFilter ?? "", State = filter.StateFilter ?? "", ZipCode = filter.ZipFilter ?? "" }, filter.TypeOfCareFilter.ToOfferingListCheckedOnly(), false, page, pageSize, out totalCount ); return allFound; }
public void DeleteFacility(DC.Facility request) { try { BL.FacilityLogic facilityLogic = new BL.FacilityLogic(); BE.Facility entity = request.ToBusinessEntity(); facilityLogic.DeleteFacility(entity); } catch (BE.FacilityNotFoundException ex) { FC.DefaultFaultContract fault = new FC.DefaultFaultContract(); fault.ErrorMessage = String.Format( "Unable to delete Facility data. Data: {0}", request.ToBusinessEntity().ToString()); throw new FaultException<FC.DefaultFaultContract>(fault, new FaultReason(ex.Message)); } }
private List<Facility> SearchByDistance(SearchFilterViewModel filter, FacilityLogic flogic, int page, int pageSize, out int totalCount) { // distance radius is in miles var allFound = flogic.GetAllFacilityByDistance( new DistanceParameters { Latitude = filter.Latitude.Value, Longitude = filter.Longitude.Value, DistanceRadius = RADIUS }, page, pageSize, out totalCount ); return allFound; }
public DC.Facility GetFacilityByFacilityGuid(Guid facilityGuid) { try { BL.FacilityLogic facilityLogic = new BL.FacilityLogic(); BE.Facility entity = facilityLogic.GetFacilityByFacilityGuid(facilityGuid); DC.Facility response = entity.ToDataContract(); return response; } catch (BE.FacilityNotFoundException ex) { FC.FacilityFault fault = new FC.FacilityFault(); fault.FacilityGuid = ex.FacilityGuid; fault.ErrorMessage = "Facility does not exsist in the database."; throw new FaultException<FC.FacilityFault>(fault, new FaultReason(ex.Message)); } catch (Exception ex) { FC.FacilityFault fault = new FC.FacilityFault(); fault.ErrorMessage = "Could not retrieve a specific Facility for unknown reasons."; throw new FaultException<FC.FacilityFault>(fault, new FaultReason(ex.Message)); } }
public List<DC.Facility> GetFacilitiesNotForOffering(Guid offeringGuid) { try { BL.FacilityLogic facilityLogic = new BL.FacilityLogic(); List<BE.Facility> facilities = facilityLogic.GetFacilitiesNotForOffering(offeringGuid); List<DC.Facility> response = facilities.ToDataContractList(); return response; } catch (BE.OfferingNotFoundException) { FC.OfferingFault fault = new FC.OfferingFault(); fault.OfferingGuid = offeringGuid; fault.ErrorMessage = String.Format("Unable to find facilities not for offering '{0}'.", offeringGuid); throw new FaultException<FC.OfferingFault>(fault, new FaultReason("Offering does not exist in database.")); } catch (Exception ex) { FC.OfferingFault fault = new FC.OfferingFault(); fault.OfferingGuid = offeringGuid; fault.ErrorMessage = String.Format("Unable to find facilities not for offering '{0}'.", offeringGuid); throw new FaultException<FC.OfferingFault>(fault, new FaultReason(ex.Message)); } }
public List<DC.Facility> GetFacilitiesNotForCityStateZip(Guid cityStateZipGuid) { try { BL.FacilityLogic facilityLogic = new BL.FacilityLogic(); List<BE.Facility> facilities = facilityLogic.GetFacilitiesNotForCityStateZip(cityStateZipGuid); List<DC.Facility> response = facilities.ToDataContractList(); return response; } catch (BE.CityStateZipNotFoundException) { FC.CityStateZipFault fault = new FC.CityStateZipFault(); fault.CityStateZipGuid = cityStateZipGuid; fault.ErrorMessage = String.Format("Unable to find facilities not for cityStateZip '{0}'.", cityStateZipGuid); throw new FaultException<FC.CityStateZipFault>(fault, new FaultReason("CityStateZip does not exist in database.")); } catch (Exception ex) { FC.CityStateZipFault fault = new FC.CityStateZipFault(); fault.CityStateZipGuid = cityStateZipGuid; fault.ErrorMessage = String.Format("Unable to find facilities not for cityStateZip '{0}'.", cityStateZipGuid); throw new FaultException<FC.CityStateZipFault>(fault, new FaultReason(ex.Message)); } }
public List<DC.Facility> GetFacilitiesForListingTypeByListingTypeGuid(Guid listingTypeGuid) { try { BL.FacilityLogic facilityLogic = new BL.FacilityLogic(); List<BE.Facility> entities = facilityLogic.GetFacilitiesForListingTypeByListingTypeGuid(listingTypeGuid); List<DC.Facility> response = entities.ToDataContractList(); return response; } catch (BE.FacilityException ex) { FC.DefaultFaultContract fault = new FC.DefaultFaultContract(); fault.ErrorMessage = string.Format("Unable to find a Facility with the given ListingType"); throw new FaultException<FC.DefaultFaultContract>(fault, new FaultReason(ex.Message)); } }
public List<DC.Facility> GetAllFacilityWithUndefined() { try { BL.FacilityLogic facilityLogic = new BL.FacilityLogic(); List<BE.Facility> entities = facilityLogic.GetAllFacilityWithUndefined(); List<DC.Facility> response = entities.ToDataContractList(); return response; } catch (Exception ex) { FC.DefaultFaultContract fault = new FC.DefaultFaultContract(); fault.ErrorMessage = "Unable to retrieve facility data."; throw new FaultException<FC.DefaultFaultContract>(fault, new FaultReason(ex.Message)); } }