private TermCategory GetTermCategory(TermCategory request) { var id = request?.Id; TermCategory ret = null; var query = DocQuery.ActiveQuery ?? Execute; DocPermissionFactory.SetSelect <TermCategory>(currentUser, "TermCategory", request.Select); DocEntityTermCategory entity = null; if (id.HasValue) { entity = DocEntityTermCategory.Get(id.Value); } if (null == entity) { throw new HttpError(HttpStatusCode.NotFound, $"No TermCategory 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 TermCategory Post(TermCategoryCopy request) { TermCategory ret = null; using (Execute) { Execute.Run(ssn => { var entity = DocEntityTermCategory.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 pName = entity.Name; var pParentCategory = entity.ParentCategory; var pScope = entity.Scope; var pTerms = entity.Terms.ToList(); var copy = new DocEntityTermCategory(ssn) { Hash = Guid.NewGuid() , Name = pName , ParentCategory = pParentCategory , Scope = pScope }; foreach (var item in pTerms) { entity.Terms.Add(item); } copy.SaveChanges(DocConstantPermission.ADD); ret = copy.ToDto(); }); } return(ret); }