Exemple #1
0
        public void TestAppealController()
        {
            AppealViewModel model = new AppealViewModel();

            model.AppealCurrent = _context.Appeals.Local.Select(x => new McpdAppeal
            {
                Cin                             = x.Cin,
                BenefitType                     = x.BenefitType,
                DataSource                      = x.DataSource,
                ErrorMessage                    = x.ErrorMessage,
                AppealId                        = x.AppealId,
                AppealReceivedDate              = x.AppealReceivedDate,
                AppealResolutionDate            = x.AppealResolutionDate,
                AppealResolutionStatusIndicator = x.AppealResolutionStatusIndicator,
                AppealType                      = x.AppealType,
                ExpeditedIndicator              = x.ExpeditedIndicator,
                McpdAppealId                    = x.McpdAppealId,
                NoticeOfActionDate              = x.NoticeOfActionDate,
                ParentAppealId                  = x.ParentAppealId,
                PartiallyOverturnIndicator      = x.PartiallyOverturnIndicator,
                McpdHeaderId                    = x.McpdHeaderId,
                ParentGrievanceId               = x.ParentGrievanceId,
                PlanCode                        = x.PlanCode,
                RecordType                      = x.RecordType,
                TradingPartnerCode              = x.TradingPartnerCode
            }).ToList();
            model.AppealHistory = new List <McpdAppeal>();
            model.AppealError   = new List <McpdAppeal>();
            var result = _appealController.Index(991, model);

            Assert.IsTrue(result.IsCompleted);
        }
        public async Task <AppealViewModel> GetAppealViewModel(AppealRequest request, string message)
        {
            var oversightReviewTask = _applyApiClient.GetOversightReview(request.ApplicationId);
            var stagedUploadsTask   = _applyApiClient.GetStagedUploads(new GetStagedFilesRequest {
                ApplicationId = request.ApplicationId
            });
            await Task.WhenAll(oversightReviewTask, stagedUploadsTask);

            var oversightReview = _applyApiClient.GetOversightReview(request.ApplicationId).Result;
            var stagedUploads   = _applyApiClient.GetStagedUploads(new GetStagedFilesRequest {
                ApplicationId = request.ApplicationId
            }).Result;

            var result = new AppealViewModel
            {
                ApplicationId          = request.ApplicationId,
                OversightReviewId      = oversightReview.Id,
                AllowAdditionalUploads = stagedUploads.Files.Count < MaxFileUploads,
                UploadedFiles          = stagedUploads.Files.Select(x => new UploadedFileViewModel {
                    Id = x.Id, Filename = x.Filename
                }).ToList(),
                Message = message
            };

            return(result);
        }
        public async Task <IActionResult> Save(AppealViewModel model)   // Сохранение обращения
        {
            if (model == null)
            {
                return(BadRequest());
            }

            var appeal = (model.Id > 0) ? await service.Get(model.Id) : new Appeal();

            // Если в БД обращения с таким идентификатором уже нет
            if (model.Id > 0 && appeal == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(nameof(Edit), model));
            }

            try
            {
                // Если происходит создание новой записи
                if (model.Id == 0)
                {
                    appeal.CopyProperties(model);
                    appeal.Phone     = model.Phone.AsPhone(PhoneNumberFormat.E164);
                    appeal.CreatedAt = DateTime.Now;
                    appeal           = await service.Insert(appeal);
                }
                else
                {
                    // Редактировать разрешено только сообщение
                    appeal.Message = model.Message;
                }

                await service.Save();  // тут в appeal.Id записывается новый идентификатор

                if (appeal.Id == 0)
                {
                    return(BadRequest());
                }

                return(RedirectToAction(nameof(Page), new { appealId = appeal.Id }));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
        public IActionResult Cancel(AppealViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (model.Page > 0)
            {
                return(RedirectToAction(nameof(Index), new { page = model.Page }));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemple #5
0
        public async Task Post_Appeal_redirects_to_confirmation()
        {
            var viewModel = new AppealViewModel()
            {
                ApplicationSummary = new ApplicationSummaryViewModel {
                    ApplicationId = _applicationDetailsApplicationId
                }
            };

            _oversightOrchestrator.Setup(x => x.GetAppealDetailsViewModel(_applicationDetailsApplicationId, null)).ReturnsAsync(viewModel);

            var command = new AppealPostRequest()
            {
                ApplicationId    = _applicationDetailsApplicationId,
                AppealStatus     = AppealStatus.Unsuccessful,
                UnsuccessfulText = "test"
            };

            var result = await _controller.Appeal(command) as RedirectToActionResult;

            Assert.AreEqual("ConfirmAppealOutcome", result.ActionName);
        }
Exemple #6
0
        public async Task GetAppealOutcome_returns_view_with_expected_viewModel()
        {
            var viewModel = new AppealViewModel {
                ApplicationSummary = new ApplicationSummaryViewModel {
                    ApplicationId = _applicationDetailsApplicationId
                }
            };

            _oversightOrchestrator.Setup(x => x.GetAppealDetailsViewModel(_applicationDetailsApplicationId, null)).ReturnsAsync(viewModel);

            var request = new AppealRequest()
            {
                ApplicationId = _applicationDetailsApplicationId
            };
            var result = await _controller.AppealOutcome(request) as ViewResult;

            var actualViewModel = result?.Model as AppealViewModel;

            Assert.That(result, Is.Not.Null);
            Assert.That(actualViewModel, Is.Not.Null);
            Assert.That(actualViewModel, Is.SameAs(viewModel));
            Assert.AreEqual(_applicationDetailsApplicationId, actualViewModel.ApplicationSummary.ApplicationId);
        }
        public async Task <IActionResult> Edit(int id, int page)  // Редактирование обращения
        {
            if (id <= 0)
            {
                return(BadRequest());
            }

            var appeal = await service.Get(id);

            if (appeal == null)
            {
                return(NotFound());
            }

            var viewModel = new AppealViewModel {
                IsEditing = true, Page = page
            };

            viewModel.CopyProperties(appeal);
            viewModel.Phone = appeal.Phone.AsPhone(PhoneNumberFormat.NATIONAL);

            return(View(nameof(Edit), viewModel));
        }
        public async Task <IActionResult> Delete(AppealViewModel model)   // Удаление сообщения
        {
            if (model == null || model.Id == 0)
            {
                return(BadRequest());
            }
            try
            {
                var result = await service.Delete(model.Id);

                if (!result)
                {
                    return(NotFound());
                }

                await service.Save();

                return(RedirectToAction(nameof(Index), new { page = model.Page }));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Exemple #9
0
        public async Task <IActionResult> Index(Guid appealId, int?key, string secretKey)
        {
            // Get chat session from database
            var chatSession = await chatRepository.GetChatSession(appealId);

            // Check if chat session is null
            if (chatSession == null)
            {
                return(NotFound("Сессии по данному идентификатору апеллянта не существует"));
            }

            // Set varable: current date less than start time of chat
            var isBefore = DateTime.Now < chatSession.StartTime;

            //
            var isAfter = DateTime.Now > chatSession.FinishTime;

            // Get member replacement from database
            var replacement = await chatRepository.GetReplacement(appealId);

            //
            var sessionModel = new SessionViewModel
            {
                AppealId   = appealId,
                Session    = chatSession,
                IsAfter    = isAfter,
                IsBefore   = isBefore,
                IsActive   = !isBefore && !isAfter && !chatSession.IsEarlyCompleted,
                IsReplaced = replacement?.OldMember != null
            };

            // Check if current date less than start time of chat
            if (isBefore)
            {
                return(View("Before", sessionModel));
            }

            //
            var clientType = key > 0 ? ContextType.Expert : ContextType.Appeal;

            //
            if (clientType == ContextType.Expert)
            {
                if (replacement?.OldMember == null)
                {
                    // Before expert replacement
                    if (chatSession.CurrentExpertKey == null)
                    {
                        chatSession.CurrentExpertKey = key;

                        if (!await chatRepository.UpdateSession(chatSession))
                        {
                            return(BadRequest("Не удалось обновить запись таблицы"));
                        }
                    }
                }
                else if (replacement.OldMember != key && replacement.ReplaceTime == null)
                {
                    // During expert replacement
                    if (replacement.NewMember == null)
                    {
                        replacement.NewMember = key;
                    }

                    //
                    replacement.ReplaceTime = DateTime.Now;

                    // Update member replacement
                    if (!await chatRepository.UpdateReplacement(replacement))
                    {
                        return(BadRequest("Не удалось обновить запись таблицы"));
                    }

                    //
                    var waitingTime = replacement.ReplaceTime.Value.Subtract(replacement.RequestTime.Value);

                    //
                    chatSession.FinishTime = chatSession.FinishTime.Add(waitingTime);

                    //
                    chatSession.CurrentExpertKey = key;

                    // Update session
                    if (!await chatRepository.UpdateSession(chatSession))
                    {
                        return(BadRequest("Не удалось обновить запись таблицы"));
                    }

                    //
                    await chatContext.Clients.User(appealId.ToString()).CompleteChange(key);
                }

                //
                if (key != chatSession.CurrentExpertKey)
                {
                    sessionModel.IsActive = false;
                }

                //
                var expertModel = new ExpertViewModel
                {
                    SessionModel = sessionModel,
                    ExpertKey    = key,
                    Messages     = await chatRepository.GetChatMessages(appealId),
                    QuickReplies = await chatRepository.GetQuickReplies()
                };

                //
                return(View("Expert", expertModel));
            }
            else if (clientType == ContextType.Appeal)
            {
                // Check if current date more than chat finish time or chat has been early completed
                if (isAfter || chatSession.IsEarlyCompleted)
                {
                    return(View("After", sessionModel));
                }

                //
                var isWaiting = replacement?.OldMember != null && replacement?.NewMember == null;

                //
                var appealModel = new AppealViewModel
                {
                    SessionModel = sessionModel,
                    Messages     = await chatRepository.GetChatMessages(appealId),
                    IsWaiting    = isWaiting
                };

                //
                return(View("Appeal", appealModel));
            }

            return(BadRequest());
        }
Exemple #10
0
        public async Task <AppealViewModel> GetAppealDetailsViewModel(Guid applicationId, Guid?outcomeKey)
        {
            var applicationDetailsTask = _applyApiClient.GetApplicationDetails(applicationId);
            var oversightReviewTask    = _applyApiClient.GetOversightReview(applicationId);
            await Task.WhenAll(applicationDetailsTask, oversightReviewTask);

            var applicationDetails = _applyApiClient.GetApplicationDetails(applicationId).Result;
            var oversightReview    = _applyApiClient.GetOversightReview(applicationId).Result;
            var onRegister         = false;
            var appealDetails      = await _applyApiClient.GetAppealDetails(applicationId);

            if (applicationDetails?.Ukprn != null)
            {
                var registerStatus = await _registerApiClient.GetOrganisationRegisterStatus(new GetOrganisationRegisterStatusRequest { UKPRN = applicationDetails.Ukprn });

                onRegister = registerStatus.UkprnOnRegister;
            }

            var viewModel = new AppealViewModel
            {
                IsNew = oversightReview == null,
                ApplicationSummary     = CreateApplicationSummaryViewModel(applicationDetails),
                GatewayOutcome         = CreateGatewayOutcomeViewModel(applicationDetails, oversightReview),
                FinancialHealthOutcome = CreateFinancialHealthOutcomeViewModel(applicationDetails),
                ModerationOutcome      = CreateModerationOutcomeViewModel(applicationDetails, oversightReview),
                InProgressDetails      = CreateInProgressDetailsViewModel(oversightReview),
                OverallOutcome         = CreateOverallOutcomeViewModel(oversightReview),
                ShowInProgressDetails  = oversightReview?.InProgressDate != null,
                OversightStatus        = oversightReview?.Status ?? OversightReviewStatus.None,
                ApproveGateway         = GetStringValueForApprovalStatusBoolean(oversightReview?.GatewayApproved),
                ApproveModeration      = GetStringValueForApprovalStatusBoolean(oversightReview?.ModerationApproved),
                IsGatewayRemoved       = applicationDetails.ApplicationStatus == ApplicationStatus.Removed,
                IsGatewayFail          = applicationDetails.GatewayReviewStatus == GatewayReviewStatus.Fail,
                HasFinalOutcome        = oversightReview != null && oversightReview.Status != OversightReviewStatus.None && oversightReview.Status != OversightReviewStatus.InProgress,
                OnRegister             = onRegister,
                Appeal       = appealDetails,
                AppealStatus = appealDetails.Status
            };

            if (oversightReview == null || oversightReview.Status == OversightReviewStatus.InProgress)
            {
                var cachedItem = await _cacheStorageService.RetrieveFromCache <OutcomePostRequest>(outcomeKey.ToString());

                if (cachedItem == null)
                {
                    return(viewModel);
                }

                viewModel.OversightStatus                 = cachedItem.OversightStatus;
                viewModel.ApproveGateway                  = cachedItem.ApproveGateway;
                viewModel.ApproveModeration               = cachedItem.ApproveModeration;
                viewModel.SuccessfulText                  = cachedItem.SuccessfulText;
                viewModel.SuccessfulAlreadyActiveText     = cachedItem.SuccessfulAlreadyActiveText;
                viewModel.SuccessfulFitnessForFundingText = cachedItem.SuccessfulFitnessForFundingText;
                viewModel.UnsuccessfulText                = cachedItem.UnsuccessfulText;
                viewModel.UnsuccessfulExternalText        = cachedItem.UnsuccessfulExternalText;
                viewModel.InProgressInternalText          = cachedItem.InProgressInternalText;
                viewModel.InProgressExternalText          = cachedItem.InProgressExternalText;
            }

            return(viewModel);
        }