public ActionResult <ResponseContext> GetFileUploadsById(string CustomerId)
 {
     try
     {
         if ((bool)HttpContext.Items["isLoggedInOtherDevice"])
         {
             return(Ok(new ResponseContext
             {
                 code = (int)Common.ResponseCode.IS_LOGGED_IN_ORTHER_DEVICE,
                 message = Common.Message.IS_LOGGED_IN_ORTHER_DEVICE,
                 data = null
             }));
         }
         var lstFileUpload = new List <FileUpload>();
         lstFileUpload = _fileUploadServices.GetListFileUploadByCustomerId(CustomerId);
         return(Ok(new ResponseContext
         {
             code = (int)Common.ResponseCode.SUCCESS,
             message = Common.Message.SUCCESS,
             data = lstFileUpload
         }));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         _logger.LogError(ex, ex.Message);
         return(StatusCode(StatusCodes.Status500InternalServerError, new ResponseMessage
         {
             status = "ERROR",
             message = ex.Message
         }));
     }
 }
Esempio n. 2
0
        public int PushDataToMC()
        {
            try
            {
                var lstMCProcessing = _dataMCProcessingServices.GetDataMCProcessings(Common.DataCRMProcessingStatus.InProgress);
                var token           = GetMCToken();//"ca5d2357-90be-4bd9-b9d9-732c690dd9c3";//GetMCToken();
                int uploadCount     = 0;
                if (lstMCProcessing.Count > 0 && !string.IsNullOrEmpty(token))
                {
                    foreach (var item in lstMCProcessing)
                    {
                        var objCustomer   = _customerServices.GetCustomer(item.CustomerId);
                        var lstFileUpload = _fileUploadServices.GetListFileUploadByCustomerId(item.CustomerId);
                        lstFileUpload = lstFileUpload.Where(l => !string.IsNullOrEmpty(l.DocumentCode)).ToList();
                        var fileZipInfo = ZipFiles(lstFileUpload, objCustomer.Id);
                        var filePath    = fileZipInfo[0];
                        var hash        = fileZipInfo[1];
                        var dataMC      = new DataMC();
                        dataMC.AppStatus                = "1";
                        dataMC.Request                  = new Models.MC.Request();
                        dataMC.Request.CitizenId        = objCustomer.Personal.IdCard;
                        dataMC.Request.CustomerName     = objCustomer.Personal.Name;
                        dataMC.Request.ProductId        = objCustomer.Loan.Product;
                        dataMC.Request.SaleCode         = objCustomer.UserName;
                        dataMC.Request.CompanyTaxNumber = objCustomer.Working.TaxId;
                        dataMC.Request.ShopCode         = objCustomer.SaleInfo.Code;
                        dataMC.Request.LoanAmount       = objCustomer.Loan.Amount;
                        dataMC.Request.LoanTenor        = objCustomer.Loan.Term;
                        dataMC.Request.HasInsurance     = objCustomer.Loan.BuyInsurance;
                        dataMC.Md5  = hash;
                        dataMC.Info = new List <Info>();

                        foreach (var f in lstFileUpload)
                        {
                            var dataMCFileInfo = new Info();
                            dataMCFileInfo.DocumentCode = f.DocumentCode;
                            dataMCFileInfo.FileName     = f.FileUploadName;
                            dataMCFileInfo.MimeType     = "jpg";
                            dataMCFileInfo.GroupId      = f.GroupId;
                            dataMC.Info.Add(dataMCFileInfo);
                        }
                        var client = new RestClient(Url.MC_BASE_URL + Url.MC_UPLOAD_DOCUMENT);
                        client.Timeout = -1;
                        var request = new RestRequest(Method.POST);
                        request.AddHeader("Authorization", "Bearer " + token + "");
                        request.AddHeader("x-security", "MEKONG-CREDIT-57d733a9-bcb5-4bff-aca1-f58163122fae");
                        request.AddHeader("Content-Type", "multipart/form-data");
                        request.AddFile("file", "" + filePath + "");
                        request.AddParameter("object", JsonConvert.SerializeObject(dataMC));
                        IRestResponse response = client.Execute(request);
                        _logger.LogInformation(response.Content);
                        if (!string.IsNullOrEmpty(response.Content))
                        {
                            uploadCount++;
                        }
                        File.Delete(filePath);
                        _dataMCProcessingServices.UpdateByCustomerId(item.CustomerId, Common.DataCRMProcessingStatus.Done);
                    }
                }
                return(uploadCount);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(-1);
            }
        }