public void Given_is_deleted_and_not_have_permissioins_When_IsEditEnabled_Then_returns_false()
        {
            // Given
            var user = new Mock<IPrincipal>();
            user
                .Setup(x => x.IsInRole(Permissions.EditGeneralandHazardousSubstancesRiskAssessments.ToString()))
                .Returns(false);

            var viewmodel = new HazardousSubstanceSummaryViewModel(
                10L,
                55881L,
                "Some Title",
                "Some Reference",
                DateTime.Now.AddDays(-1),
                RiskAssessmentStatus.Draft,
                "Some dangerous substance",
                true,
                false
                );

            // When
            var result = viewmodel.IsEditEnabled(user.Object);

            // Then
            Assert.IsFalse(result);
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Request.IsAjaxRequest()) return;

            var riskAssessmentId = new RiskAssessmentContextFilterHelper(filterContext)
                                                        {
                                                            ActionParamterIdKey = "riskAssessmentId",
                                                            ViewModelPropertyNameKey = "RiskAssessmentId"
                                                        }
                                                        .GetRiskAssessmentId();

            if (riskAssessmentId > 0)
            {
                var user = filterContext.HttpContext.User as CustomPrincipal;
                if (user == null)
                {
                    filterContext.Result = new HttpUnauthorizedResult();
                }

                var riskAssessment = ObjectFactory.GetInstance<IHazardousSubstanceRiskAssessmentService>().GetRiskAssessment(riskAssessmentId, user.CompanyId);

                var summary = new HazardousSubstanceSummaryViewModel(riskAssessment.Id, riskAssessment.CompanyId,
                                                                     riskAssessment.Title, riskAssessment.Reference,
                                                                     riskAssessment.CreatedOn.GetValueOrDefault(),
                                                                     riskAssessment.Status,
                                                                     (riskAssessment.HazardousSubstance != null ? riskAssessment.HazardousSubstance.Name : ""),
                                                                     riskAssessment.Deleted,
                                                                     riskAssessment.Status == RiskAssessmentStatus.Archived
                                                                     );


                dynamic viewBag = filterContext.Controller.ViewBag;
                viewBag.RiskAssessmentSummary = summary;
                if (riskAssessment.Status == RiskAssessmentStatus.Archived)
                {
                    viewBag.IsReadOnly = true;
                }
            }
        }