private Form GetAlbumForm(string context, long elementId) { // Get current album settings Guid elementTypeId = FormId; IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId); AlbumSettings albumSettings = (AlbumSettings)elementService.New(_authenticationService.TenantId); albumSettings.ElementId = elementId; elementService.Read(albumSettings); // Get album photo view models List <AlbumPhotoViewModel> photoViewModels = new List <AlbumPhotoViewModel>(); foreach (AlbumPhoto photo in albumSettings.Photos) { AlbumPhotoViewModel photoViewModel = new AlbumPhotoViewModel { AlbumPhotoId = photo.AlbumPhotoId.ToString(), PreviewImageUploadId = photo.PreviewImageUploadId.ToString(), Name = photo.Name, Description = photo.Description, ImageUrl = string.Format("/elements/{0}/uploads/{1}?format=preview&t={1}", photo.ElementId, photo.AlbumPhotoId) }; photoViewModels.Add(photoViewModel); } string data = JsonConvert.SerializeObject(photoViewModels); // Return form with data return(new Form { Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context, Data = data }); }
private AlbumPhotoViewModel GetPhotoViewModel(AlbumPhoto photo, bool uncommittedPhotoImages) { // TODO: Use proper URL routing here, do not hard wire these URLs. string imageUrl = null; if (uncommittedPhotoImages) { imageUrl = string.Format("/uploads/{0}?t={0}", photo.ThumbnailImageUploadId); } else { imageUrl = string.Format("/elements/{0}/uploads/{1}?format=thumbnail&t={1}", photo.ElementId, photo.AlbumPhotoId); } AlbumPhotoViewModel photoViewModel = new AlbumPhotoViewModel { AlbumPhotoId = photo.AlbumPhotoId.ToString(), ThumbnailImageUploadId = photo.ThumbnailImageUploadId.ToString(), PreviewImageUploadId = photo.PreviewImageUploadId.ToString(), ImageUploadId = photo.ImageUploadId.ToString(), Name = photo.Name, Description = photo.Description, ImageUrl = imageUrl }; return(photoViewModel); }
private string PostPhotoForm(Form form, long tenantId, long pageId, long elementId) { // Get album photo details long albumPhotoId = Convert.ToInt64(form.Data); string uploadIds = ((UploadField)form.Fields["upload"]).Value; AlbumPhoto photo = new AlbumPhoto { TenantId = tenantId, ElementId = elementId, AlbumPhotoId = albumPhotoId, Name = ((TextField)form.Fields["name"]).Value, Description = ((MultiLineTextField)form.Fields["description"]).Value }; if (!string.IsNullOrWhiteSpace(uploadIds)) { string[] uploadParts = uploadIds.Split('|'); photo.ImageTenantId = tenantId; photo.ThumbnailImageUploadId = Convert.ToInt64(uploadParts[0]); photo.PreviewImageUploadId = Convert.ToInt64(uploadParts[1]); photo.ImageUploadId = Convert.ToInt64(uploadParts[2]); } // Validate supplied data _albumValidator.ValidatePhoto(photo); // Determine whether or not there are uncommitted photo images bool uncommittedPhotoImages = true; if (albumPhotoId > 0) { IAlbumService albumService = (IAlbumService)_elementFactory.GetElementService(FormId); AlbumPhoto currentPhoto = albumService.ReadPhoto(tenantId, elementId, albumPhotoId); uncommittedPhotoImages = currentPhoto.ImageUploadId != photo.ImageUploadId; } // Get photo view model and return it's JSON representation as form result status AlbumPhotoViewModel photoViewModel = GetPhotoViewModel(photo, uncommittedPhotoImages); return(JsonConvert.SerializeObject(photoViewModel)); }
private void PostPhotosForm(Form form, long pageId, long elementId) { // Get tenant ID long tenantId = _authenticationService.TenantId; // Get element service IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(FormId); // Get updated album settings AlbumSettings albumSettings = (AlbumSettings)elementService.New(_authenticationService.TenantId); albumSettings.ElementId = elementId; albumSettings.DisplayName = string.IsNullOrWhiteSpace(((TextField)form.Fields["displayName"]).Value) ? null : ((TextField)form.Fields["displayName"]).Value; albumSettings.Photos = new List <AlbumPhoto>(); List <AlbumPhotoViewModel> photoViewModels = JsonConvert.DeserializeObject <List <AlbumPhotoViewModel> >(form.Data); for (int index = 0; index < photoViewModels.Count; index++) { AlbumPhotoViewModel photoViewModel = photoViewModels[index]; albumSettings.Photos.Add(new AlbumPhoto { AlbumPhotoId = Convert.ToInt64(photoViewModel.AlbumPhotoId), Description = photoViewModel.Description, ElementId = elementId, ImageTenantId = tenantId, ImageUploadId = Convert.ToInt64(photoViewModel.ImageUploadId), Name = photoViewModel.Name, PreviewImageUploadId = Convert.ToInt64(photoViewModel.PreviewImageUploadId), SortOrder = index, TenantId = tenantId, ThumbnailImageUploadId = Convert.ToInt64(photoViewModel.ThumbnailImageUploadId) }); } // Perform the update elementService.Update(albumSettings); }