Exemplo n.º 1
0
        public MemberData GetOTPData(string GroupId, string MobileNo)
        {
            MemberData objMemberData = new MemberData();

            try
            {
                CustomerDetail objCustomerDetail = new CustomerDetail();
                OTPMaintenance objOTP            = new OTPMaintenance();
                string         connStr           = objCustRepo.GetCustomerConnString(GroupId);
                using (var contextNew = new BOTSDBContext(connStr))
                {
                    objOTP = contextNew.OTPMaintenances.Where(x => x.MobileNo == MobileNo).OrderByDescending(y => y.Datetime).FirstOrDefault();
                }
                if (objOTP != null)
                {
                    objMemberData.MobileNo   = objOTP.OTP;
                    objMemberData.EnrolledOn = Convert.ToString(objOTP.Datetime);
                    var OutletId = objOTP.CounterId.Substring(0, objOTP.CounterId.Length - 2);
                    using (var contextNew = new BOTSDBContext(connStr))
                    {
                        objMemberData.EnrolledOutletName = contextNew.OutletDetails.Where(x => x.OutletId == OutletId).Select(y => y.OutletName).FirstOrDefault();
                    }
                }
            }
            catch (Exception ex)
            {
                newexception.AddException(ex, GroupId);
            }
            return(objMemberData);
        }
        public JsonResult GenerateOTP(string OutletId)
        {
            bool           status      = false;
            Random         r           = new Random();
            int            randNum     = r.Next(1000);
            string         newOTP      = randNum.ToString("D4");
            var            UserSession = (CustomerDetail)Session["ChitaleUser"];
            OTPMaintenance objOTP      = new OTPMaintenance();

            objOTP.MobileNo  = UserSession.MobileNo;
            objOTP.Datetime  = DateTime.Now;
            objOTP.CounterId = null;
            objOTP.OTP       = newOTP;
            status           = pr.GenerateOTP(objOTP);


            string _Url           = "https://http2.myvfirst.com/smpp/sendsms?";
            string _MobileMessage = "Dear Participant, your OTP for Chitale's redemption request is " + newOTP + " - Chitale Bandhu";

            _MobileMessage = HttpUtility.UrlEncode(_MobileMessage);
            string        type1      = "TEXT";
            StringBuilder sbposdata1 = new StringBuilder();

            sbposdata1.AppendFormat("username={0}", "blueohttpotp");
            sbposdata1.AppendFormat("&password={0}", "bluoct87");
            sbposdata1.AppendFormat("&to={0}", UserSession.MobileNo);
            sbposdata1.AppendFormat("&from={0}", "CHiTLE");
            sbposdata1.AppendFormat("&text={0}", _MobileMessage);
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)3072;
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            HttpWebRequest httpWReq1 = (HttpWebRequest)WebRequest.Create(_Url);
            UTF8Encoding   encoding1 = new UTF8Encoding();

            byte[] data1 = encoding1.GetBytes(sbposdata1.ToString());
            httpWReq1.Method        = "POST";
            httpWReq1.ContentType   = "application/x-www-form-urlencoded";
            httpWReq1.ContentLength = data1.Length;
            using (Stream stream1 = httpWReq1.GetRequestStream())
            {
                stream1.Write(data1, 0, data1.Length);
            }
            HttpWebResponse response1       = (HttpWebResponse)httpWReq1.GetResponse();
            StreamReader    reader1         = new StreamReader(response1.GetResponseStream());
            string          responseString1 = reader1.ReadToEnd();

            reader1.Close();
            response1.Close();
            return(new JsonResult()
            {
                Data = status, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public bool GenerateOTP(OTPMaintenance objOTP)
        {
            bool status = false;

            using (var context = new ChitaleDBContext())
            {
                try
                {
                    context.OTPMaintenances.Add(objOTP);
                    context.SaveChanges();
                    status = true;
                }
                catch (Exception ex)
                {
                    newexception.AddException(ex);
                }
            }

            return(status);
        }