public async Task<object> Register(APILoginModel param)
        {
            var api = GoPlayApi.Instance;
            ErrorCodes? error = null;
            string rootUrl = new Uri(Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.PathAndQuery, String.Empty)).AbsoluteUri;

            GtokenAPILoginModel profile = param.profile;
            // Game game = param.game;
            customer_account user = param.user;
            string gtokenSession = profile != null ? profile.session : null;

            var result = api.UpdateProfile(param.profile, param.game.id);
            if (!result.HasData)
            {
                error = result.Error;
            }
            else
            {
                user = result.Data;
                if (!string.IsNullOrEmpty(user.email))
                {
                    var template = new WelcomeMessageTemplate
                    {
                        main_index = rootUrl,
                        logoImg_src = rootUrl + ConstantValues.S_IMAGE_IN_EMAIL_LOGO_GOPLAY,
                        username = user.username,
                        login_link = Url.Link("Default", new { controller = "account", action = "login" }),
                        lastestGame_link = Url.Link("Default", new { controller = "game" }),
                        facebook_link = ConfigurationManager.AppSettings["LINK_TO_FACEBOOK_GO_PLAY"],
                        twitter_link = ConfigurationManager.AppSettings["LINK_TO_TWITTER_GO_PLAY"],
                        KennethImg_src = rootUrl + ConstantValues.S_IMAGE_IN_EMAIL_KENNETH,
                        home_link = rootUrl
                    };
                    await EmailHelper.SendMailWelcome(user.email, template);
                }
            }
            if (param.profile != null && param.game != null)
            {
                param.profile.session = api.GetAccessToken(user.id, param.game.id, param.game.guid, gtokenSession).token;
            }

            return Json(new
            {
                success = error == null,
                session = (error == null && param.profile != null) ? param.profile.session : "",
                profile = (error == null && param.profile != null) ? Profile.GetForm(user) : null
            });
        }
        public async Task<JsonResult> Register(RegisterViewModel model)
        {
            try
            {
                if (!ModelState.IsValid
                    || !String.IsNullOrEmpty(model.submit) && model.submit != "submit")
                {
                    return Json(new { errors = Errors(ModelState) });
                }

                var api = GoPlayApi.Instance;
                string partnerId = ConfigurationManager.AppSettings["GTOKEN_PARTNER_UID"];

                //Calling to Gtoken api to create user and adding friend in Gtoken
                var gtokenResultRegister = await api.GTokenAPIAccount(new GtokenModelAccountAction
                {
                    enumAction = EGtokenAction.Register,
                    username = model.username,
                    pwd = model.password,
                    partnerId = partnerId,
                    email = model.email,
                    referral_code = model.referralID,
                    ip_address = WebIpHelper.GetClientIp(Request).ToString(),
                    country_code = model.countryCode,
                    country_name = model.countryName
                });


                if (!gtokenResultRegister.HasData)
                {
                    ModelState.AddModelError("CustomError", gtokenResultRegister.Error.ToErrorMessage());
                    return Json(new { errors = Errors(ModelState) });
                }

                //store Gtoken session for futher using ( used in edit profile)
                HttpContext.Session["gtoken_section"] = gtokenResultRegister.Data.session;

                //Create user and adding friend
                var user = api.UpdateProfile(gtokenResultRegister.Data).Data;

                CreateLoginOauth();
                var applicationUser = new ApplicationUser()
                {
                    Id = user.id,
                    Email = user.email,
                    UserName = user.username
                };

                await SignInAsync(applicationUser, false);

                //sending mail
                string rootUrl = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, String.Empty);
                var template = new WelcomeMessageTemplate
                {
                    main_index = rootUrl + Url.Action("index", "main"),
                    logoImg_src = rootUrl + ConstantValues.S_IMAGE_IN_EMAIL_LOGO_GOPLAY,
                    username = user.username,
                    login_link = rootUrl + Url.Action("login", "account"),
                    lastestGame_link = rootUrl + Url.Action("index", "game"),
                    facebook_link = ConfigurationManager.AppSettings["LINK_TO_FACEBOOK_GO_PLAY"],
                    twitter_link = ConfigurationManager.AppSettings["LINK_TO_TWITTER_GO_PLAY"],
                    KennethImg_src = rootUrl + ConstantValues.S_IMAGE_IN_EMAIL_KENNETH,
                    home_link = rootUrl
                };
                await EmailHelper.SendMailWelcome(user.email, template);
                //end sending mail
                return Json(new { success = true, redirect = Url.Action("profile", "account") });
            }
            catch
            {
                ModelState.AddModelError("CustomError", Messages.MISSING_FIELDS);
                return Json(new { errors = Errors(ModelState) });
            }
        }