Exemplo n.º 1
0
        public async Task <IActionResult> Get(string account1CCode, string client1CCode, int documentId)
        {
            Client client = new Client()
            {
                Code1C = client1CCode
            };

            RegistrarDocument result = default;

            try {
                result = await _ServiceRegistrar.GetDocumentsByAccountAndClients1CAndDocumentIDAsync(
                    HelperASP.Login(User),
                    account1CCode,
                    client,
                    documentId,
                    CancellationToken.None);
            }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Ошибка получения списка файлов. Account1CCode: {account1CCode}, DocumentId {documentId}," +
                    " Пользователь: {login}, Client1CCode: {client1CCode} Ошибка: {exceptionMessage}," +
                    " StackTrace: {StackTrace}",
                    account1CCode, documentId, HelperASP.Login(User), client1CCode, exception.Message,
                    exception.StackTrace);
                return(StatusCode(StatusCodes.Status400BadRequest, exception.Message));
            }
            return(Ok(result));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get(string account, string region)
        {
            ObjectResult checkResult = GetCheckParams(StatusCode, account, region);

            if (checkResult != default)
            {
                return(checkResult);
            }

            (Client[] Clients, string[] Errors)clients;
            try {
                clients = await RegistrarDocuments.GetClientsFrom1CAccountAsync(_Service1C, _Secret1C, region, account);
            }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Ошибка получения списка контрагентов по договору {account1CCode}. Пользователь: {login}." +
                    "	 Ошибка: {exceptionMessage}, StackTrace: {StackTrace}.",
                    account, HelperASP.Login(User), exception.Message, exception.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            if (clients.Errors.Length > 0)
            {
                _Logger.LogError(
                    "Ошибка получения списка контрагентов по договору {account1CCode}. Пользователь: {login}," +
                    " ошибка: {errorMessage}.",
                    account, HelperASP.Login(User), string.Join(". ", clients.Errors));
                return(StatusCode(StatusCodes.Status500InternalServerError, string.Join(". ", clients.Errors)));
            }

            return(Ok(clients.Clients));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Post(string account1CCode, [FromForm] DateTime date, [FromForm] int clientTimeZone,
                                               [FromForm] string message)
        {
            ObjectResult checkResult = PostCheckParams(StatusCode, account1CCode, date, clientTimeZone, message);

            if (checkResult != default)
            {
                return(checkResult);
            }

            Post post = new Post()
            {
                Account1CCode = account1CCode,
                Date          = date,
                Message       = message
            };

            try {
                await _ServicePosts.AddPostAsync(HelperASP.Login(User), account1CCode, post, clientTimeZone, CancellationToken.None);
            }
            catch (Exception exception) {
                _Logger.LogError(exception,
                                 "Ошибка добавления сообщения в договор {account1CCode}. Часовой пояс клиента {clientTimeZone}," +
                                 " сообщение {message}, пользователь {login}, ошибка: {exceptionMessage}.",
                                 account1CCode, clientTimeZone, message, HelperASP.Login(User), exception.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            return(Ok());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Get(string account1CCode, string client1CCode)
        {
            Client client = new Client()
            {
                Code1C = client1CCode
            };

            Dictionary <Client, RegistrarDocument[]> result = default;

            try {
                result = await _ServiceRegistrar.GetDocumentsByAccountAndClients1CAsync(
                    HelperASP.Login(User),
                    account1CCode,
                    new Client[] { client },
                    CancellationToken.None
                    );
            }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Ошибка получения списка документов. Account1CCode: {account1CCode}. Пользователь: {login}," +
                    " Client1CCode: {client1CCode} Ошибка: {exceptionMessage}, StackTrace: {StackTrace}",
                    account1CCode, HelperASP.Login(User), client1CCode, exception.Message, exception.StackTrace);

                return(StatusCode(StatusCodes.Status400BadRequest, exception.Message));
            }
            return(Ok(result[result.Keys.First()]));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Get(string client1CCode, string excludeAccount = default)
        {
            ObjectResult checkResult = GetCheckParams(StatusCode, client1CCode);

            if (checkResult != default)
            {
                return(checkResult);
            }

            UploadedPhoto[] result = default;
            try {
                result = (await _ServiceRegistrar.GetPhotoListAsync(client1CCode, excludeAccount, HelperASP.Login(User), CancellationToken.None)).
                         Select(i => new UploadedPhoto()
                {
                    ID = i.Key, UploadDate = i.Value.ToString()
                }).
                         ToArray();
            }
            catch (Exception exception) {
                _Logger.LogError(
                    "Ошибка получения фотографий клиента с кодом: {client1CCode}, excludeAccount: {excludeAccount}, пользователь {login}, ошибка: {exceptionMessage}.",
                    client1CCode, excludeAccount, HelperASP.Login(User), exception.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            return(Ok(result));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Get(int idFile)
        {
            ObjectResult checkResult = GetCheckParams(StatusCode, idFile);

            if (checkResult != default)
            {
                return(checkResult);
            }

            RegistrarFileData registrarFileData = default;

            try {
                registrarFileData =
                    await _ServiceRegistrar.GetRegistrarFileAsync(HelperASP.Login(User), idFile, CancellationToken.None);
            }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Ошибка получения файла. ID файла: {idFile}. Пользователь: {login}, ошибка: {exceptionMessage}",
                    idFile, HelperASP.Login(User), exception.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            byte[] mas = registrarFileData.Data;
            string fileType;
            string fileName = registrarFileData.FileName;

            switch (Path.GetExtension(registrarFileData.FileName)?.ToUpper())
            {
            case ".PDF":
                fileType = "application/pdf";
                break;

            case ".JPEG":
            case ".JPG":
                fileType = "image/jpeg";
                break;

            case ".GIF":
                fileType = "image/gif";
                break;

            case ".PNG":
                fileType = "image/png";
                break;

            case ".TIF":
                fileType = "image/tiff";
                break;

            default:
                fileType = "application/pdf";
                break;
            }

            return(File(mas, fileType, fileName));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> UploadFiles(IFormFileCollection files, int idFileDescription, string client1CCode, string account1CCode, int clientTimeZone)
        {
            if (clientTimeZone == default)
            {
                return(StatusCode(400, "Не задан часовой пояс клиента"));
            }

            Dictionary <string, byte[]> filesToSend = new Dictionary <string, byte[]>();

            if ((files?.Count ?? 0) > 0)
            {
                foreach (IFormFile file in files)
                {
                    string fileExtension = Path.GetExtension(file.FileName)?.ToUpper();
                    if (
                        fileExtension != ".PDF" &&
                        fileExtension != ".JPEG" &&
                        fileExtension != ".JPG" &&
                        fileExtension != ".GIF" &&
                        fileExtension != ".PNG" &&
                        fileExtension != ".TIF")
                    {
                        return(StatusCode(400, "Допускается загружать файлы только с расширением 'PDF, JPEG, JPG, GIF, PNG, TIF'"));
                    }

                    await using var memoryStream = new MemoryStream();
                    if (file.Length <= 0)
                    {
                        continue;
                    }
                    await file.CopyToAsync(memoryStream);

                    byte[] fileBytes = memoryStream.ToArray();
                    string fileName  = Path.GetFileName(file.FileName);
                    filesToSend.Add(fileName ?? string.Empty, fileBytes);
                }

                if (idFileDescription != default && client1CCode != default && account1CCode != default && filesToSend.Count > 0)
                {
                    try {
                        await _ServiceRegistrar.UploadRegistrarFilesAsync(User.Identity.Name, account1CCode,
                                                                          client1CCode, idFileDescription, filesToSend, clientTimeZone, CancellationToken.None);
                    }
                    catch (Exception exception) {
                        _Logger.LogError(
                            exception,
                            "Не удалось сохранить файл на сервер. Пользователь: {login}, idFileDescription: {idFileDescription}, client1CCode: {client1CCode}," +
                            " account1CCode: {account1CCode}, clientTimeZone: {clientTimeZone}, filesCount {filesCount}, ошибка: {exceptionMessage}",
                            HelperASP.Login(User), idFileDescription, client1CCode, account1CCode, clientTimeZone, files.Count, exception.Message);
                        return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
                    }
                }
            }

            return(Ok());
        }
Exemplo n.º 8
0
 // Task<IEnumerable<string>>
 public async Task <IActionResult> Get()
 {
     try { return(Ok(await _ServicePDN.GetFullRecordOver50PAsync(CancellationToken.None))); }
     catch (Exception exception) {
         _Logger.LogError(
             "Ошибка получения ПДН. Пользователь {login}, ошибка: {exceptionMessage}.",
             HelperASP.Login(User), exception.Message);
         return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Скачать файл из хранилища.
        /// </summary>
        /// <param name="idFile">ID файла</param>
        /// <returns></returns>
        public async Task <FileResult> DownloadFile(int idFile)
        {
            if (idFile != default)
            {
                RegistrarFileData registrarFileData = new RegistrarFileData();
                try {
                    registrarFileData =
                        await _ServiceRegistrar.GetRegistrarFileAsync(User.Identity.Name, idFile, CancellationToken.None);
                }
                catch (Exception exception) {
                    _Logger.LogError(
                        exception,
                        "Не удалось получить файл с сервера. Пользователь: {login}, idFile: {idFile}, ошибка: {exceptionMessage}",
                        HelperASP.Login(User), idFile, exception.Message);
                }

                byte[] mas = registrarFileData.Data;
                string fileType;
                string fileName = registrarFileData.FileName;

                switch (Path.GetExtension(registrarFileData.FileName)?.ToUpper())
                {
                case ".PDF":
                    fileType = "application/pdf";
                    break;

                case ".JPEG":
                case ".JPG":
                    fileType = "image/jpeg";
                    break;

                case ".GIF":
                    fileType = "image/gif";
                    break;

                case ".PNG":
                    fileType = "image/png";
                    break;

                case ".TIF":
                    fileType = "image/tiff";
                    break;

                default:
                    fileType = "application/pdf";
                    break;
                }

                return(File(mas, fileType, fileName));
            }

            return(null);
        }
Exemplo n.º 10
0
        // IEnumerable<string>
        public IActionResult Get()
        {
            try { return(Ok(_Secret1C.Servers.Keys.ToArray())); }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Ошибка получения списка регионов. Пользователь {login}, ошибка: {exceptionMessage}.",
                    HelperASP.Login(User), exception.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            // new[] { "Дальний восток", "Крым" };
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Delete(int idFile)
        {
            if (idFile == default)
            {
                return(StatusCode(400, "Не задан ID файла."));
            }

            try {
                await _ServiceRegistrar.MarkFileAsDeletedAsync(HelperASP.Login(User), idFile, CancellationToken.None);
            }
            catch (Exception ex) {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }

            return(Ok());
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Index(string searchString)
        {
            SearchClientModel searchClientModel = new SearchClientModel {
                SearchString = searchString
            };

            if (!string.IsNullOrEmpty(searchString))
            {
                try { searchClientModel.SearchClientList = await _ServiceNBCH.SearchClientAsync(searchString, CancellationToken.None); }
                catch (Exception exception) {
                    _Logger.LogError(
                        exception,
                        "Не удалось получить список клиентов. Пользователь: {login},  строка поиска: {searchString}, ошибка: {exceptionMessage}, StackTrace: {StackTrace}, exception: {exception}.",
                        HelperASP.Login(User), searchString, exception.Message, exception.StackTrace, exception);
                }
            }

            return(View(searchClientModel));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Удалить файл.
        /// </summary>
        /// <param name="idFile"></param>
        /// <returns></returns>
        public async Task <IActionResult> DeleteFile(int idFile)
        {
            if (idFile == default)
            {
                return(StatusCode(400, "Не задан ID файла"));
            }

            try {
                await _ServiceRegistrar.MarkFileAsDeletedAsync(User.Identity.Name, idFile, CancellationToken.None);
            }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Файл на сервере не удален. Пользователь: {login}, idFile: {idFile}, ошибка: {exceptionMessage}",
                    HelperASP.Login(User), idFile, exception.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            return(Ok());
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Index(string account1CCode, [FromForm] int clientTimeZone)
        {
            try {
                await _InspectingService.SetInspectionAsync(
                    account1CCode,
                    HelperASP.Login(User),
                    DateTime.Now.AddHours(clientTimeZone - ServerTimeZone),
                    clientTimeZone,
                    CancellationToken.None);
            }
            catch (Exception exception) {
                _Logger.LogError(exception,
                                 "Ошибка не удалось привязать проверяющего сотрудника к договору. Договор {account1CCode}," +
                                 " пользователь {login}, ошибка: {exceptionMessage}.",
                                 account1CCode, HelperASP.Login(User), exception.Message);

                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            return(Ok());
        }
Exemplo n.º 15
0
        public async Task <ActionResult> Post([FromBody] string[] accounts)
        {
            ObjectResult checkResult = PostCheckParams(StatusCode, accounts);

            if (checkResult != default)
            {
                return(checkResult);
            }

            PdnResult[] result;

            try { result = await _ServicePDN.GetPDNPercentsAsync(accounts, CancellationToken.None); }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Ошибка получения ПДН по договорам. Договора: {accounts}, пользователь: {login}. ошибка: {exceptionMessage}.",
                    string.Join(',', accounts), HelperASP.Login(User), exception.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            return(Ok(result));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Edit(DateTime reportDate, string account1CCode, PDNCard[] pdnCards,
                                               PDNNonCard[] pdnNonCards, int creditHistoryID, bool pdnAccept)
        {
            pdnCards.AsParallel().ForAll(i => i.Errors    = i.CheckPDNError(reportDate));
            pdnNonCards.AsParallel().ForAll(i => i.Errors = i.CheckPDNError(reportDate));

            PDNInfoList pdnInfoList = new PDNInfoList {
                PDNCards        = pdnCards,
                PDNNonCards     = pdnNonCards,
                Manual          = true,
                Account1CID     = account1CCode,
                ReportDate      = reportDate,
                CreditHistoryID = creditHistoryID,
                PDNAccept       = pdnAccept
            };

            try { await _ServiceServicePDN.SavePDNAsync(pdnInfoList, CancellationToken.None); }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Не удалось сохранить данные ПДН. Пользователь: {login},  данные: {pdnInfoList}, ошибка: {exceptionMessage}",
                    HelperASP.Login(User), pdnInfoList, exception.Message);
            }


            PDNEditEdit pdnEditIndex = new PDNEditEdit {
                Account1CCode = account1CCode,
                ReportDate    = reportDate
            };

            if (pdnAccept)
            {
                return(RedirectToAction("Index"));
            }

            return(View(pdnEditIndex));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Get(string account1CCode)
        {
            ObjectResult checkResult = GetCheckParams(StatusCode, account1CCode);

            if (checkResult != default)
            {
                return(checkResult);
            }

            Post[] posts;

            try {
                posts = await _ServicePosts.GetPostsAsync(HelperASP.Login(User), account1CCode, CancellationToken.None);
            }
            catch (Exception exception) {
                _Logger.LogError(
                    exception,
                    "Ошибка получения списка сообщений по договору: {account1CCode}. Пользователь: {login}, ошибка: {exceptionMessage}.",
                    account1CCode, HelperASP.Login(User), exception.Message);
                return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
            }

            return(Ok(posts));
        }
Exemplo n.º 18
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));
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Post([FromForm] IFormFileCollection files, [FromForm] int idFileDescription,
                                               [FromForm] string client1CCode, [FromForm] string account1CCode, [FromForm] int clientTimeZone)
        {
            ObjectResult checkResult = PostCheckParams(StatusCode, files, idFileDescription, client1CCode,
                                                       account1CCode, clientTimeZone);

            if (checkResult != default)
            {
                return(checkResult);
            }

            Dictionary <string, byte[]> filesToSend = new Dictionary <string, byte[]>();

            if (files.Count > 0)
            {
                foreach (IFormFile file in files)
                {
                    string fileExtension = Path.GetExtension(file.FileName)?.ToUpper();
                    if (
                        fileExtension != ".PDF" &&
                        fileExtension != ".JPEG" &&
                        fileExtension != ".JPG" &&
                        fileExtension != ".GIF" &&
                        fileExtension != ".PNG" &&
                        fileExtension != ".TIF")
                    {
                        return(StatusCode(StatusCodes.Status400BadRequest, "Допускается загружать файлы только с расширением 'PDF, JPEG, JPG, GIF, PNG, TIF.'"));
                    }

                    await using (var memoryStream = new MemoryStream()) {
                        if (file.Length <= 0)
                        {
                            continue;
                        }

                        await file.CopyToAsync(memoryStream);

                        byte[] fileBytes = memoryStream.ToArray();
                        string fileName  = Path.GetFileName(file.FileName);
                        filesToSend.Add(fileName ?? string.Empty, fileBytes);
                    }
                }

                try {
                    await _ServiceRegistrar.UploadRegistrarFilesAsync(
                        HelperASP.Login(User),
                        account1CCode,
                        client1CCode,
                        idFileDescription,
                        filesToSend,
                        clientTimeZone,
                        CancellationToken.None
                        );
                }
                catch (Exception exception) {
                    _Logger.LogError(
                        exception,
                        "Не удалось сохранить файлы на сервер. Пользователь: {login}," +
                        " Account1CCode: {account1CCode}, Client1CCode: {client1CCode}," +
                        " IdFileDescription: {idFileDescription} , Кол-во файлов {FilesCount}," +
                        " Часовой пояс: {clientTimeZone}, Ошибка: {exceptionMessage}",
                        HelperASP.Login(User), account1CCode, client1CCode, idFileDescription,
                        filesToSend.Count, clientTimeZone, exception.Message);
                    return(StatusCode(StatusCodes.Status500InternalServerError, exception.Message));
                }
            }

            return(Ok());
        }