Beispiel #1
0
        private Rating GetRating(Rating request)
        {
            var    id    = request?.Id;
            Rating ret   = null;
            var    query = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityRating entity = null;

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

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityRating.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 pAssignee    = entity.Assignee;
                    var pData        = entity.Data;
                    var pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pDocument       = entity.Document;
                    var pDueDate        = entity.DueDate;
                    var pRating         = entity.Rating;
                    var pReasonRejected = entity.ReasonRejected;
                    var pReporter       = entity.Reporter;
                    var pType           = entity.Type;
                    var pWorkflow       = entity.Workflow;
                    var copy            = new DocEntityRating(ssn)
                    {
                        Hash             = Guid.NewGuid()
                        , Assignee       = pAssignee
                        , Data           = pData
                        , Description    = pDescription
                        , Document       = pDocument
                        , DueDate        = pDueDate
                        , Rating         = pRating
                        , ReasonRejected = pReasonRejected
                        , Reporter       = pReporter
                        , Type           = pType
                        , Workflow       = pWorkflow
                    };

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