Example #1
0
        public async Task <ActionResult> ReNewResume(String IsDevice)
        {
            try
            {
                //get MSISDN from header

                variable.UserPhoneNo = objCheckMsisdnUserStatus.GetHeaderWhileActionRequested(Request);


                //if header Exists

                if (variable.UserPhoneNo != null && !variable.UserPhoneNo.Equals(""))
                {
                    //check status from CheckSubcription table
                    var resultmodel = db.objCheckSubcription.Where(t => t.UserName == variable.UserPhoneNo).Select(t => t).ToList();

                    _IsSubscribedWithRemainingDate.UserPhoneNo = variable.UserPhoneNo;

                    //assign login failed
                    _IsSubscribedWithRemainingDate.LoginResult = ConstantValues.LOGIN_STATUS_FAILED_ID;

                    //if exists
                    if (resultmodel.Count == 1)
                    {
                        //now call api fore genrate soap request and check if user is subscribed
                        //this is renew, a user who is already logged in can renew so this user already logged in

                        if (resultmodel[0].Status == ConstantValues.STATUS_SUBSCRIBE_ID)
                        {
                            //already subscribed so Request Type=renew
                            variable.CheckResult = await SoapManager(variable.UserPhoneNo, ConstantValues.STATUS_Renew_Name);
                        }
                        else
                        {
                            //Unsubscribe status means user re start service again RequestType=Resume  and does not logged in
                            variable.CheckResult = await SoapManager(variable.UserPhoneNo, ConstantValues.STATUS_Resume_Name);
                        }

                        //end call api

                        //if Soap Response Success 1
                        if (variable.CheckResult == ConstantValues.SOAP_RESPONSE_RESULT_SUCCESS_ID)
                        {
                            //for renew user who alredy logged in Satus=1 means Subscribed then add one months with existings
                            if (resultmodel[0].Status == ConstantValues.STATUS_SUBSCRIBE_ID)
                            {
                                resultmodel[0].ExpireDate = resultmodel[0].ExpireDate.AddDays(30);

                                variable.ExpiredDateTime = resultmodel[0].ExpireDate;

                                _IsSubscribedWithRemainingDate.ExpiredRemainingDate = Convert.ToInt32((resultmodel[0].ExpireDate - DateTime.Now).TotalDays);  //+1


                                //check is user already Logged in or not
                                if (Request.IsAuthenticated)
                                {
                                    _IsSubscribedWithRemainingDate.LoginResult = ConstantValues.LOGIN_STATUS_SUCCESS_ID;
                                }
                                else
                                {
                                    //login again
                                    //assign login status failed
                                    variable.InitResult = ConstantValues.InitValue; //1
                                }
                            }

                            //For unsubscribed user who is not logged in, status=2 add one month from current date
                            else if (resultmodel[0].Status == ConstantValues.STATUS_UN_SUBSCRIBE_ID)
                            {
                                resultmodel[0].SubscribeDate = DateTime.Now;
                                resultmodel[0].ExpireDate    = DateTime.Now.AddDays(30);

                                variable.ExpiredDateTime = resultmodel[0].ExpireDate;

                                //change subscribe status from unsubscibed=2 to Subscribed=1
                                resultmodel[0].Status = ConstantValues.STATUS_SUBSCRIBE_ID;

                                //check Expired date and reduced 1 day because DateTime.Now.AddMonths(1) add current day + 30=31

                                _IsSubscribedWithRemainingDate.ExpiredRemainingDate = Convert.ToInt32((resultmodel[0].ExpireDate - DateTime.Now).TotalDays);  //

                                //assign login status failed
                                variable.InitResult = ConstantValues.InitValue; //1
                            }

                            db.SaveChanges();

                            _IsSubscribedWithRemainingDate.StatusID = ConstantValues.STATUS_SUBSCRIBE_ID;



                            //check if remaining days less 30 it access renew if greater renew false
                            if (_IsSubscribedWithRemainingDate.ExpiredRemainingDate < ConstantValues.SUB_DATE_RANGE)
                            {
                                _IsSubscribedWithRemainingDate.Renew = true;
                            }
                            else
                            {
                                _IsSubscribedWithRemainingDate.Renew = false;
                            }

                            //for above case Status is Subscribed and login status failed so we need to log in
                            //now login this user

                            if (variable.InitResult == ConstantValues.InitValue)
                            {
                                //assign login status failed then hit login method

                                LoginViewModel    LogInModel = new LoginViewModel();
                                AccountController ObjAccount = new AccountController();


                                LogInModel.UserName   = resultmodel[0].UserName; //user phone
                                LogInModel.Password   = resultmodel[0].UserName;
                                LogInModel.RememberMe = false;

                                //login for this user and get jason data as string
                                variable.result = ObjAccount.LoginFromInternal(LogInModel, ConstantValues.Device);


                                if (variable.result == ConstantValues.LOGIN_STATUS_SUCCESS_MSG)
                                {
                                    _IsSubscribedWithRemainingDate.LoginResult = ConstantValues.LOGIN_STATUS_SUCCESS_ID;
                                }
                                //no need to assign failed status because it assign before
                            }

                            //end log in
                        }
                    }
                }
                else
                {
                    //header not found
                    _IsSubscribedWithRemainingDate.StatusID = ConstantValues.STATUS_NOT_ROBI_ID;
                }
            }
            catch (Exception mx)
            {
                string a = mx.Message;
            }

            if (IsDevice == ConstantValues.Device)
            {
                return(Json(new { _IsSubscribedWithRemainingDate }, JsonRequestBehavior.AllowGet));
            }

            else
            {
                if (_IsSubscribedWithRemainingDate.StatusID == ConstantValues.STATUS_SUBSCRIBE_ID)
                {
                    ViewBag.Date = variable.ExpiredDateTime;

                    if (_IsSubscribedWithRemainingDate.LoginResult == ConstantValues.LOGIN_STATUS_SUCCESS_ID)
                    {
                        return(View("SubscribeSucess"));
                    }
                    else
                    {
                        return(View("LoginError"));
                    }
                }
                else if (_IsSubscribedWithRemainingDate.StatusID == ConstantValues.STATUS_UN_SUBSCRIBE_ID)
                {
                    return(View("SubscribeUnSucess"));
                }
                else
                {
                    return(View("SubscribeUnSucess"));
                }
            }
        }