public async Task<JsonResult> Register(RegisterViewModel model)
        {
            try
            {
                if (Request.IsAuthenticated && CurrentUser != null && CurrentUser.Id > 0)
                {
                    return Json(new { success = true, redirect = Url.Action("profile", "account") });
                }

                model.email = model.email.Split('@')[0] + "@" + model.email.Split('@')[1].ToLower();

                if (ModelState.IsValid)
                {
                    if (!String.IsNullOrEmpty(model.submit) && model.submit == "submit")
                    {
                        var api = GoEatApi.Instance;
                        string ip = Request.UserHostAddress == null || Request.UserHostAddress == "::1"
                            ? IPAdressExtension.GetDefaultIp()
                            : Request.UserHostAddress;

                        var result = await api.Register(model.username, model.password, String.Empty,
                            model.email, String.Empty, Genders.Male.ToString(), model.referralID, ip);

                        if (!result.Succeeded || !result.HasData)
                        {
                            switch (result.Error)
                            {
                                case ErrorCodes.UserNameOrEmailExist:
                                    ModelState.AddModelError("username", Messages.USERNAME_OR_EMAIL_EXIST);
                                    break;
                                case ErrorCodes.InvalidReferrerId:
                                    ModelState.AddModelError("referralID", Messages.REFERAL_CODE_ERROR);
                                    break;
                                case ErrorCodes.MissingFields:
                                default:
                                    ModelState.AddModelError("CustomError", Messages.MISSING_FIELDS);
                                    break;
                            }
                        }
                        else
                        {

                            //Login User
                            var applicationUser = new ApplicationUser
                            {
                                Id = result.Data.profile.uid,
                                Email = result.Data.profile.email,
                                UserName = result.Data.profile.account
                            };

                            await SignInAsync(applicationUser, false);

                            return Json(new { success = true, redirect = Url.Action("profile", "account") });
                        }
                    }
                }

                //Something failed, display errors
                // Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return Json(new { errors = Errors(ModelState) });
            }
            catch
            {
                ModelState.AddModelError("CustomError", Messages.MISSING_FIELDS);
                return Json(new { errors = Errors(ModelState) });
            }
        }
        public ActionResult Register(string referralName = null)
        {
            if (Request.IsAuthenticated && CurrentUser != null && CurrentUser.Id > 0)
            {
                return RedirectToAction("profile", "account");
            }

            var model = new RegisterViewModel
            {
                referralID = referralName

            };
            return View(model);
        }