public BuildingBackOfficeModel GetById(int id) { BuildingBackOfficeModel model = new BuildingBackOfficeModel(); var building = _bldgRepo.GetById(id); AddressManager addressMgr = new AddressManager(); model.Building = building; model.Addresses = addressMgr.GetByBuildingId(building.Id); return(model); }
private void TryCreatingMediaStructure(List <Apartment> apartments, int buildingId) { try { var building = _buildingRepo.GetById(buildingId); var account = _accountRepo.GetById(building.AccountId); var apartmentIdentifiers = apartments.Select(x => x.Name).ToList(); var result = _mediaManager.CreateFolder(account.Name, account.Id, building.Name, building.Id, apartmentIdentifiers); } catch (Exception ex) { LogHelper.Error <ApartmentManager>(ex.Message, ex); } }
/// <summary> /// Get specific building asset based on its id and building /// Not specifying the asset id will default to first asset object in /// a building's asset collection /// </summary> /// <param name="buildingId"></param> /// <param name="assetId"></param> /// <returns></returns> public BuildingAsset GetBuildingAsset(int buildingId, int assetId = -1) { IList <BuildingAsset> buildingAssets = GetBuildingAssets(buildingId); if (buildingAssets != null && buildingAssets.Count > 0) { if (assetId > 0) { return(_buildingAssetRepo.GetById(assetId)); } return(buildingAssets.FirstOrDefault()); } return(null); }
public void UpdateAsset(int buildingId, int mediaId) { //check if child media node already exists in the db var dbassetExisting = _buildingAssetRepo.GetById(mediaId); if (dbassetExisting != null) { dbassetExisting.BuildingId = buildingId; dbassetExisting.MediaId = mediaId; dbassetExisting.TypeId = (int)AssetMediaType.Image; //just update to make sure it's referenced to correct buildign and media _buildingAssetRepo.Update(dbassetExisting.Id, dbassetExisting); } else { //re-add each media to db asset table _buildingAssetRepo.Insert((BuildingAsset)AssetFactory.CreateAsset(AssetType.Building, buildingId, mediaId, AssetMediaType.Image)); } }
public ActionResult BMEmbedBuildingSlider(Guid guid) { var bldg = ((BuildingRepository)_buildingRepo).GetByGuid(guid); if (bldg != null) { var buildingModel = new SliderViewModel(); buildingModel.Id = bldg.Id; buildingModel.AccountId = bldg.AccountId; buildingModel.Name = bldg.Name; buildingModel.Description = bldg.Description; buildingModel.CreatedOn = bldg.CreatedOn; buildingModel.CreatedBy = bldg.CreatedBy; buildingModel.ModifiedBy = bldg.ModifiedBy; buildingModel.ModifiedOn = bldg.ModifiedOn; buildingModel.AccountName = _accountRepo.GetById(bldg.AccountId).Name; var apartmentStatusRepo = new ApartmentStatusRepository(); buildingModel.ApartmentStatuses = apartmentStatusRepo.GetAll() as List <ApartmentStatus>; buildingModel.Guid = bldg.Guid; var asset = new AssetManager(); var assets = asset.GetAssets(bldg.Id); var mediaItems = new Dictionary <int, string>(); foreach (var media in assets) { var umbracoMedia = Umbraco.Media(media.MediaId); mediaItems.Add(media.MediaId, umbracoMedia.Url); } buildingModel.MediaItems = mediaItems; buildingModel.Apartments = _apartmentRepo.GetAllByBuildingId(bldg.Id); return(View("BMEmbedBuildingSlider", buildingModel)); } return(View()); }
public ActionResult BMBuildingPage(RenderModel model) { if (model == null || model.Content == null) { return(CurrentUmbracoPage()); } if (model.Content.IsPropertyValid(Constants.BUILDING_PROPERTY_ALIAS)) { int bldgId = -1; int.TryParse(model.Content.GetValidPropertyValue(Constants.BUILDING_PROPERTY_ALIAS).ToString(), out bldgId); if (bldgId > -1) { var bldg = _buildingRepo.GetById(bldgId); var assetManager = new AssetManager(); if (bldg != null) { var buildingModel = new BuildingViewModel(CurrentPage); buildingModel.Id = bldg.Id; buildingModel.AccountId = bldg.AccountId; buildingModel.Name = bldg.Name; buildingModel.Description = bldg.Description; buildingModel.CreatedOn = bldg.CreatedOn; buildingModel.CreatedBy = bldg.CreatedBy; buildingModel.ModifiedBy = bldg.ModifiedBy; buildingModel.ModifiedOn = bldg.ModifiedOn; buildingModel.AccountName = _accountRepo.GetById(bldg.AccountId).Name; var apartmentStatusRepo = new ApartmentStatusRepository(); buildingModel.ApartmentStatuses = apartmentStatusRepo.GetAll() as List <ApartmentStatus>; buildingModel.Guid = bldg.Guid; var asset = new AssetManager(); var assets = asset.GetAssets(bldg.Id); var mediaIds = new List <int>(); foreach (var media in assets) { mediaIds.Add(media.MediaId); } buildingModel.MediaItems = mediaIds; buildingModel.Apartments = _apartmentRepo.GetAllByBuildingId(bldg.Id); // var pdfStatus = new ApartmentAssetPdfViewModel(); foreach (var apartment in buildingModel.Apartments) { var apartmenPdf = assetManager.GetByApartmentId(apartment.Id); var pdfStatus = new ApartmentAssetPdfViewModel(); if (apartmenPdf != null) { pdfStatus.HasPdf = true; pdfStatus.ApartmentId = apartment.Id; } else { pdfStatus.HasPdf = false; pdfStatus.ApartmentId = apartment.Id; } buildingModel.PdfStatus.Add(pdfStatus); } return(CurrentTemplate(buildingModel)); } } return(CurrentUmbracoPage()); } return(CurrentUmbracoPage()); }
public Building GetBuildingById(int buildingId) { return(_buildingRepo.GetById(buildingId)); }
/// <summary> /// Method to check if asset is found on db and that if found, /// check if the reference to media library object can be found also, /// otherwise, delete the record on the database and default to 'no image' thumbnail /// </summary> /// <param name="mediaId"></param> /// <returns></returns> public IMedia TryGetTypedMediaAsset(int buildingId, int mediaId) { //try finding from the custom 'buildingAsset' db table var dbMediaAsset = _buildingAssetRepo.GetById(mediaId); //from the umbraco media library var mediaAsset = _mediaService.GetById(mediaId); // UmbracoHelper.TypedMedia(mediaId); //if dbasset found and media (from umbraco) also found if (dbMediaAsset != null && (mediaAsset != null && !mediaAsset.Trashed)) { return(mediaAsset); } IMedia mediaAssetFound = null; //Building var building = _buildingRepo.GetById(buildingId); var account = _accountRepo.GetById(building.AccountId); //if it CANNOT find the DB asset if (dbMediaAsset == null) { //TODO: what if there are many folders existing for the building //try to check if building has already existing DB folder var bldgFolder = GetBuildingFolder(building.Id); if (bldgFolder != null) { //try to check if media library folder for the building already exist in UMB var mediaAssetFolder = GetMediaFolder(bldgFolder.FolderId); if (mediaAssetFolder != null && _mediaService.HasChildren(mediaAssetFolder.Id)) { //try to find existing media asset of type images or similar under the //media library for the building var childrenMedia = _mediaService.GetChildren(mediaAssetFolder.Id); var enumerator = childrenMedia.GetEnumerator(); while (enumerator.MoveNext()) { //update the assets related to the media assets in the building's folder library if (enumerator.Current.Id == mediaId) { _assetManager.UpdateAsset(building.Id, enumerator.Current.Id); mediaAssetFound = enumerator.Current; } }//end while } } else { //try to create the folders on db and media library var result = CreateFolder(account.Name, account.Id, building.Name, building.Id); } } else { //if db asset found but for some reason, //media was not (possibly deleted from the media library in Backoffice or in recycle bin) //delete the record if (dbMediaAsset != null && (mediaAsset == null || mediaAsset.Trashed)) { ((BuildingAssetRepository)_buildingAssetRepo).Delete(dbMediaAsset); } } return(mediaAssetFound); }