public ActionResult Index(UserLoginModel model)
 {
     LoggedUserModel user = new LoggedUserModel();
     UserServices services = new UserServices();
     if(Session["zalogowany"] != null && Request.Cookies["LoggedUser"] !=null && model.Login == null && model.Password == null)
     {
         user.Login = Request.Cookies["LoggedUser"].Values.Get("Login");
         user.Name = Request.Cookies["LoggedUser"].Values.Get("Name");
         user.Surname = Request.Cookies["LoggedUser"].Values.Get("Surname");
     }
     else
     {
         user.Login = model.Login;
         user.Name = model.Name;
         user.Surname = model.Surname;
     }
     return View(user);
 }
        public ActionResult Index(string Login, string Password)
        {
            UserServices service = new UserServices();
            UserLoginModel model = service.GetLoggedUser(Login, Password);

            if (model != null)
            {
                Session["zalogowany"] = model;
                LoggedUserModel user = new LoggedUserModel();
                user.Name = model.Name;
                user.Surname = model.Surname;
                user.Login = model.Login;
                HttpCookie cookie = new HttpCookie("LoggedUser");
                cookie.Values.Add("Name",model.Name);
                cookie.Values.Add("Surname",model.Surname);
                cookie.Values.Add("Login",model.Login);

                if (service.ExistsStudentInDatabase(user.Login, user.Name, user.Surname))
                {
                    cookie.Values.Add("Role", "S");
                    cookie.Expires = DateTime.Now.AddDays(1.0);
                    Response.Cookies.Add(cookie);
                    return RedirectToAction("Index", "Student", user);
                }
                else
                {
                    cookie.Values.Add("Role", "T");
                    cookie.Expires = DateTime.Now.AddDays(1.0);
                    Response.Cookies.Add(cookie);
                    return RedirectToAction("Index", "Teacher", user);
                }
            }
            else
            {
                ViewBag.Message = "Nie istnieje użytkownik o podanych danych logowania, spróbuj ponownie";
                return View();
            }
        }