コード例 #1
0
        private LookupTableBinding GetLookupTableBinding(LookupTableBinding request)
        {
            var id = request?.Id;
            LookupTableBinding ret = null;
            var query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityLookupTableBinding entity = null;

            if (id.HasValue)
            {
                entity = DocEntityLookupTableBinding.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No LookupTableBinding 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);
        }
コード例 #2
0
        public LookupTableBinding Post(LookupTableBinding request)
        {
            if (request == null)
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be null.");
            }

            request.Select = request.Select ?? new List <string>();

            LookupTableBinding ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!DocPermissionFactory.HasPermissionTryAdd(currentUser, "LookupTableBinding"))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    ret = _AssignValues(request, DocConstantPermission.ADD, ssn);
                });
            }
            return(ret);
        }
コード例 #3
0
        public void Delete(LookupTableBinding request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityLookupTableBinding.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No LookupTableBinding 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.LOOKUPTABLEBINDING);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
コード例 #4
0
        public LookupTableBinding Post(LookupTableBindingCopy request)
        {
            LookupTableBinding ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLookupTableBinding.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 pBinding   = entity.Binding;
                    var pBoundName = entity.BoundName;
                    if (!DocTools.IsNullOrEmpty(pBoundName))
                    {
                        pBoundName += " (Copy)";
                    }
                    var pLookupTable = entity.LookupTable;
                    var pScope       = entity.Scope;
                    var pSynonyms    = entity.Synonyms.ToList();
                    var pWorkflows   = entity.Workflows.ToList();
                    var copy         = new DocEntityLookupTableBinding(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , Binding     = pBinding
                        , BoundName   = pBoundName
                        , LookupTable = pLookupTable
                        , Scope       = pScope
                    };
                    foreach (var item in pSynonyms)
                    {
                        entity.Synonyms.Add(item);
                    }

                    foreach (var item in pWorkflows)
                    {
                        entity.Workflows.Add(item);
                    }

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
コード例 #5
0
        public LookupTableBinding Patch(LookupTableBinding request)
        {
            if (true != (request?.Id > 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the LookupTableBinding to patch.");
            }

            request.Select = request.Select ?? new List <string>();

            LookupTableBinding ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    ret = _AssignValues(request, DocConstantPermission.EDIT, ssn);
                });
            }
            return(ret);
        }
コード例 #6
0
 public LookupTableBinding Put(LookupTableBinding request)
 {
     return(Patch(request));
 }
コード例 #7
0
        private LookupTableBinding _AssignValues(LookupTableBinding 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, "LookupTableBinding"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            LookupTableBinding ret = null;

            request = _InitAssignValues <LookupTableBinding>(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 <LookupTableBinding>(DocConstantModelName.LOOKUPTABLEBINDING, nameof(LookupTableBinding), request);

            //First, assign all the variables, do database lookups and conversions
            var pBinding = (DocTools.IsNullOrEmpty(request.Binding)) ? null : DocSerialize <Bindings> .ToString(request.Binding);

            var pBoundName = request.BoundName;
            DocEntityLookupTable pLookupTable = GetLookup(DocConstantLookupTable.ATTRIBUTENAME, request.LookupTable?.Name, request.LookupTable?.Id);
            var pScope     = DocEntityScope.Get(request.Scope?.Id, true, Execute) ?? DocEntityScope.Get(request.ScopeId, true, Execute);
            var pSynonyms  = GetVariable <Reference>(request, nameof(request.Synonyms), request.Synonyms?.ToList(), request.SynonymsIds?.ToList());
            var pWorkflows = GetVariable <Reference>(request, nameof(request.Workflows), request.Workflows?.ToList(), request.WorkflowsIds?.ToList());
            var pArchived  = true == request.Archived;
            var pLocked    = request.Locked;

            var entity = InitEntity <DocEntityLookupTableBinding, LookupTableBinding>(request, permission, session);

            if (AllowPatchValue <LookupTableBinding, bool>(request, DocConstantModelName.LOOKUPTABLEBINDING, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <LookupTableBinding, string>(request, DocConstantModelName.LOOKUPTABLEBINDING, pBinding, permission, nameof(request.Binding), pBinding != entity.Binding))
            {
                entity.Binding = pBinding;
            }
            if (AllowPatchValue <LookupTableBinding, string>(request, DocConstantModelName.LOOKUPTABLEBINDING, pBoundName, permission, nameof(request.BoundName), pBoundName != entity.BoundName))
            {
                entity.BoundName = pBoundName;
            }
            if (AllowPatchValue <LookupTableBinding, DocEntityLookupTable>(request, DocConstantModelName.LOOKUPTABLEBINDING, pLookupTable, permission, nameof(request.LookupTable), pLookupTable != entity.LookupTable))
            {
                entity.LookupTable = pLookupTable;
            }
            if (AllowPatchValue <LookupTableBinding, DocEntityScope>(request, DocConstantModelName.LOOKUPTABLEBINDING, pScope, permission, nameof(request.Scope), pScope != entity.Scope))
            {
                entity.Scope = pScope;
            }
            if (request.Locked && AllowPatchValue <LookupTableBinding, bool>(request, DocConstantModelName.LOOKUPTABLEBINDING, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            idsToInvalidate.AddRange(PatchCollection <LookupTableBinding, DocEntityLookupTableBinding, Reference, DocEntityTermSynonym>(request, entity, pSynonyms, permission, nameof(request.Synonyms)));
            idsToInvalidate.AddRange(PatchCollection <LookupTableBinding, DocEntityLookupTableBinding, Reference, DocEntityWorkflow>(request, entity, pWorkflows, permission, nameof(request.Workflows)));
            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.LOOKUPTABLEBINDING);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <LookupTableBinding>(currentUser, nameof(LookupTableBinding), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.LOOKUPTABLEBINDING);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.LOOKUPTABLEBINDING, cacheExpires);

            return(ret);
        }
コード例 #8
0
 public object Get(LookupTableBinding request) => GetEntityWithCache <LookupTableBinding>(DocConstantModelName.LOOKUPTABLEBINDING, request, GetLookupTableBinding);