public async Task <ActionResult> SubscribeUser(mcmsSubscribeUser mcmssubscribeuser, string IsDevice) { try { //Header Check variable.UserPhoneNo = objCheckMsisdnUserStatus.GetHeaderWhileActionRequested(Request); RegisterViewModel RModel = new Models.RegisterViewModel(); //assign login status failed _IsSubscribedWithRemainingDate.LoginResult = ConstantValues.LOGIN_STATUS_FAILED_ID; //if header exists if (variable.UserPhoneNo != null && !variable.UserPhoneNo.Equals("")) { //assign UserName/PhoneNo _IsSubscribedWithRemainingDate.UserPhoneNo = variable.UserPhoneNo; //Check weather user is subcribed or new user.... var resultmodel = db.objCheckSubcription.Where(t => t.UserName == variable.UserPhoneNo).Select(t => t).ToList(); //User is not exists add User Info if (resultmodel.Count == 0) { //for register a new user RModel.UserName = variable.UserPhoneNo; RModel.Password = variable.UserPhoneNo; RModel.ConfirmPassword = variable.UserPhoneNo; //get user id of new user AccountController ObjAccount = new AccountController(); variable.UserId = ObjAccount.RegisterCalled(RModel); // if User Create then add user info in mcms_SubcriptionCheck table if (variable.UserId != null && !variable.UserId.Equals("")) { // SubscribeStatus = true; mcms_SubcriptionCheck aCheck = new mcms_SubcriptionCheck(); aCheck.Id = variable.UserId; aCheck.UserName = RModel.UserName; aCheck.SubscribeDate = DateTime.Now; aCheck.ExpireDate = DateTime.Now.AddDays(30); variable.ExpiredDateTime = aCheck.ExpireDate; aCheck.Status = ConstantValues.STATUS_SUBSCRIBE_INIT_ID;//attempt to Subscribe id= 7 db.objCheckSubcription.Add(aCheck); db.SaveChanges(); //now call api fore genrate soap request variable.CheckResult = await SoapManager(variable.UserPhoneNo, ConstantValues.STATUS_SUBSCRIBE_NAME); //if soap response success 1 if (variable.CheckResult == ConstantValues.SOAP_RESPONSE_RESULT_SUCCESS_ID) //1 { //now update aCheck.Status from INIT_ID to ConstantValues.STATUS_SUBSCRIBE_ID UpdateSubcriptionCheckStatus(ConstantValues.STATUS_SUBSCRIBE_ID, variable.UserPhoneNo); //login status success _IsSubscribedWithRemainingDate.LoginResult = ConstantValues.LOGIN_STATUS_SUCCESS_ID; _IsSubscribedWithRemainingDate.StatusID = ConstantValues.STATUS_SUBSCRIBE_ID; //To do update aCheck.Status=ConstantValues.STATUS_SUBSCRIBE_ID _IsSubscribedWithRemainingDate.ExpiredRemainingDate = Convert.ToInt32((aCheck.ExpireDate - aCheck.SubscribeDate).TotalDays); //check renew true or false //check if ExpiredRemainingDate is less 30 renew true else renew false if (_IsSubscribedWithRemainingDate.ExpiredRemainingDate < ConstantValues.SUB_DATE_RANGE) { _IsSubscribedWithRemainingDate.Renew = true; } else { _IsSubscribedWithRemainingDate.Renew = false; } } else { _IsSubscribedWithRemainingDate.StatusID = ConstantValues.STATUS_UN_SUBSCRIBE_ID; // _IsSubscribedWithRemainingDate.ExpiredRemainingDate = Convert.ToInt32((aCheck.ExpireDate - aCheck.SubscribeDate).TotalDays - 1); } } //new user but user is not create else { //any reson user is not created _IsSubscribedWithRemainingDate.StatusID = ConstantValues.STATUS_UN_SUBSCRIBE_ID; } } } //if user does not found else { _IsSubscribedWithRemainingDate.StatusID = ConstantValues.STATUS_NOT_ROBI_ID;; } } catch (Exception mx) { var a = mx.Message; _IsSubscribedWithRemainingDate.StatusID = ConstantValues.STATUS_EXCEPTION_ID; } // if request come from Device=android return json 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")); } } }
[HttpGet] // in global it is post [HttpPost] public async Task <ActionResult> UnSubscribe(mcmsSubscribeUser mcmssubscribeuser, string msg, string IsDevice) { //get MSISDN from header variable.UserPhoneNo = objCheckMsisdnUserStatus.GetHeaderWhileActionRequested(Request); //if header Exists if (variable.UserPhoneNo != null && !variable.UserPhoneNo.Equals("")) { variable.CheckResult = await SoapManager(variable.UserPhoneNo, ConstantValues.STATUS_UN_SUBSCRIBE_NAME); //work only has a response success- 1 or failed-0 if (variable.CheckResult != ConstantValues.SOAP_RESPONSE_NOT_FOUND_ID) { var resultmodel = db.objCheckSubcription.Where(t => t.UserName == variable.UserPhoneNo).ToList(); if (resultmodel.Count == 1) { if (msg == "1") { resultmodel[0].SelectUnsbStatus = ConstantValues.cause1; } else if (msg == "2") { resultmodel[0].SelectUnsbStatus = ConstantValues.cause2; } else if (msg == "3") { resultmodel[0].SelectUnsbStatus = ConstantValues.cause3; } else { resultmodel[0].SelectUnsbStatus = ConstantValues.cause4; } //check if response result is success then status will unsubscribe else status does not change if (variable.CheckResult == ConstantValues.SOAP_RESPONSE_RESULT_SUCCESS_ID) { resultmodel[0].Status = ConstantValues.STATUS_UN_SUBSCRIBE_ID; //set UnSubscribe Success Id 1 as return variable.UnSubscribedResult = ConstantValues.STATUS_UNSUBSCRIBE_SUCCESS_ID; //1 } else { //set UnSubscribe Success Id 1 as return variable.UnSubscribedResult = ConstantValues.STATUS_UNSUBSCRIBE_FAILED_ID; //2 } db.SaveChanges(); //so check if user is Authenticate then Logged of if (Request.IsAuthenticated) { AccountController objAccount = new AccountController(); variable.result = objAccount.DeviceLogOff(); } } //if User Does not in DB return UnSubscribe Failed else { variable.UnSubscribedResult = ConstantValues.STATUS_UNSUBSCRIBE_FAILED_ID; //2 //return RedirectToAction("UnSubscribeFailed"); } } //Response not Found 2 Unsubscribe else { variable.UnSubscribedResult = ConstantValues.STATUS_UNSUBSCRIBE_FAILED_ID; } } //if header does not Found return Unsubscribe-2 else { variable.UnSubscribedResult = ConstantValues.STATUS_UNSUBSCRIBE_FAILED_ID; } return(Json(new { variable.UnSubscribedResult }, JsonRequestBehavior.AllowGet)); }