public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (_unitOfWork.Accounts.IsValidLogin(model.UserName, model.Password))
                {
                    //FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    var aa = _unitOfWork.Accounts.GetUserProfileByUserName(model.UserName);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    return RedirectToAction("Index", "Home");
                }
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public JsonResult JsonLogin(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {

                if (_unitOfWork.Accounts.IsValidLogin(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    LoadProfile(model.UserName);

                    var role = Roles.GetRolesForUser(model.UserName);

                    if (role.Contains(RoleTypes.Admin))
                    {
                        var urlReferrer = (HttpContext.Request).UrlReferrer;
                        if (urlReferrer != null)
                            returnUrl = string.Format("{0}admin",urlReferrer.AbsoluteUri);
                    }
                    else if (role.Contains(RoleTypes.Buddy))
                    {
                        var urlReferrer = (HttpContext.Request).UrlReferrer;
                        if (urlReferrer != null)
                            returnUrl = string.Format("{0}buddy", urlReferrer.AbsoluteUri);
                    }
                    else //if (role.Contains(RoleTypes.TeamLeader))
                    {
                        var urlReferrer = (HttpContext.Request).UrlReferrer;
                        if (urlReferrer != null)
                            returnUrl = string.Format("{0}bikeplan", urlReferrer.AbsoluteUri);
                    }

                    return Json(new { success = true, redirect = returnUrl });
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }