Ejemplo n.º 1
0
        private Impersonation GetImpersonation(Impersonation request)
        {
            var           id    = request?.Id;
            Impersonation ret   = null;
            var           query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityImpersonation entity = null;

            if (id.HasValue)
            {
                entity = DocEntityImpersonation.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No Impersonation 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);
        }