private async Task <GetControlNumberResp> GetControlNumber(IntentOfSinglePay intent) { var result = await new PaymentController(_configuration, _hostingEnvironment, _loggerFactory).CHFRequestControlNumberForSimplePolicy(intent); var result1 = (OkObjectResult)result; var value = (GetControlNumberResp)result1.Value; return(value); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { IntentOfSinglePay intent = (IntentOfSinglePay)validationContext.ObjectInstance; if (intent.OfficerCode == null && value != null && Convert.ToInt32(value) != 0) { return(new ValidationResult(_fieldName + " is not required if Enrolment officer is not provided")); } else { return(ValidationResult.Success); } }
public async Task <DataMessage> CreateSelfRenewal(SelfRenewal renewal) { // Log the request for future reference GenerateRquestFile(renewal); var context = new ImisDB(); var dataMessage = Validate(renewal); // Send SMS for the previously created request if (dataMessage.Code == (int)Errors.Renewal.RenewalAlreadyRequested) { var payment = new ImisPayment(_configuration, _hostingEnvironment, _loggerFactory); var paymentId = GetPaymentId(renewal); if (paymentId > 0) { payment.GetPaymentInfo(Convert.ToInt32(paymentId)); // Replace the phone number by the current recipient payment.PhoneNumber = renewal.Msisdn; SendSMS(payment); } } if (dataMessage.Code != 0) { return(dataMessage); } // All checks passed, continue creating a new policy in tblPolicy var insuree = context.TblInsuree .Where(i => i.Chfid == renewal.InsuranceNumber && i.ValidityTo == null) .Include(i => i.Family).ThenInclude(f => f.TblPolicy).ThenInclude(p => p.Prod).ThenInclude(pr => pr.ConversionProd) .FirstOrDefault(); var insurees = context.TblInsuree .Where(i => i.FamilyId == insuree.FamilyId && i.ValidityTo == null).ToList(); var product = context.TblProduct.Where(prod => prod.ProductCode.ToUpper() == renewal.ProductCode.ToUpper() && prod.ValidityTo == null).FirstOrDefault(); var dtPolicyPeriod = GetPolicyPeriod(product.ProdId, DateTime.Now.Date); var prevPolicy = insuree.Family.TblPolicy.Where(p => p.Prod.ProductCode.ToUpper() == renewal.ProductCode.ToUpper() && p.ValidityTo == null).FirstOrDefault(); var conProd = insuree.Family.TblPolicy.Any(p => p.Prod.ConversionProd != null); TblPolicy convPolicy = null; if (conProd == true) { convPolicy = insuree.Family.TblPolicy.Where(p => p.Prod.ConversionProd.ProductCode.ToUpper() == renewal.ProductCode.ToUpper() && p.ValidityTo == null).FirstOrDefault(); } int officerId = 0; if (prevPolicy != null) { officerId = (int)prevPolicy.OfficerId; } else { officerId = (int)convPolicy.OfficerId; } // Prepare policy var policy = new TblPolicy { FamilyId = insuree.FamilyId, EnrollDate = DateTime.Now, StartDate = (DateTime)dtPolicyPeriod.Rows[0]["StartDate"], ExpiryDate = (DateTime?)dtPolicyPeriod.Rows[0]["ExpiryDate"], PolicyStatus = 1, PolicyValue = product.LumpSum, // for now we are taking lumnpsum but in future we might have to consider other paramters like Grace period, discount preiod etc... ProdId = product.ProdId, OfficerId = officerId, ValidityFrom = DateTime.Now, AuditUserId = -1, IsOffline = false, PolicyStage = "R", SelfRenewed = true }; // Prepare InsureePolicy var insureePolicy = new List <TblInsureePolicy>(); foreach (var ins in insurees) { var insPol = new TblInsureePolicy { InsureeId = ins.InsureeId, PolicyId = policy.PolicyId, EnrollmentDate = policy.EnrollDate, StartDate = policy.StartDate, EffectiveDate = policy.EffectiveDate, ExpiryDate = policy.ExpiryDate, ValidityFrom = DateTime.Now, AuditUserId = -1, IsOffline = false }; insureePolicy.Add(insPol); } policy.TblInsureePolicy = insureePolicy; var controlNumberResponse = new GetControlNumberResp(); // Begin transaction using (var dbContextTransaction = context.Database.BeginTransaction()) { try { context.TblPolicy.Add(policy); context.SaveChanges(); // Request Control Number from the Pool, if we fail to get the control number delete the newly created entry var officer = context.TblOfficer.Where(o => o.OfficerId == policy.OfficerId).FirstOrDefault(); var intent = new IntentOfSinglePay { Msisdn = renewal.Msisdn, request_date = DateTime.Now.Date.ToString(), OfficerCode = officer.Code, InsureeNumber = renewal.InsuranceNumber, ProductCode = renewal.ProductCode, EnrolmentType = ePayment.Models.EnrolmentType.Renewal, language = "en" }; controlNumberResponse = await GetControlNumber(intent); if (!String.IsNullOrEmpty(controlNumberResponse.control_number)) { dbContextTransaction.Commit(); dataMessage.Data = context.TblPolicy.Where(p => p.PolicyId == policy.PolicyId).Select(p => new { p.PolicyId, p.EnrollDate, ControlNumber = controlNumberResponse.control_number }).FirstOrDefault(); } else { dbContextTransaction.Rollback(); dataMessage.Data = controlNumberResponse.error_message; } } catch (Exception) { dbContextTransaction.Rollback(); throw; } } return(dataMessage); }
public virtual async Task <IActionResult> CHFRequestControlNumberForSimplePolicy([FromBody] IntentOfSinglePay intent) { return(await Task.FromResult <IActionResult>(null)); }
public override async Task <IActionResult> CHFRequestControlNumberForSimplePolicy([FromBody] IntentOfSinglePay intent) { if (!ModelState.IsValid) { var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage; return(BadRequest(new { success = false, message = error, error_occured = true, error_message = error })); } intent.phone_number = intent.Msisdn; intent.enrolment_officer_code = intent.OfficerCode; intent.SmsRequired = true; if (String.IsNullOrEmpty(intent.enrolment_officer_code)) { intent.EnrolmentType = EnrolmentType.Renewal + 1; } intent.SetDetails(); var result = await base.GetControlNumber(intent); // Check if the product requested has enough CNs left try { var count = await _payment.ControlNumbersToBeRequested(intent.ProductCode); if (count > 0) { // The following method is Async, but we do not await it since we don't want to wait for the result _ = RequestBulkControlNumbers(new RequestBulkControlNumbersModel { ControlNumberCount = count, ProductCode = intent.ProductCode }); } } catch (Exception e) { _logger.LogError(e, "Error in CHFRequestControlNumberForSimplePolicy"); } return(result); }