public void Setup()
        {
            _responsibilitiesService = new Mock<IResponsibilitiesService>();
            _responsibilitiesService.Setup(x => x.CreateResponsibilitiesFromWizard(It.IsAny<CreateResponsibilityFromWizardRequest>()));

            _model = new CreateResponsibilityFromSiteAndResponsibilityTemplateModel
                     {
                         SiteIds = new [] {123L},
                         Responsibilities =  new List<ConfiguredResponsibilityFromTemplate>()
                                             {
                                                 new ConfiguredResponsibilityFromTemplate() { 
                                                     FrequencyId = TaskReoccurringType.SixMonthly,
                                                     ResponsibilityTemplateId = 1234L,
                                                     ResponsiblePersonEmployeeId = Guid.NewGuid()
                                                 },
                                                 new ConfiguredResponsibilityFromTemplate() { 
                                                     FrequencyId = TaskReoccurringType.TwentyFourMonthly,
                                                     ResponsibilityTemplateId = 352334L,
                                                     ResponsiblePersonEmployeeId = Guid.NewGuid()
                                                 }
                                             }
                     };
        }
Пример #2
0
        public JsonResult GenerateResponsibilities(CreateResponsibilityFromSiteAndResponsibilityTemplateModel model)
        {
            ValidateGenerateResponsibilities(model);
            if (!ModelState.IsValid)
            {
                return ModelStateErrorsAsJson();
            }

            var request = new CreateResponsibilityFromWizardRequest
                                {
                                    CompanyId = CurrentUser.CompanyId,
                                    SiteIds = model.SiteIds,
                                    UserId = CurrentUser.UserId,
                                    ResponsibilityFromTemplateDetails = model.Responsibilities
                                        .Select(x => new ResponsibilityFromTemplateDetail()
                                                    {
                                                        ResponsibilityTemplateId = x.ResponsibilityTemplateId,
                                                        FrequencyId = x.FrequencyId,
                                                        ResponsiblePersonEmployeeId = x.ResponsiblePersonEmployeeId.Value
                                                    })
                                        .ToList()
                                };

            _responsibilitiesService.CreateResponsibilitiesFromWizard(request);
            return Json(new { Success = true });
        }
Пример #3
0
        private void ValidateGenerateResponsibilities(CreateResponsibilityFromSiteAndResponsibilityTemplateModel model)
        {
            if (model.SiteIds == null || model.SiteIds.Any() == false)
            {
                ModelState.AddModelError("SiteIds", "Please select the Sites you wish to add Responsibilities to");
            }

            if (model.Responsibilities == null || model.Responsibilities.Any() == false)
            {
                ModelState.AddModelError("Responsibilities", "Please select at least one Responsibility you wish to generate");
            }
            else
            {
                var responsibilityTemplateIdInError = false;
                var frequencyIdInError = false;
                var employeeIdInError = false;
                
                foreach (var resp in model.Responsibilities)
                {
                    if (resp.ResponsibilityTemplateId == default(long) && !responsibilityTemplateIdInError)
                    {
                        ModelState.AddModelError("Responsibilities", "Please select the Responsibility you wish to generate");
                        responsibilityTemplateIdInError = true;
                    }
                    if (resp.FrequencyId == TaskReoccurringType.None && !frequencyIdInError)
                    {
                        ModelState.AddModelError("Responsibilities", "Please select the Monitoring Frequency for each of the selected Responsibilities");
                        frequencyIdInError = true;
                    }
                    if ((resp.ResponsiblePersonEmployeeId == Guid.Empty || resp.ResponsiblePersonEmployeeId == null) && !employeeIdInError)
                    {
                        ModelState.AddModelError("Responsibilities", "Please select a Responsible Person for the selected Responsibilities");
                        employeeIdInError = true;
                    }
                }
            }


        }