private Page GetPage(Page request) { var id = request?.Id; Page ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <Page>(currentUser, "Page", request.Select); DocEntityPage entity = null; if (id.HasValue) { entity = DocEntityPage.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No Page found for Id {id.Value}"); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route."); } ret = entity?.ToDto(); return(ret); }
public Page Post(PageCopy request) { Page ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityPage.Get(request?.Id); if (null == entity) { throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed."); } if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } var pApps = entity.Apps.ToList(); var pDescription = entity.Description; if (!DocTools.IsNullOrEmpty(pDescription)) { pDescription += " (Copy)"; } var pGlossary = entity.Glossary.ToList(); var pHelp = entity.Help.ToList(); var pName = entity.Name; if (!DocTools.IsNullOrEmpty(pName)) { pName += " (Copy)"; } var pRoles = entity.Roles.ToList(); var copy = new DocEntityPage(ssn) { Hash = Guid.NewGuid() , Description = pDescription , Name = pName }; foreach (var item in pApps) { entity.Apps.Add(item); } foreach (var item in pGlossary) { entity.Glossary.Add(item); } foreach (var item in pHelp) { entity.Help.Add(item); } foreach (var item in pRoles) { entity.Roles.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }