public async Task <IActionResult> LoginAsync(RestaurantLoginModelView authView)
 {
     TempData["RestaurantName"] = null;
     if (authView.Type == 0)
     {
         var user = UsersManager.Authenticate(authView.Username, authView.Password);
         if (user == null)
         {
             TempData["Message"]      = null;
             TempData["ErrorMessage"] = "Login Error!!!.Try Again. Don't forget to Register first!!";
             return(RedirectToAction("Login", "Account"));
         }
         var custId = CustomersManager.GetCustomerIdByUserId(user.UserId);
         var empId  = EmployeesManager.GetEmployeeIdByUserId(user.UserId);
         var ownId  = OwnersManager.GetOwnerIdByUserId(user.UserId);
         var claims = new List <Claim>()
         {
             new Claim(ClaimTypes.Name, user.Authentication.Username),
             new Claim("FullName", $"{user.FirstName} {user.LastName}"),
             new Claim("AuthID", user.AuthenticationId.ToString()),
             new Claim("UserID", user.UserId.ToString()),
             new Claim("CustomerID", custId.ToString()),
             new Claim("EmployeeID", empId.ToString()),
             new Claim("OwnerID", ownId.ToString()),
         };
         var claimsIdentity = new ClaimsIdentity(claims, "Cookies");
         await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(claimsIdentity));
     }
     else
     {
         var user = RestaurantsManager.AuthenticateRestaurant(authView.Username, authView.Password, authView.RestaurantId);
         if (user.UserId <= 0)
         {
             TempData["Message"]      = null;
             TempData["ErrorMessage"] = "Login Error!!!.Try Again.Don't forget to Register first!!";
             return(RedirectToAction("Login", "Account"));
         }
         var custId = CustomersManager.GetCustomerIdByUserId(user.UserId);
         var empId  = EmployeesManager.GetEmployeeIdByUserId(user.UserId);
         var ownId  = OwnersManager.GetOwnerIdByUserId(user.UserId);
         var claims = new List <Claim>()
         {
             new Claim(ClaimTypes.Name, user.Authentication.Username),
             new Claim("FullName", $"{user.FirstName} {user.LastName}"),
             new Claim("AuthID", user.AuthenticationId.ToString()),
             new Claim("UserID", user.UserId.ToString()),
             new Claim("CustomerID", custId.ToString()),
             new Claim("EmployeeID", empId.ToString()),
             new Claim("OwnerID", ownId.ToString()),
         };
         if (user.Authentication.AuthenticationMatrix.Count() > 0)
         {
             foreach (AuthenticationMatrix a in user.Authentication.AuthenticationMatrix)
             {
                 if (a.RestaurantId == authView.RestaurantId)
                 {
                     claims.Add(new Claim("RestaurantID", a.RestaurantId.ToString()));
                     claims.Add(new Claim(ClaimTypes.Role, a.Role));
                     TempData["RestaurantName"] = RestaurantsManager.GetRestaurantIdByNameByRestauranID(a.RestaurantId);
                 }
             }
         }
         var claimsIdentity = new ClaimsIdentity(claims, "Cookies");
         await HttpContext.SignInAsync("Cookies", new ClaimsPrincipal(claimsIdentity));
     }
     if (TempData["returnUrl"] == null)
     {
         return(Redirect("~/Account/Profile"));
     }
     else
     {
         return(Redirect(TempData["returnUrl"].ToString()));
     }
 }