public JsonResult SaveRiskAssessmentReview(AddEditRiskAssessmentReviewViewModel viewModel)
        {
            if (!viewModel.RiskAssessmentReviewId.HasValue)
            {

                return AddRiskAssessmentReview(viewModel);
            }
            else
            {
                return EditRiskAssessmentReview(viewModel);
            }
        }
        public static AddEditRiskAssessmentReviewViewModel CreateFrom(RiskAssessmentReviewDto riskAssessmentReview,
                                                                      IEnumerable<EmployeeDto> employees)
        {
            var viewModel = new AddEditRiskAssessmentReviewViewModel
                                {
                                    CompanyId = riskAssessmentReview.RiskAssessment.CompanyId,
                                    RiskAssessmentId = riskAssessmentReview.RiskAssessment.Id,
                                    ReviewingEmployeeId = riskAssessmentReview.ReviewAssignedTo.Id,
                                    RiskAssessmentReviewId = riskAssessmentReview.Id,
                                    ReviewDate =
                                        riskAssessmentReview.CompletionDueDate.GetValueOrDefault().ToShortDateString(),
                                    RiskAssessmentReviewers = GetReviewersSelectList(employees)
                                };


            return viewModel;
        }
        public static AddEditRiskAssessmentReviewViewModel CreateFrom(RiskAssessmentDto riskAssessment,
                                                                      IEnumerable<EmployeeDto> employees,
                                                                      IRiskAssessmentService riskAssessmentService)
        {
            var reviewDate = riskAssessmentService.GetDefaultDateOfNextReviewById(riskAssessment.Id);

            var viewModel = new AddEditRiskAssessmentReviewViewModel
                                {
                                    CompanyId = riskAssessment.CompanyId,
                                    RiskAssessmentId = riskAssessment.Id,
                                    ReviewingEmployeeId =
                                        riskAssessment.RiskAssessor != null
                                            ? riskAssessment.RiskAssessor.Employee.Id
                                            : Guid.Empty,
                                    ReviewDate = reviewDate.HasValue ? reviewDate.Value.ToString("dd/MM/yyyy") : null,
                                    RiskAssessmentReviewers = GetReviewersSelectList(employees)
                                };

            return viewModel;
        }
        private JsonResult EditRiskAssessmentReview(AddEditRiskAssessmentReviewViewModel viewModel)
        {
            if (!ModelState.IsValid)
                return Json(new { Success = false, Errors = ModelState.GetErrorMessages() });

            using (var session = _businessSafeSessionManager.Session)
            {
                _riskAssessmentReviewService.Edit(new EditRiskAssessmentReviewRequest
                                                      {
                                                          RiskAssessmentReviewId = viewModel.RiskAssessmentReviewId.Value,
                                                          AssigningUserId = CurrentUser.UserId,
                                                          CompanyId = viewModel.CompanyId,
                                                          ReviewDate = DateTime.Parse(viewModel.ReviewDate),
                                                          ReviewingEmployeeId = viewModel.ReviewingEmployeeId
                                                      });

                _businessSafeSessionManager.CloseSession();

                var riskAssessmentReview = _riskAssessmentReviewService.GetByIdAndCompanyId(
                                                                viewModel.RiskAssessmentReviewId.Value,
                                                                CurrentUser.CompanyId
                                                                );

                _bus.Publish(new ReviewAssigned { TaskGuid = riskAssessmentReview.RiskAssessmentReviewTask.TaskGuid });
            }

            return Json(new { Success = true });
        }
        private JsonResult AddRiskAssessmentReview(AddEditRiskAssessmentReviewViewModel viewModel)
        {
            if (!ModelState.IsValid)
                return Json(new { Success = false, Errors = ModelState.GetErrorMessages() });

            var taskGuid = Guid.NewGuid();

            using (var session = _businessSafeSessionManager.Session)
            {
                _riskAssessmentReviewService.Add(new AddRiskAssessmentReviewRequest
                                                     {
                                                         TaskGuid = taskGuid,
                                                         CompanyId = viewModel.CompanyId,
                                                         ReviewDate = DateTime.Parse(viewModel.ReviewDate),
                                                         ReviewingEmployeeId =
                                                             viewModel.ReviewingEmployeeId,
                                                         RiskAssessmentId = viewModel.RiskAssessmentId,
                                                         AssigningUserId = CurrentUser.UserId,
                                                         SendTaskNotification = viewModel.DoNotSendTaskNotification
                                                     });

                _businessSafeSessionManager.CloseSession();
            }

            _bus.Publish(new ReviewAssigned { TaskGuid = taskGuid });
            
            TempData["Notice"] = "Risk Assessment Review Request Successfully Saved";

            return Json(new { Success = true });
        }