Exemple #1
0
 public void OnPostSave([FromBody] Upagent person)
 {
     //do something with the person class
 }
Exemple #2
0
        public async Task <IActionResult> OnPostSaveAgentAsync()
        {
            string merchantid = "";
            var    builder    = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json");
            var    configuration = builder.Build();
            string paendpoint    = configuration["payattititudeendpoint"];
            //
            var random = new Random();
            var tid    = PhoneNumber.Substring(3, 8) + BusinessName.Substring(0, 3).ToUpper() + DateTime.Now.ToString("ddMMyyHHmmss");
            //var normed = Regex.Replace(tid, @"\s+", "");
            var normed = tid.Replace(" ", String.Empty);

            Transactionid = normed;
            double totalamt = 5000.00 * Double.Parse(noofselectedlgas);
            var    am       = totalamt.ToString("0.00");
            //
            Pwpresponse response = new Pwpresponse();
            Pwprequest  payload  = new Pwprequest()
            {
                Description = "UP AGENT REGISTRATION FEE",
                TrxId       = normed,
                Amount      = am,
                Phone       = PhoneNumber
            };
            var despayload = JsonConvert.SerializeObject(payload);

            //ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => {
            //    return true;
            //};
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpClient client = CreateWebRequest();

            var resp = await client.PostAsJsonAsync(paendpoint, payload);

            if (!resp.IsSuccessStatusCode)
            {
                //SuccessResponse response = new SuccessResponse {
                response.status       = null;
                response.amount       = null;
                response.approvalCode = null;
                response.date         = DateTime.Now.ToString();
                response.holder       = null;
                response.id           = null;
                response.paymentRef   = null;
                response.requestId    = null;
                response.existing     = null;
                response.phone        = null;
                response.success      = null;
                response.uan          = null;
                MutantStatus          = "A network error occured, Please try again";
                return(Page());
            }
            else
            {
                var readResult = await resp.Content.ReadAsStringAsync();

                var dresult = (Pwpresponse)JsonConvert.DeserializeObject(readResult, typeof(Pwpresponse));

                response.status       = dresult.status;
                response.amount       = dresult.amount;
                response.approvalCode = dresult.approvalCode;
                response.date         = dresult.date;
                response.holder       = dresult.holder;
                response.id           = dresult.id;
                response.paymentRef   = dresult.paymentRef;
                response.requestId    = dresult.requestId;
                response.existing     = dresult.existing;
                response.phone        = dresult.phone;
                response.success      = dresult.success;
                response.uan          = dresult.uan;

                if (response.success == "true")
                {
                    try
                    {
                        successstatus = response.success;
                        var agent = new Upagent
                        {
                            Phonenumber         = PhoneNumber,
                            Businessname        = BusinessName,
                            Businessphone       = BusinessPhoneNumber,
                            Selectedproprietors = JSONproprietors,
                            Businessemail       = BusinessEmail,
                            Officeaddress       = Address,
                            Officestateid       = Officestateid,
                            Officelgaid         = Officelgaid,
                            Acctypeid           = 2,
                            Rcnumber            = RCNumber,
                            Natureofbusiness    = NatureofBusiness,
                            Noofbusinessyears   = NoofBusinessYears,
                            Deslgaid            = Deslgaid,
                            Turnover            = Turnover,
                            Profitbeforetax     = ProfitBeforeTax,
                            Selectedlgas        = JSONLGAs,
                            invoiceNumber       = normed,
                            PATransactionid     = dresult.paymentRef,
                            PaymentStatus       = "1",
                            Trandate            = DateTime.Now.ToString()
                        };
                        _context.Add(agent);
                        await _context.SaveChangesAsync();

                        return(RedirectToPage("./Success"));
                    }
                    catch (Exception e) { }
                }
                else
                {
                    var agent = new Upagent
                    {
                        Phonenumber         = PhoneNumber,
                        Businessname        = BusinessName,
                        Businessphone       = BusinessPhoneNumber,
                        Selectedproprietors = JSONproprietors,
                        Businessemail       = BusinessEmail,
                        Officeaddress       = Address,
                        Officestateid       = Officestateid,
                        Officelgaid         = Officelgaid,
                        Acctypeid           = 2,
                        Rcnumber            = RCNumber,
                        Natureofbusiness    = NatureofBusiness,
                        Noofbusinessyears   = NoofBusinessYears,
                        Deslgaid            = Deslgaid,
                        Turnover            = Turnover,
                        Profitbeforetax     = ProfitBeforeTax,
                        Selectedlgas        = JSONLGAs,
                        invoiceNumber       = normed,
                        PATransactionid     = dresult.paymentRef,
                        PaymentStatus       = "0",
                        Trandate            = DateTime.Now.ToString(),
                    };
                    _context.Add(agent);
                    await _context.SaveChangesAsync();

                    StateList = _context.State.Select(a =>
                                                      new SelectListItem
                    {
                        Value = a.Id.ToString(),
                        Text  = a.Statename
                    }).ToList();

                    LGAList = _context.Lga.Select(a =>
                                                  new SelectListItem
                    {
                        Value = a.Id.ToString(),
                        Text  = a.Lganame
                    }).ToList();
                    Transactionid = null;
                    MutantStatus  = dresult.status;
                    return(Page());
                }

                StateList = _context.State.Select(a =>
                                                  new SelectListItem
                {
                    Value = a.Id.ToString(),
                    Text  = a.Statename
                }).ToList();

                LGAList = _context.Lga.Select(a =>
                                              new SelectListItem
                {
                    Value = a.Id.ToString(),
                    Text  = a.Lganame
                }).ToList();
                return(Page());
            }
        }