Пример #1
0
 public ActionResult Register(RegisterModel model)
 {
     if (ModelState.IsValid)
     {
         using (var context = new DbTTTEntities())
         {
             List <User> users = context.Users.Where(u => u.UserEmail == model.Email).ToList();
             if (users.Count > 0)
             {
                 ViewBag.AlreadyUsed = "Пользователь с таким адресом уже зарегистрирован.";
                 return(View());
             }
             else
             {
                 User newUser = new User();
                 newUser.UserName  = model.Name;
                 newUser.UserEmail = model.Email;
                 newUser.UserPass  = model.Password.GetHashCode().ToString();
                 context.Users.Add(newUser);
                 context.SaveChanges();
                 TempData["registerSuccess"] = "Регистрация прошла успешно.";
             }
         }
         return(RedirectToAction("Index", "Home"));
     }
     else
     {
         return(View());
     }
 }
Пример #2
0
        public ActionResult AddRoom()
        {
            if (Session["userID"] == null)
            {
                return(RedirectToAction("Login", "Account"));
            }

            using (var context = new DbTTTEntities())
            {
                Room        room   = new Room();
                int         userId = (int)Session["userID"];
                List <User> users  = context.Users.ToList();
                User        user   = users.Where(u => u.UserID == userId).First();
                room.User1 = user;
                context.Rooms.Add(room);
                context.SaveChanges();

                return(View("Index"));
            }
        }
Пример #3
0
 public ActionResult ChangePassword(ChangePasswordModel model)
 {
     if (Session["userID"] != null)
     {
         using (var context = new DbTTTEntities())
         {
             int id;
             if (Int32.TryParse(Session["userID"].ToString(), out id))
             {
                 var user = context.Users.Where(u => u.UserID == id).First();
                 if (model.OldPassword.GetHashCode().ToString() == user.UserPass)
                 {
                     user.UserPass = model.Password.GetHashCode().ToString();
                     context.SaveChanges();
                     TempData["passwordChange"] = "Пароль успешно изменен.";
                     return(RedirectToAction("Index", "Home"));
                 }
                 else
                 {
                     ViewBag.ChangeError = "Не верный старый пароль.";
                     return(View());
                 }
             }
             else
             {
                 ViewBag.ChangeError = "Не удалось изменить пароль.";
                 return(View());
             }
         }
     }
     else
     {
         ViewBag.ChangeError = "Не удалось изменить пароль.";
         return(View());
     }
 }