示例#1
0
        private ActionResult CreatePOST(int cAseId, bool publish = false)
        {
            var cAse = _cAseService.Get(cAseId, VersionOptions.Latest).As <CasePart>();

            if (cAse == null)
            {
                return(HttpNotFound());
            }

            var cAsePost = Services.ContentManager.New <CasePostPart>("CasePost");

            cAsePost.CasePart = cAse;

            if (!Services.Authorizer.Authorize(Permissions.EditCasePost, cAsePost, T("Couldn't create cAse post")))
            {
                return(new HttpUnauthorizedResult());
            }

            Services.ContentManager.Create(cAsePost, VersionOptions.Draft);
            var model = Services.ContentManager.UpdateEditor(cAsePost, this);

            CasePostAttribPart attri = cAsePost.Get <CasePostAttribPart>();
            int id = attri.Id;

            attri.CasePostNumber = cAsePost.ContentItem.Id;
            attri.CaseNumber     = _cAsePostService.GetNextCaseNumber(attri.CaseYear);

            if (cAsePost.Text.Contains("PFR"))
            {
                string[] caseHeader = CommonExtentions.ExtractCaseHeader(cAsePost.Text).ToArray();
                if (caseHeader.Length >= 4)
                {
                    string[] clients = CommonExtentions.GetClients(caseHeader[0].ToString());
                    if (clients.Length >= 2)
                    {
                        attri.CaseClient1 = clients[0].ToString();
                        attri.CaseClient2 = clients[1].ToString();
                    }
                    attri.CaseHeldCourt       = caseHeader[1].ToString();
                    attri.CaseDecisionTakenBy = caseHeader[2].ToString();
                    attri.CaseReference       = caseHeader[3].ToString();
                }
            }


            model = Services.ContentManager.UpdateEditor(cAsePost, this);

            if (!ModelState.IsValid)
            {
                Services.TransactionManager.Cancel();
                return(View(model));
            }

            if (publish)
            {
                if (!Services.Authorizer.Authorize(Permissions.PublishCasePost, cAsePost.ContentItem, T("Couldn't publish cAse post")))
                {
                    return(new HttpUnauthorizedResult());
                }

                Services.ContentManager.Publish(cAsePost.ContentItem);
            }


            Services.Notifier.Information(T("Your {0} has been created.", cAsePost.TypeDefinition.DisplayName));
            return(Redirect(Url.CasePostEdit(cAsePost)));
        }
示例#2
0
        public ActionResult EditPOST(int cAseId, int postId, string returnUrl, Action <ContentItem> conditionallyPublish)
        {
            var cAse = _cAseService.Get(cAseId, VersionOptions.Latest);

            if (cAse == null)
            {
                return(HttpNotFound());
            }

            // Get draft (create a new version if needed)
            var cAsePost = _cAsePostService.Get(postId, VersionOptions.DraftRequired);

            if (cAsePost == null)
            {
                return(HttpNotFound());
            }
            var casat = cAsePost.Get <CasePostAttribPart>();
            CasePostAttribPart attri      = casat.Get <CasePostAttribPart>();
            Boolean            isAcquired = attri.CaseAcquiredBy == 0 ? false : true;

            bool isMe = false;
            //Check isit accuired by me

            int userId = _workContextAccessor.GetContext().CurrentUser.Id;

            isMe = userId == attri.CaseAcquiredBy;

            bool icanEdit = isAcquired && isMe;

            if (!icanEdit)
            {
                if (!Services.Authorizer.Authorize(Permissions.EditCasePost, cAsePost, T("Couldn't edit cAse post")))
                {
                    return(new HttpUnauthorizedResult());
                }
            }

            if (cAsePost.Text.Contains("PFR"))
            {
                string[] caseHeader = CommonExtentions.ExtractCaseHeader(cAsePost.Text).ToArray();
                if (caseHeader.Length > 3)
                {
                    string[] clients = CommonExtentions.GetClients(caseHeader[0].ToString());
                    if (clients.Length > 2)
                    {
                        attri.CaseClient1 = clients[0].ToString();
                        attri.CaseClient2 = clients[1].ToString();
                    }
                    attri.CaseHeldCourt       = caseHeader[1].ToString();
                    attri.CaseDecisionTakenBy = caseHeader[2].ToString();
                    attri.CaseReference       = caseHeader[3].ToString();
                }
            }

            // Validate form input
            var model = Services.ContentManager.UpdateEditor(cAsePost, this);

            if (!ModelState.IsValid)
            {
                Services.TransactionManager.Cancel();
                return(View(model));
            }

            conditionallyPublish(cAsePost.ContentItem);

            Services.Notifier.Information(T("Your {0} has been saved.", cAsePost.TypeDefinition.DisplayName));

            return(this.RedirectLocal(returnUrl, Url.CasePostEdit(cAsePost)));
        }