public virtual ServiceProvider ToEntity() { long id; ServiceProvider serviceProvider = new ServiceProvider(); List <long> paymentTypeIds = new List <long>(); foreach (CheckBoxVm checkBoxVm in from m in this.PaymentTypes where m.IsChecked select m) { if (!long.TryParse(checkBoxVm.Value, out id)) { continue; } paymentTypeIds.Add(id); } serviceProvider.PaymentTypeIds = paymentTypeIds; serviceProvider.Coupon = this.Coupon.ToEntity(); serviceProvider.Package = this.Package; serviceProvider.Book = new Book() { Id = this.BookId }; serviceProvider.ServiceCategories = ( from key in ConverterHelpers.CheckBoxListToLongArray(this.ServiceCategories) select new KeyValuePair <long, string>(key, string.Empty)).ToList <KeyValuePair <long, string> >(); serviceProvider.AllCounties = this.AllCounties; serviceProvider.CountiesServed = this.CountiesServed; serviceProvider.Name = this.Name; serviceProvider.Address = (this.AddressValidation.ValidationItems == null ? this.Address.ToEntity() : this.AddressValidation.ToEntity()); serviceProvider.DisplayAddress = !this.DoNotDisplayAddress; serviceProvider.Phones = this.PhoneList.ToEntityList(); serviceProvider.Emails = this.EmailList.ToEntity(); serviceProvider.Contacts = this.Contacts.ConvertAll <Contact>((ContactVm m) => m.ToEntity()).Where <Contact>((Contact x) => { if (!string.IsNullOrWhiteSpace(x.FirstName)) { return(true); } return(!string.IsNullOrWhiteSpace(x.LastName)); }).ToList <Contact>(); serviceProvider.OfficeHours = this.OfficeHours.ConvertAll <MSLivingChoices.Entities.Admin.OfficeHours>((OfficeHoursVm m) => m.ToEntity()); serviceProvider.Description = this.Description; serviceProvider.WebsiteUrl = MslcUrlBuilder.NormalizeUri(this.WebsiteUrl); serviceProvider.DisplayWebsiteUrl = this.DisplayWebsiteUrl; serviceProvider.FeatureStartDate = this.FeatureStartDate; serviceProvider.FeatureEndDate = this.FeatureEndDate; serviceProvider.PublishStartDate = this.PublishStartDate; serviceProvider.PublishEndDate = this.PublishEndDate; serviceProvider.Images = (this.Images != null ? this.Images.ToEntity(ImageType.Photo) : new List <Image>()); serviceProvider.CallTrackingPhones = new List <CallTrackingPhone>(); if (this.CallTrackingPhones != null) { if (!this.ProvisionCallTrackingNumbers) { this.CallTrackingPhones.ForEach((CallTrackingPhoneVm c) => c.IsDisconnected = true); } serviceProvider.CallTrackingPhones = ( from p in this.CallTrackingPhones.ConvertAll <CallTrackingPhone>((CallTrackingPhoneVm m) => m.ToEntity()) where !string.IsNullOrEmpty(p.Phone) select p).ToList <CallTrackingPhone>(); } return(serviceProvider); }
public virtual Community ToEntity() { long id; Community community = new Community() { Book = new Book() { Id = this.BookId }, Package = this.Package, ListingTypes = ConverterHelpers.CheckBoxListToEnumList <ListingType>(this.ListingTypes), SeniorHousingAndCareCategoryIds = ConverterHelpers.CheckBoxListToLongArray(this.SeniorHousingAndCareCategories), AgeRestrictions = ConverterHelpers.CheckBoxListToEnumList <AgeRestriction>(this.AgeRestrictions), Name = this.Name, Address = (this.AddressValidation.ValidationItems == null ? this.Address.ToEntity() : this.AddressValidation.ToEntity()), DisplayAddress = !this.DoNotDisplayAddress, Phones = this.PhoneList.ToEntityList(), Emails = this.EmailList.ToEntity(), Contacts = this.Contacts.ConvertAll <Contact>((ContactVm m) => m.ToEntity()).Where <Contact>((Contact x) => { if (!string.IsNullOrWhiteSpace(x.FirstName)) { return(true); } return(!string.IsNullOrWhiteSpace(x.LastName)); }).ToList <Contact>(), OfficeHours = ( from m in this.OfficeHours select m.ToEntity()).ToList <MSLivingChoices.Entities.Admin.OfficeHours>(), Description = this.Description, WebsiteUrl = MslcUrlBuilder.NormalizeUri(this.WebsiteUrl), DisplayWebsiteUrl = this.DisplayWebsiteUrl }; List <long> paymentTypeIds = new List <long>(); foreach (CheckBoxVm checkBoxVm in from m in this.CommunityDetails.PaymentTypes where m.IsChecked select m) { if (!long.TryParse(checkBoxVm.Value, out id)) { continue; } paymentTypeIds.Add(id); } community.PaymentTypeIds = paymentTypeIds; community.PriceRange = this.CommunityDetails.PriceRange.ToEntity(); community.Deposit = this.CommunityDetails.Deposit.ToEntity(); community.ApplicationFee = this.CommunityDetails.ApplicationFee.ToEntity(); community.PetDeposit = this.CommunityDetails.PetDeposit.ToEntity(); community.BedroomFromId = this.CommunityDetails.BedroomFromId; community.BedroomToId = this.CommunityDetails.BedroomToId; community.BathroomFromId = this.CommunityDetails.BathroomFromId; community.BathroomToId = this.CommunityDetails.BathroomToId; community.LivingSpace = this.CommunityDetails.LivingSpace.ToEntity(); community.UnitCount = this.CommunityDetails.UnitCount; community.Amenities = AmenityVm.ToEntityList(this.CommunityDetails.DefaultAmenities, this.CommunityDetails.CustomAmenities); community.CommunityServices = CommunityServiceVm.ToEntityList(this.CommunityDetails.DefaultCommunityServices, this.CommunityDetails.CustomCommunityServices); community.FloorPlans = new List <FloorPlan>(); community.SpecHomes = new List <SpecHome>(); community.Houses = new List <House>(); community.VirtualTour = MslcUrlBuilder.NormalizeUri(this.CommunityDetails.VirtualTour); community.Coupon = this.CommunityDetails.Coupon.ToEntity(); community.Images = (this.CommunityDetails.Images == null ? new List <Image>() : this.CommunityDetails.Images.ToEntity(ImageType.Photo)); community.LogoImages = (this.CommunityDetails.LogoImages == null ? new List <Image>() : this.CommunityDetails.LogoImages.ToEntity(ImageType.Logo)); if (this.CommunityDetails.HasFloorPlans) { community.FloorPlans = ( from m in this.CommunityDetails.FloorPlans select m.ToEntity()).ToList <FloorPlan>(); community.FloorPlans.ForEach((FloorPlan m) => m.Community = community); } if (this.CommunityDetails.HasSpecHomes) { community.SpecHomes = ( from m in this.CommunityDetails.SpecHomes select m.ToEntity()).ToList <SpecHome>(); community.SpecHomes.ForEach((SpecHome m) => m.Community = community); } if (this.CommunityDetails.HasHouses) { community.Houses = ( from m in this.CommunityDetails.Houses select m.ToEntity()).ToList <House>(); community.Houses.ForEach((House m) => m.Community = community); } community.PropertyManager = this.ListingDetails.PropertyManager.ToEntity(OwnerType.PropertyManager); community.Builder = this.ListingDetails.Builder.ToEntity(OwnerType.Builder); community.CallTrackingPhones = new List <CallTrackingPhone>(); if (this.ListingDetails.CallTrackingPhones != null) { if (!this.ListingDetails.ProvisionCallTrackingNumbers) { this.ListingDetails.CallTrackingPhones.ForEach((CallTrackingPhoneVm c) => c.IsDisconnected = true); } community.CallTrackingPhones = ( from p in this.ListingDetails.CallTrackingPhones.ConvertAll <CallTrackingPhone>((CallTrackingPhoneVm x) => x.ToEntity()) where !string.IsNullOrEmpty(p.Phone) select p).ToList <CallTrackingPhone>(); } community.Publishing.StartDate = this.PublishStart; community.Publishing.EndDate = this.PublishEnd; community.Showcase.StartDate = this.ShowcaseStart; community.Showcase.EndDate = this.ShowcaseEnd; return(community); }