Esempio n. 1
0
        public void Delete(TermSynonym request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityTermSynonym.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No TermSynonym 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.TERMSYNONYM);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Esempio n. 2
0
        private TermSynonym GetTermSynonym(TermSynonym request)
        {
            var         id    = request?.Id;
            TermSynonym ret   = null;
            var         query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <TermSynonym>(currentUser, "TermSynonym", request.Select);

            DocEntityTermSynonym entity = null;

            if (id.HasValue)
            {
                entity = DocEntityTermSynonym.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No TermSynonym 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);
        }
Esempio n. 3
0
        public TermSynonym Post(TermSynonymCopy request)
        {
            TermSynonym ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityTermSynonym.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 pApproved  = entity.Approved;
                    var pBindings  = entity.Bindings.ToList();
                    var pMaster    = entity.Master;
                    var pPreferred = entity.Preferred;
                    var pScope     = entity.Scope;
                    var pSynonym   = entity.Synonym;
                    if (!DocTools.IsNullOrEmpty(pSynonym))
                    {
                        pSynonym += " (Copy)";
                    }
                    var copy = new DocEntityTermSynonym(ssn)
                    {
                        Hash        = Guid.NewGuid()
                        , Approved  = pApproved
                        , Master    = pMaster
                        , Preferred = pPreferred
                        , Scope     = pScope
                        , Synonym   = pSynonym
                    };
                    foreach (var item in pBindings)
                    {
                        entity.Bindings.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }