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

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

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

            DocEntityHelp entity = null;

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

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityHelp.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 pConfluenceId = entity.ConfluenceId;
                    if (!DocTools.IsNullOrEmpty(pConfluenceId))
                    {
                        pConfluenceId += " (Copy)";
                    }
                    var pDescription = entity.Description;
                    if (!DocTools.IsNullOrEmpty(pDescription))
                    {
                        pDescription += " (Copy)";
                    }
                    var pIcon = entity.Icon;
                    if (!DocTools.IsNullOrEmpty(pIcon))
                    {
                        pIcon += " (Copy)";
                    }
                    var pOrder  = entity.Order;
                    var pPages  = entity.Pages.ToList();
                    var pScopes = entity.Scopes.ToList();
                    var pTitle  = entity.Title;
                    if (!DocTools.IsNullOrEmpty(pTitle))
                    {
                        pTitle += " (Copy)";
                    }
                    var pType = entity.Type;
                    var copy  = new DocEntityHelp(ssn)
                    {
                        Hash           = Guid.NewGuid()
                        , ConfluenceId = pConfluenceId
                        , Description  = pDescription
                        , Icon         = pIcon
                        , Order        = pOrder
                        , Title        = pTitle
                        , Type         = pType
                    };
                    foreach (var item in pPages)
                    {
                        entity.Pages.Add(item);
                    }

                    foreach (var item in pScopes)
                    {
                        entity.Scopes.Add(item);
                    }

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