Esempio n. 1
0
        private LookupTableEnum GetLookupTableEnum(LookupTableEnum request)
        {
            var             id    = request?.Id;
            LookupTableEnum ret   = null;
            var             query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityLookupTableEnum entity = null;

            if (id.HasValue)
            {
                entity = DocEntityLookupTableEnum.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No LookupTableEnum 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. 2
0
        public LookupTableEnum Post(LookupTableEnumCopy request)
        {
            LookupTableEnum ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityLookupTableEnum.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 pIsBindable = entity.IsBindable;
                    var pIsGlobal   = entity.IsGlobal;
                    var pName       = entity.Name;
                    if (!DocTools.IsNullOrEmpty(pName))
                    {
                        pName += " (Copy)";
                    }
                    var copy = new DocEntityLookupTableEnum(ssn)
                    {
                        Hash         = Guid.NewGuid()
                        , IsBindable = pIsBindable
                        , IsGlobal   = pIsGlobal
                        , Name       = pName
                    };

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