public ActionResult Register(User user)
 {
     if (ctx.Users.Any(x => x.UserName == user.UserName))
     {
         return Content("שם משתמש כבר קיים");
     }
     user.Id = Guid.NewGuid();
     ctx.Users.Add(user);
     ctx.SaveChanges();
     //return RedirectToAction("Index", "Home");
     return RedirectToAction("Index", "Login");
 }
 public ActionResult Login(User user)
 {
     if (ModelState.IsValid)
     {
         var usrFromDb = IsValid(user);
         if (usrFromDb != null)
         {
             Session["LoggedinUserId"] = usrFromDb.Id;
             Session["LoggedinUserName"] = usrFromDb.FirstName + " " + usrFromDb.LastName;
             Session["LoggedinUserType"] = usrFromDb.Type;
             FormsAuthentication.SetAuthCookie(usrFromDb.UserName, usrFromDb.RememberMe);
             return RedirectToAction("Index", "Home");
         }
         else
         {
             ModelState.AddModelError("", "Login data is incorrect!");
         }
     }
     return RedirectToAction("Index","Login");
 }
        public ActionResult UpdateUser(User user)
        {
            var userFromDb = ctx.Users.Find(user.Id);
            userFromDb.UserName = user.UserName;
            userFromDb.Email = user.Email;
            userFromDb.FirstName = user.FirstName;
            userFromDb.LastName = user.LastName;
            userFromDb.Password = user.Password;
            userFromDb.Type = user.Type;
            userFromDb.RememberMe = user.RememberMe;

            ctx.Users.AddOrUpdate(userFromDb);
            ctx.SaveChanges();

            Session["LoggedinUserId"] = userFromDb.Id;
            Session["LoggedinUserName"] = userFromDb.FirstName + " " + userFromDb.LastName;
            Session["LoggedinUserType"] = userFromDb.Type;
            FormsAuthentication.SetAuthCookie(userFromDb.UserName, userFromDb.RememberMe);
            return RedirectToAction("Index", "Home");
        }
 private User IsValid(User user)
 {
     return _ctx.Users.FirstOrDefault(x => x.UserName == user.UserName && x.Password == user.Password);
 }