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

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

            DocEntityDefault entity = null;

            if (id.HasValue)
            {
                entity = DocEntityDefault.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No Default 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 Default Post(DefaultCopy request)
        {
            Default ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityDefault.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 pDiseaseState    = entity.DiseaseState;
                    var pRole            = entity.Role;
                    var pScope           = entity.Scope;
                    var pTherapeuticArea = entity.TherapeuticArea;
                    var copy             = new DocEntityDefault(ssn)
                    {
                        Hash              = Guid.NewGuid()
                        , DiseaseState    = pDiseaseState
                        , Role            = pRole
                        , Scope           = pScope
                        , TherapeuticArea = pTherapeuticArea
                    };

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