Exemplo n.º 1
0
        public async Task <IActionResult> Index(string[] file)
        {
            CancellationToken cancellationToken = CancellationToken.None;
            List <string>     message           = new List <string>();

            ModelState.Clear();

            foreach (string account1C in file)
            {
                IndexModel credit = await NBCHRequest.GetDataFrom1CAsync(_Service1C, account1C, _Secret1Cs, "Дальний восток", _Configuration);

                if (!String.IsNullOrEmpty(credit.Account1CCode) && !String.IsNullOrEmpty(credit.Client1CCode))
                {
                    try {
                        PDNInfoList pdnInfoListN = await _ServiceServicePDN.GetSavedPDNAsync(account1C, cancellationToken);

                        if (pdnInfoListN == default)
                        {
                            PDNInfoList pdnInfoList = await _ServiceServicePDN.CalculatePDNAsync(credit.Account1CCode, credit.Account1CDate, credit.Client1CCode, cancellationToken);

                            if (pdnInfoList.ReportDate >= credit.Account1CDate.AddDays(-SOAPNBCH.NBCHAnketaExpiredDay))
                            {
                                await _ServiceServicePDN.SavePDNAsync(pdnInfoList, cancellationToken);

                                message.Add($"Договор {credit.Account1CCode}, данные обновлены");
                            }
                            else
                            {
                                message.Add($"Договор {credit.Account1CCode}, для расчета ПДН, требуется обновить анкету НБКИ");
                            }
                        }
                        ;
                    }
                    catch (FaultException ex) {
                        message.Add($"Договор {credit.Account1CCode}, {ex.Message}");
                    }
                }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(IndexModel model, string submit, ClientPersonalInfo clientPersonalInfo,
                                                string regionWebServiceListName, string[] orgs)
        {
            IndexModel.SubmitType submitType =
                Enum.IsDefined(typeof(IndexModel.SubmitType), submit)
                                                ? (IndexModel.SubmitType)Enum.Parse(typeof(IndexModel.SubmitType), submit)
                                                : IndexModel.SubmitType.Null;

            if (!int.TryParse(Request.Cookies["ClientTimeZone"], out int clientTimeZone))
            {
                submitType         = IndexModel.SubmitType.Null;
                model.ErrorMessage = "Ошибка определения часового пояса на клиентской машине";
            }

            model.ClientPersonalInfo = clientPersonalInfo ?? new ClientPersonalInfo();
            ViewData["RequestCreditHistoryButtonDisabled"] = "style=\"display: none\"";
            ViewData["orgs"] = Organization.OrganizationsByLogin(User.Identity.Name, orgs);

            switch (submitType)
            {
            case IndexModel.SubmitType.Null:
                break;

            case IndexModel.SubmitType.GetFrom1C:
                if ((model.Account1CCode ?? default) == default)
                {
                    break;
                }
                ModelState.Clear();

                try {
                    model = await NBCHRequest.GetDataFrom1CAsync(_Service1C, model.Account1CCode, _Secret1Cs, regionWebServiceListName, _Configuration);

                    ViewData["RequestCreditHistoryButtonDisabled"] = "";
                }
                catch (Exception exception) {
                    _Logger.LogError(
                        exception,
                        "Ошибка получения данных из 1С. Пользователь: {login}, данные запроса: {model}, регион {region}, ошибка: {exceptionMessage}.",
                        HelperASP.Login(User), model, regionWebServiceListName, exception.Message);

                    model.ErrorMessage = exception.InnerException != default
                                                        ? model.ErrorMessage += Environment.NewLine + exception.InnerException.Message
                                                        : exception.Message;
                }
                break;

            case IndexModel.SubmitType.GetCH:
                Report report = new Report();
                model.ClientTimeZone = clientTimeZone;

                try {
                    report = await NBCHRequest.GetCreditHistoryAsync(_ServiceNBCHsoap, model,
                                                                     SecretNBCH.GetSecretNBCH(_Configuration, model.InquiryReq.ConsentReq.reportUser), _Logger);
                }
                catch (EndpointNotFoundException) {
                    report.ErrorMessage = "Не удалось подключиться к службе NBCH (запрос данных из НБКИ).";
                    _Logger.LogError(report.ErrorMessage);
                }
                catch (Exception exception) {
                    report.ErrorMessage = exception.ToString();
                    _Logger.LogError(
                        exception,
                        "Ошибка получения данных из НБКИ. Пользователь: {login}, данные запроса: {model}, ошибка: {exceptionMessage}.",
                        HelperASP.Login(User), model, exception.Message);
                }

                model.AccountReply = report.AccountReply;
                model.Calc         = report.calc;
                model.ErrorMessage = report.ErrorMessage;
                break;

            default:
                break;
            }

            ViewData["ReportDate"] = model?.Calc?.ReportDate ?? default;

            model.RegionsWebServiceListName = Secret1C.GetRegions(_Secret1Cs, regionWebServiceListName);
            Response.Cookies.Append(Startup.WebService1CRegion, regionWebServiceListName);

            return(View(model));
        }