示例#1
0
        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;
        }
示例#2
0
        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;
        }
示例#3
0
 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));
     }
 }