コード例 #1
0
        /// <summary>
        /// #4
        /// GET: /ConditionalApproval/Edit/
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Edit(int id)
        {
            ActionResult redirectToAction;
            var          conditionalApproval = GetConditionalApprovalAndCheckAccess(id, out redirectToAction, extraFetch: true);

            if (conditionalApproval == null)
            {
                return(redirectToAction);
            }

            if (conditionalApproval.Workgroup != null)
            {
                ViewBag.WorkgroupId = conditionalApproval.Workgroup.Id;
                ViewBag.IsWorkgroup = true;
            }
            else
            {
                ViewBag.IsWorkgroup    = false;
                ViewBag.OrganizationId = conditionalApproval.Organization.Id;
            }

            var model = new ConditionalApprovalViewModel
            {
                Id                 = conditionalApproval.Id,
                Question           = conditionalApproval.Question,
                OrgOrWorkgroupName = conditionalApproval.Organization == null ? conditionalApproval.Workgroup.Name : conditionalApproval.Organization.Name,
                PrimaryUserName    = conditionalApproval.PrimaryApprover.FullNameAndId,
                SecondaryUserName  =
                    conditionalApproval.SecondaryApprover == null
                                        ? string.Empty
                                        : conditionalApproval.SecondaryApprover.FullNameAndId
            };

            return(View(model));
        }
コード例 #2
0
        public ActionResult Edit(ConditionalApprovalViewModel conditionalApprovalViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(conditionalApprovalViewModel));
            }

            ActionResult redirectToAction;
            var          conditionalApprovalToEdit = GetConditionalApprovalAndCheckAccess(conditionalApprovalViewModel.Id, out redirectToAction);

            if (conditionalApprovalToEdit == null)
            {
                return(redirectToAction);
            }

            //TODO: for now, only updating of the question is allowed
            conditionalApprovalToEdit.Question = conditionalApprovalViewModel.Question;

            _conditionalApprovalRepository.EnsurePersistent(conditionalApprovalToEdit);

            Message = "Conditional Approval edited successfully";

            if (conditionalApprovalToEdit.Workgroup != null)
            {
                return(this.RedirectToAction(a => a.ByWorkgroup(conditionalApprovalToEdit.Workgroup.Id)));
            }

            if (conditionalApprovalToEdit.Organization != null)
            {
                return(this.RedirectToAction(a => a.ByOrg(conditionalApprovalToEdit.Organization.Id)));
            }

            //return this.RedirectToAction(a => a.Index());
            return(this.RedirectToAction <ErrorController>(a => a.Index()));
        }
コード例 #3
0
        public ActionResult Delete(ConditionalApprovalViewModel conditionalApprovalViewModel)
        {
            ActionResult redirectToAction;
            var          conditionalApproval = GetConditionalApprovalAndCheckAccess(conditionalApprovalViewModel.Id, out redirectToAction);

            if (conditionalApproval == null)
            {
                return(redirectToAction);
            }

            // save the values for redirection
            int?workgroupId = conditionalApproval.Workgroup != null ? (int?)conditionalApproval.Workgroup.Id : null;
            var orgId       = conditionalApproval.Organization != null ? conditionalApproval.Organization.Id : null;

            _conditionalApprovalRepository.Remove(conditionalApproval);

            Message = "Conditional Approval removed successfully";

            if (workgroupId.HasValue)
            {
                return(this.RedirectToAction(a => a.ByWorkgroup(workgroupId.Value)));
            }

            if (!string.IsNullOrWhiteSpace(orgId))
            {
                return(this.RedirectToAction(a => a.ByOrg(orgId)));
            }

            //return this.RedirectToAction(a => a.Index());
            return(this.RedirectToAction <ErrorController>(a => a.Index()));
        }