Esempio n. 1
0
        public IActionResult Get_CommissionsChf([FromBody] ChfGetCommissionInputs model)
        {
            if (!ModelState.IsValid)
            {
                var error = ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage;
                return(BadRequest(new { success = false, message = error }));
            }

            USSDGetCommissionInputs commision = new USSDGetCommissionInputs()
            {
                enrolment_officer_code = model.officer_code,
                insurance_product_code = model.product_code,
                mode  = CommissionMode.Paid,
                year  = model.year,
                month = model.month,
                payer = model.payer
            };

            JsonResult  resp    = (JsonResult)base.Get_Commissions(commision);
            DataMessage message = (DataMessage)resp.Value;

            var commissionString = JsonConvert.SerializeObject(message.Data);
            var commissionAmount = JsonConvert.DeserializeObject <List <CommissionAmount> >(commissionString).FirstOrDefault();

            var response = new GetCommissionResponse(message.Code, false, 0).Message;

            Language language = Language.Secondary;

            if (model.language == 2)
            {
                language = Language.Primary;
            }

            ImisSms sms = new ImisSms(_configuration, _hostingEnvironment, language);

            var txtmsgTemplate = sms.GetMessage("CommissionInformSms");


            var txtmsg = string.Format(txtmsgTemplate,
                                       new DateTime(Convert.ToInt32(model.year), Convert.ToInt32(model.month), 1).ToString("MMMM", CultureInfo.CreateSpecificCulture("en")),
                                       model.year,
                                       commissionAmount.Amount
                                       );


            sms.QuickSms(txtmsg, model.msisdn);

            if (!response.ErrorOccured)
            {
                return(Ok(new { success = true, message = response.MessageValue }));
            }
            else
            {
                return(BadRequest(new { success = false, message = response.MessageValue }));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> GetChf([FromBody] ChfGetCoverageModel model)
        {
            if (new ValidationBase().InsureeNumber(model.insureeNumber) != ValidationResult.Success)
            {
                return(BadRequest(new { success = false, message = "1:Wrong format or missing insurance number of insuree" }));
            }

            JsonResult  resp    = (JsonResult)base.Get(model.insureeNumber);
            DataMessage message = (DataMessage)resp.Value;

            var response = new GetCoverageResponse(message.Code, message.ErrorOccured, model.language).Message;

            if (!message.ErrorOccured)
            {
                var coverage = new ChfCoverage();
                try
                {
                    var covstring = JsonConvert.SerializeObject(message.Data);
                    coverage = JsonConvert.DeserializeObject <ChfCoverage>(covstring);
                }
                catch (Exception)
                {
                    throw;
                }

                Language language = Language.Secondary;

                if (model.language == 2)
                {
                    language = Language.Primary;
                }

                ImisSms sms = new ImisSms(_configuration, _hostingEnvironment, language);

                var txtmsgTemplate = sms.GetMessage("EnquireInformSms");

                var txtmsg = string.Format(txtmsgTemplate,
                                           coverage.OtherNames,
                                           coverage.LastNames,
                                           coverage.BirthDate,
                                           model.insureeNumber,
                                           coverage.CoverageProducts.FirstOrDefault().ProductCode,
                                           coverage.CoverageProducts.FirstOrDefault().Status,
                                           coverage.CoverageProducts.FirstOrDefault().EffectiveDate,
                                           coverage.CoverageProducts.FirstOrDefault().ExpiryDate
                                           );

                for (int i = 1; i > coverage.CoverageProducts.Count; i++)
                {
                    var cov = coverage.CoverageProducts[i];

                    var txt = string.Format(txtmsgTemplate,
                                            string.Empty,
                                            string.Empty,
                                            string.Empty,
                                            string.Empty,
                                            cov.ProductCode,
                                            cov.Status,
                                            cov.EffectiveDate,
                                            cov.ExpiryDate
                                            );

                    txtmsg += ":-" + txtmsg.Split(":-")[1];
                }

                sms.QuickSms(txtmsg, model.msisdn);

                return(Ok(new { success = true, message = response.MessageValue }));
            }
            else
            {
                return(BadRequest(new { success = false, message = response.MessageValue }));
            }
        }