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

                    var en = DocEntityReconcileDocument.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No ReconcileDocument 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.RECONCILEDOCUMENT);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
Exemple #2
0
        private ReconcileDocument GetReconcileDocument(ReconcileDocument request)
        {
            var id = request?.Id;
            ReconcileDocument ret = null;
            var query             = DocQuery.ActiveQuery ?? Execute;

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

            DocEntityReconcileDocument entity = null;

            if (id.HasValue)
            {
                entity = DocEntityReconcileDocument.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No ReconcileDocument 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);
        }
Exemple #3
0
        public ReconcileDocument Post(ReconcileDocumentCopy request)
        {
            ReconcileDocument ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityReconcileDocument.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 pArticleId = entity.ArticleId;
                    if (!DocTools.IsNullOrEmpty(pArticleId))
                    {
                        pArticleId += " (Copy)";
                    }
                    var pArticleLink = entity.ArticleLink;
                    if (!DocTools.IsNullOrEmpty(pArticleLink))
                    {
                        pArticleLink += " (Copy)";
                    }
                    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 pMatches    = entity.Matches;
                    var pReporter   = entity.Reporter;
                    var pSearchLink = entity.SearchLink;
                    if (!DocTools.IsNullOrEmpty(pSearchLink))
                    {
                        pSearchLink += " (Copy)";
                    }
                    var pStatus   = entity.Status;
                    var pType     = entity.Type;
                    var pWorkflow = entity.Workflow;
                    var copy      = new DocEntityReconcileDocument(ssn)
                    {
                        Hash          = Guid.NewGuid()
                        , ArticleId   = pArticleId
                        , ArticleLink = pArticleLink
                        , Assignee    = pAssignee
                        , Data        = pData
                        , Description = pDescription
                        , Document    = pDocument
                        , DueDate     = pDueDate
                        , Matches     = pMatches
                        , Reporter    = pReporter
                        , SearchLink  = pSearchLink
                        , Status      = pStatus
                        , Type        = pType
                        , Workflow    = pWorkflow
                    };

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