public void ReplacePage(int appId, int pageId, AjaxMozaicEditorPage postData) { try { var context = COREobject.i.Context; var app = context.Applications.Find(appId); app.MozaicChangedSinceLastBuild = true; app.TapestryChangedSinceLastBuild = true; var requestedPage = context.MozaicEditorPages.Find(pageId); deleteComponents(requestedPage, context); requestedPage.Name = postData.Name; requestedPage.IsModal = postData.IsModal; requestedPage.ModalWidth = postData.ModalWidth; requestedPage.ModalHeight = postData.ModalHeight; foreach (var ajaxComponent in postData.Components) { requestedPage.Components.Add(convertAjaxComponentToDbFormat(ajaxComponent, requestedPage, null)); } requestedPage.IsDeleted = false; context.SaveChanges(); } catch (Exception ex) { var errorMessage = $"Mozaic editor: error replacing page with id={pageId} (POST api/mozaic-editor/apps/{appId}/pages/{pageId}) " + $"Exception message: {ex.Message}"; throw GetHttpInternalServerErrorResponseException(errorMessage); } }
public int NewPage(int appId, AjaxMozaicEditorPage postData) { try { var context = COREobject.i.Context; var app = context.Applications.Find(appId); app.MozaicChangedSinceLastBuild = true; app.TapestryChangedSinceLastBuild = true; var newPage = new MozaicEditorPage { Name = postData.Name }; foreach (var ajaxComponent in postData.Components) { newPage.Components.Add(convertAjaxComponentToDbFormat(ajaxComponent, newPage, null)); } context.Applications.Find(appId).MozaicEditorPages.Add(newPage); context.SaveChanges(); return(newPage.Id); } catch (Exception ex) { var errorMessage = $"Mozaic editor: error creating new page (POST api/mozaic-editor/apps/{appId}/pages) " + $"Exception message: {ex.Message}"; throw GetHttpInternalServerErrorResponseException(errorMessage); } }
public AjaxMozaicEditorPage GetPage(int appId, int pageId) { try { var context = COREobject.i.Context; var requestedPage = context.MozaicEditorPages.Find(pageId); // TODO: replace with real error checking if (requestedPage == null) { return(new AjaxMozaicEditorPage()); } var result = new AjaxMozaicEditorPage { Id = requestedPage.Id, Name = requestedPage.Name ?? "Nepojmenovaná stránka", IsModal = requestedPage.IsModal, ModalWidth = requestedPage.ModalWidth, ModalHeight = requestedPage.ModalHeight }; foreach (var component in requestedPage.Components.Where(c => c.ParentComponent == null)) { var ajaxComponent = new AjaxMozaicEditorComponent { Id = component.Id, Name = component.Name ?? "", Type = component.Type, PositionX = component.PositionX, PositionY = component.PositionY, Width = component.Width, Height = component.Height, Tag = component.Tag, Attributes = component.Attributes, Classes = component.Classes ?? "", Styles = component.Styles ?? "", Content = component.Content, Label = component.Label, Placeholder = component.Placeholder, TabIndex = component.TabIndex, Properties = component.Properties ?? "" }; if (component.ChildComponents.Count > 0) { ajaxComponent.ChildComponents = new List <AjaxMozaicEditorComponent>(); foreach (var childComponent in component.ChildComponents) { ajaxComponent.ChildComponents.Add(new AjaxMozaicEditorComponent { Id = childComponent.Id, Name = childComponent.Name ?? "", Type = childComponent.Type, PositionX = childComponent.PositionX, PositionY = childComponent.PositionY, Width = childComponent.Width, Height = childComponent.Height, Tag = childComponent.Tag, Attributes = childComponent.Attributes, Classes = childComponent.Classes ?? "", Styles = childComponent.Styles ?? "", Content = childComponent.Content, Label = childComponent.Label, Placeholder = childComponent.Placeholder, TabIndex = childComponent.TabIndex, Properties = childComponent.Properties }); } } result.Components.Add(ajaxComponent); } // Renew deleted page if (requestedPage.IsDeleted) { requestedPage.IsDeleted = false; context.SaveChanges(); } return(result); } catch (Exception ex) { var errorMessage = $"Mozaic editor: error loading page with id={pageId} (GET api/mozaic-editor/apps/{appId}/pages/{pageId}) " + $"Exception message: {ex.Message}"; throw GetHttpInternalServerErrorResponseException(errorMessage); } }