protected override void ProcessAttributes(BookVersion bookVersion, XmlReader xmlReader) { var termXmlId = xmlReader.GetAttribute("id"); var position = xmlReader.GetAttribute("n"); string termCategoryName = xmlReader.GetAttribute("subtype"); string text = GetInnerContentAsString(xmlReader); TermCategory termCategory = null; if (!string.IsNullOrWhiteSpace(termCategoryName)) { termCategory = m_termRepository.GetTermCategoryByName(termCategoryName) ?? new TermCategory { Name = termCategoryName }; } var term = new Term { XmlId = termXmlId, Position = long.Parse(position), Text = text, TermCategory = termCategory, }; m_termRepository.SaveOrUpdate(term); }
public bool AddTerm(TermModel termModel) { bool retVal = false; try { TermCategory category = realmRepository.GetAll <TermCategory>().FirstOrDefault(x => x.Name.Equals(termModel.Category.Name)); if (category == null) { category = new TermCategory { Id = DateTime.Now.Ticks, Name = termModel.Category.Name }; } Term term = new Term { Id = DateTime.Now.Ticks, Category = category, NoOfOccurrence = 0, Value = termModel.Value }; realmRepository.Add(term); retVal = true; } catch (Exception ex) { retVal = false; } return(retVal); }
public void TestIsRank() { var negOne = new NegOneRank(); var zero = new ZeroRank(); var one = new OneRank(); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Eq, zero, zero)); Assert.IsFalse(TermCategory.IsRank(TermCategoryBoolOps.Eq, one, zero)); Assert.IsFalse(TermCategory.IsRank(TermCategoryBoolOps.Eq, zero, one)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Ne, zero, one)); Assert.IsFalse(TermCategory.IsRank(TermCategoryBoolOps.Ne, one, one)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Gt, one, zero)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Gt, zero, negOne)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Lt, zero, one)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Lt, negOne, zero)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Ge, one, zero)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Ge, zero, negOne)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Ge, zero, zero)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Ge, negOne, negOne)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Ge, one, one)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Le, zero, one)); Assert.IsTrue(TermCategory.IsRank(TermCategoryBoolOps.Le, negOne, zero)); }
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(TermCategory request) { if (request == null) { throw new HttpError(HttpStatusCode.NotFound, "Request cannot be null."); } request.Select = request.Select ?? new List <string>(); TermCategory ret = null; using (Execute) { Execute.Run(ssn => { if (!DocPermissionFactory.HasPermissionTryAdd(currentUser, "TermCategory")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } ret = _AssignValues(request, DocConstantPermission.ADD, ssn); }); } return(ret); }
public void Delete(TermCategory request) { using (Execute) { Execute.Run(ssn => { if (!(request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete."); } var en = DocEntityTermCategory.Get(request?.Id); if (null == en) { throw new HttpError(HttpStatusCode.NotFound, $"No TermCategory could be found for Id {request?.Id}."); } if (en.IsRemoved) { return; } if (!DocPermissionFactory.HasPermission(en, currentUser, DocConstantPermission.DELETE)) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have DELETE permission for this route."); } en.Remove(); DocCacheClient.RemoveSearch(DocConstantModelName.TERMCATEGORY); DocCacheClient.RemoveById(request.Id); }); } }
public virtual Term GetTermByNameAndCategoryName(string termName, string termCategoryName) { TermCategory termCategoryAlias = null; return(GetSession().QueryOver <Term>() .JoinAlias(x => x.TermCategory, () => termCategoryAlias) .Where(x => x.Text == termName) .And(() => termCategoryAlias.Name == termCategoryName) .SingleOrDefault()); }
private TermCategory GetOrCreateTermCategory(string termCategoryName) { var dbTermCategory = m_resourceRepository.GetTermCategoryByName(termCategoryName); if (dbTermCategory != null) { return(dbTermCategory); } var newDbTermCategory = new TermCategory { Name = termCategoryName, }; m_resourceRepository.Create(newDbTermCategory); newDbTermCategory = m_resourceRepository.Load <TermCategory>(newDbTermCategory.Id); return(newDbTermCategory); }
public TermCategory Patch(TermCategory request) { if (true != (request?.Id > 0)) { throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the TermCategory to patch."); } request.Select = request.Select ?? new List <string>(); TermCategory ret = null; using (Execute) { Execute.Run(ssn => { ret = _AssignValues(request, DocConstantPermission.EDIT, ssn); }); } 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); }
public TermCategory Put(TermCategory request) { return(Patch(request)); }
private TermCategory _AssignValues(TermCategory request, DocConstantPermission permission, Session session) { if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0)) { throw new HttpError(HttpStatusCode.NotFound, $"No record"); } if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "TermCategory")) { throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route."); } request.Select = request.Select ?? new List <string>(); TermCategory ret = null; request = _InitAssignValues <TermCategory>(request, permission, session); //In case init assign handles create for us, return it if (permission == DocConstantPermission.ADD && request.Id > 0) { return(request); } var cacheKey = GetApiCacheKey <TermCategory>(DocConstantModelName.TERMCATEGORY, nameof(TermCategory), request); //First, assign all the variables, do database lookups and conversions DocEntityLookupTable pName = GetLookup(DocConstantLookupTable.TERMCATEGORY, request.Name?.Name, request.Name?.Id); var pParentCategory = DocEntityTermCategory.Get(request.ParentCategory?.Id, true, Execute) ?? DocEntityTermCategory.Get(request.ParentCategoryId, true, Execute); var pScope = DocEntityScope.Get(request.Scope?.Id, true, Execute) ?? DocEntityScope.Get(request.ScopeId, true, Execute); var pTerms = GetVariable <Reference>(request, nameof(request.Terms), request.Terms?.ToList(), request.TermsIds?.ToList()); var pArchived = true == request.Archived; var pLocked = request.Locked; var entity = InitEntity <DocEntityTermCategory, TermCategory>(request, permission, session); if (AllowPatchValue <TermCategory, bool>(request, DocConstantModelName.TERMCATEGORY, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived)) { entity.Archived = pArchived; } if (AllowPatchValue <TermCategory, DocEntityLookupTable>(request, DocConstantModelName.TERMCATEGORY, pName, permission, nameof(request.Name), pName != entity.Name)) { entity.Name = pName; } if (AllowPatchValue <TermCategory, DocEntityTermCategory>(request, DocConstantModelName.TERMCATEGORY, pParentCategory, permission, nameof(request.ParentCategory), pParentCategory != entity.ParentCategory)) { entity.ParentCategory = pParentCategory; } if (AllowPatchValue <TermCategory, DocEntityScope>(request, DocConstantModelName.TERMCATEGORY, pScope, permission, nameof(request.Scope), pScope != entity.Scope)) { entity.Scope = pScope; } if (request.Locked && AllowPatchValue <TermCategory, bool>(request, DocConstantModelName.TERMCATEGORY, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked)) { entity.Archived = pArchived; } entity.SaveChanges(permission); var idsToInvalidate = new List <int>(); idsToInvalidate.AddRange(PatchCollection <TermCategory, DocEntityTermCategory, Reference, DocEntityTermMaster>(request, entity, pTerms, permission, nameof(request.Terms))); if (idsToInvalidate.Any()) { idsToInvalidate.Add(entity.Id); DocCacheClient.RemoveByEntityIds(idsToInvalidate); DocCacheClient.RemoveSearch(DocConstantModelName.TERMCATEGORY); } entity.SaveChanges(permission); DocPermissionFactory.SetSelect <TermCategory>(currentUser, nameof(TermCategory), request.Select); ret = entity.ToDto(); var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.TERMCATEGORY); DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.TERMCATEGORY, cacheExpires); return(ret); }
public object Get(TermCategory request) => GetEntityWithCache <TermCategory>(DocConstantModelName.TERMCATEGORY, request, GetTermCategory);
public Proportionality(Func <ILegalPerson[], ILegalPerson> getSubjectPerson) : base(getSubjectPerson) { IsProportional = (t1, t2) => TermCategory.IsRank(TermCategoryBoolOps.Eq, t1, t2) && TermCategory.IsRank(TermCategoryBoolOps.Eq, t2, t1); }
public ChoiceThereof(Func <ILegalPerson[], ILegalPerson> getSubjectPerson) : base(getSubjectPerson) { IsProportional = (t1, t2) => TermCategory.IsRank(TermCategoryBoolOps.Lt, t1, t2); }