public ActionResult Logout(UserLoginModel usm)
 {
     usm = null;
     Session.Remove("zalogowany");
     HttpCookie cookie = Response.Cookies.Get("LoggedUser");
     cookie.Expires = DateTime.Now.AddYears(-1);
     return RedirectToAction("Index");
 }
        public ActionResult EditStudent(StudentModel model)
        {
            HttpCookie loggedStudent = Request.Cookies["LoggedUser"];
            UserServices services = new UserServices();
            StudentModel student = services.GetStudent(loggedStudent.Values.Get("Login"));
            services.ChangePassword(student.Login, student.Name, student.Surname, model.Password);

            UserLoginModel logged = new UserLoginModel();
            logged.Login = student.Login;
            logged.Name = student.Name;
            logged.Surname = student.Surname;
            return RedirectToAction("Index",logged);
        }
        public ActionResult EditTeacher(TeacherModel model)
        {
            HttpCookie loggedTeacher = Request.Cookies["LoggedUser"];
            UserServices services = new UserServices();
            TeacherModel teacher = services.GetTeacher(loggedTeacher.Values.Get("Login"));
            services.ChangePassword(teacher.Login, teacher.Imię, teacher.Nazwisko, model.Hasło);

            UserLoginModel logged = new UserLoginModel();
            logged.Login = model.Login;
            logged.Name = model.Imię;
            logged.Surname = model.Nazwisko;
            return RedirectToAction("Index", logged);
        }
 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);
 }
 //Pobieranie z bazy danych aktualnie zalogowanego użytkownika
 public UserLoginModel GetLoggedUser(string Login,string Password)
 {
     try
     {
         var studentquery = db.Uczniowie.Where(x => x.Login == Login && x.Hasło == Password).FirstOrDefault();
         if (studentquery != null)
         {
             UserLoginModel ulm = new UserLoginModel
             {
                 Login = studentquery.Login,
                 Name = studentquery.Imię,
                 Surname = studentquery.Nazwisko,
                 Password = studentquery.Hasło
             };
             return ulm;
         }
         else
         {
             var teacherquery = db.Nauczyciele.Where(x => x.Login == Login && x.Hasło == Password).FirstOrDefault();
             if (teacherquery != null)
             {
                 UserLoginModel ulm = new UserLoginModel
                 {
                     Login = teacherquery.Login,
                     Name = teacherquery.Imię,
                     Surname = teacherquery.Nazwisko,
                     Password = teacherquery.Hasło
                 };
                 return ulm;
             }
             return null;
         }
     }
     catch 
     {
         return null;
     }
 }