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

                    var en = DocEntityLookupTable.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No LookupTable 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.LOOKUPTABLE);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
コード例 #2
0
        private LookupTable GetLookupTable(LookupTable request)
        {
            var         id    = request?.Id;
            LookupTable ret   = null;
            var         query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityLookupTable entity = null;

            if (id.HasValue)
            {
                entity = DocEntityLookupTable.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No LookupTable 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);
        }
コード例 #3
0
        public LookupTable Post(LookupTableCopy request)
        {
            LookupTable ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLookupTable.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 pBindings   = entity.Bindings.ToList();
                    var pCategories = entity.Categories.ToList();
                    var pDocuments  = entity.Documents.ToList();
                    var pEnum       = entity.Enum;
                    var pName       = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var copy = new DocEntityLookupTable(ssn)
                    {
                        Hash   = Guid.NewGuid()
                        , Enum = pEnum
                        , Name = pName
                    };
                    foreach (var item in pBindings)
                    {
                        entity.Bindings.Add(item);
                    }

                    foreach (var item in pCategories)
                    {
                        entity.Categories.Add(item);
                    }

                    foreach (var item in pDocuments)
                    {
                        entity.Documents.Add(item);
                    }

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