Beispiel #1
0
        public async Task <object> GetCbsAccInfo(string mphone, string bankAcNo)
        {
            try
            {
                if (!String.IsNullOrEmpty(mphone) && !String.IsNullOrEmpty(bankAcNo))
                {
                    var customerInfo = _customerSevice.GetCustomerByMphone(mphone);
                    if (customerInfo == null)
                    {
                        CbsApiInfo      apiInfo         = new CbsApiInfo();
                        CbsCustomerInfo cbsCustomerInfo = new CbsCustomerInfo();
                        Reginfo         reginfo         = new Reginfo();
                        dynamic         apiResponse     = null;
                        bool            isMphoneSame    = false;
                        bool            isNidValid      = false;
                        bool            isNidExist      = false;
                        using (var httpClient = new HttpClient())
                        {
                            using (var response = await httpClient.GetAsync(apiInfo.Ip + apiInfo.ApiUrl + bankAcNo))
                            {
                                apiResponse = await response.Content.ReadAsStringAsync();

                                cbsCustomerInfo = JsonConvert.DeserializeObject <CbsCustomerInfo>(apiResponse);
                            }
                        }

                        if (cbsCustomerInfo == null)
                        {
                            return(Ok(new
                            {
                                Status = HttpStatusCode.NotAcceptable,
                                Model = string.Empty,
                                Erros = "No Cbs Account Found"
                            }));
                        }

                        if (cbsCustomerInfo != null)
                        {
                            isMphoneSame = _customerSevice.IsMobilePhoneMatch(mphone, cbsCustomerInfo);
                            reginfo      = _customerSevice.ConvertCbsPullToregInfo(cbsCustomerInfo);
                        }
                        if (!string.IsNullOrEmpty(reginfo.PhotoId))
                        {
                            isNidValid = CheckIsNidIsValid(reginfo.PhotoId);
                            isNidExist = CheckIsNidIsExist(reginfo.PhotoId);
                        }
                        if (!isNidValid)
                        {
                            return(Ok(new
                            {
                                Status = HttpStatusCode.NotAcceptable,
                                Model = string.Empty,
                                Erros = "Invalid Photo Id"
                            }));
                        }
                        if (isNidExist)
                        {
                            return(Ok(new
                            {
                                Status = HttpStatusCode.NotAcceptable,
                                Model = string.Empty,
                                Erros = "Photo Id already exist"
                            }));
                        }
                        if (reginfo.Mphone.Length != 11)
                        {
                            return(Ok(new
                            {
                                Status = HttpStatusCode.NotAcceptable,
                                Model = string.Empty,
                                Erros = "Mobile No Should be 11 digit"
                            }));
                        }
                        if (isMphoneSame)
                        {
                            return(Ok(new
                            {
                                Status = HttpStatusCode.OK,
                                Model = reginfo,
                                Erros = String.Empty
                            }));
                        }
                        else
                        {
                            return(Ok(new
                            {
                                Status = HttpStatusCode.NotAcceptable,
                                Model = string.Empty,
                                Erros = "Mobile No Mismatched"
                            }));
                        }
                    }
                    else
                    {
                        return(Ok(new
                        {
                            Status = HttpStatusCode.NotAcceptable,
                            Model = string.Empty,
                            Erros = "Customer is already Exist"
                        }));
                    }
                }
                else
                {
                    return(Ok(new
                    {
                        Status = HttpStatusCode.NotAcceptable,
                        Model = string.Empty,
                        Erros = "Invalid Input"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Ok(new
                {
                    Status = HttpStatusCode.ExpectationFailed,
                    Model = string.Empty,
                    Erros = ex.Message.ToString()
                }));
            }
        }