예제 #1
0
 private void UpdateAllAgreementsStatuses()
 {
     using (var context = new CreditAppContext())
     {
         var creditDataEntities = context.CreditData.Where(x => x.Status != "SIGNED" && x.AdobeSignAgreementId != null && x.AdobeSignAgreementId != "").ToList();
         if (creditDataEntities.Any())
         {
             this.RefreshToken(null);
             foreach (var creditDataEntity in creditDataEntities)
             {
                 var response = client.GetAgreement(creditDataEntity.Id, creditDataEntity.AdobeSignAgreementId);
                 repository.AddAdobeSignLog(creditDataEntity.Id, "UpdateAgreementStatus", $"agreementId={creditDataEntity.AdobeSignAgreementId}", response);
                 if (response.status == "CANCELLED")
                 {
                     creditDataEntity.Status               = null;
                     creditDataEntity.SigningUrl           = null;
                     creditDataEntity.AdobeSignAgreementId = null;
                 }
                 else
                 {
                     creditDataEntity.Status = response.status;
                 }
                 context.SaveChanges();
             }
         }
     }
 }
예제 #2
0
        public Task <bool> UpdateCreditApplicationStatus([FromBody] WebHookInfo webHookInfo)
        {
            using (var context = new CreditAppContext())
            {
                var creditDataEntity = context.CreditData.SingleOrDefault(x =>
                                                                          x.AdobeSignAgreementId == webHookInfo.agreement.id);
                if (creditDataEntity != null)
                {
                    creditDataEntity.Status = webHookInfo.Event;

                    context.Update(creditDataEntity);
                    context.SaveChanges();
                }
            }
            //log
            repository.AddAdobeSignLog("UpdateCreditApplicationStatus", $"AgreementId={webHookInfo.agreement.id}", webHookInfo.ToJson());

            return(Task.FromResult(true));
        }
        public IActionResult GetDistributorView(string token)
        {
            string          baseUrl         = repository.GetKeyValue("BMGBaseUrl");// "https://webservice.bevmedia.com/BMGOrderWebService/api";
            ErrorModel      errorModel      = new ErrorModel();
            BevMediaService bevMediaService = new BevMediaService(baseUrl);
            TokenInfo       tokenInfo       = bevMediaService.VerifyToken(token, out var err);

            if (string.IsNullOrWhiteSpace(err))
            {
                DistributorInfo distributor = bevMediaService.GetDistributorInfo(tokenInfo, out var errMsg);
                //RetailerInfo distributor = bevMediaService.GetRetailerInfo(tokenInfo, out var errMsg);
                if (string.IsNullOrWhiteSpace(errMsg))
                {
                    var creditDataList = _context.CreditData
                                         .Where(x => x.DistributorId == tokenInfo.DistributorID)
                                         .Include(files => files.CreditDataFiles)
                                         .ToList();
                    var ws = new AdobeSignWS();
                    foreach (var creditDataEntity in creditDataList)
                    {
                        if (creditDataEntity.Status == CreditAppStatusEnum.OUT_FOR_SIGNATURE.ToString())
                        {
                            var agreement = ws.GetAgreement(creditDataEntity.AdobeSignAgreementId, creditDataEntity.Id.Value);
                            if (agreement.status != creditDataEntity.Status)
                            {
                                creditDataEntity.Status = agreement.status;
                                _context.SaveChanges();
                            }
                        }
                    }
                    var           creditDataListModel = _mapper.Map <List <CreditData> >(creditDataList);
                    List <string> acceptedStatuses    = new List <string> {
                        CreditAppStatusEnum.OUT_FOR_SIGNATURE.ToString(),
                                  CreditAppStatusEnum.SIGNED.ToString(),
                                  CreditAppStatusEnum.APPROVED.ToString(),
                                  CreditAppStatusEnum.DENIED.ToString(),
                    };
                    List <string> editStatuses = new List <string> {
                        CreditAppStatusEnum.SIGNED.ToString(),
                                  CreditAppStatusEnum.APPROVED.ToString(),
                                  CreditAppStatusEnum.DENIED.ToString(),
                    };
                    foreach (var item in creditDataListModel)
                    {
                        if (acceptedStatuses.Contains(item.Status))
                        {
                            item.DistributorStatus = item.Status;
                        }
                        else
                        {
                            item.DistributorStatus = CreditAppStatusEnum.IN_PROGRESS.ToString();
                        }
                        if (editStatuses.Contains(item.Status))
                        {
                            item.CanAddComments = true;
                        }
                    }
                    var distributorViewModel = new DistributorViewModel();
                    distributorViewModel.CreditDataList = creditDataListModel;

                    distributorViewModel.Distributor = new Distributor();
                    distributorViewModel.Distributor.DistributorLogoURL = distributor.DistributorLogoURL;
                    distributorViewModel.Distributor.DistributorName    = distributor.DistributorName;

                    return(View("DistributorView", distributorViewModel));
                }
                else
                {
                    errorModel.Message = errMsg;
                }
            }
            else
            {
                errorModel.Message = err;
            }
            return(View("ErrorView", errorModel));
        }