Esempio n. 1
0
 public ActionResult Register(User u)
 {
     try
     {
         ViewData["UserName"] = Request.Form["UserName"].ToString();
         ViewData["Password"] = Request.Form["Password"].ToString();
         String UserName = Request.Form["UserName"].ToString();
         String Password = Request.Form["Password"].ToString();
         User user = null;
         user = userService.GetByUserName(UserName);
         if (user == null)
         {
             var newUser = userService.Add(new User() { Name = UserName, Password = Password});
             userService.Save();
             Session["LogedUserID"] = newUser.UserId.ToString();
             Session["LogedUserFullName"] = newUser.Name.ToString();
             return RedirectToAction("ShowNotes", "Note");
         }
         else
         {
             ViewData["ErrorMessage"] = "Try another name";
             return View(u);
         }
     }
     catch (NullReferenceException)
     {
         return RedirectToAction("ErrorMessage", "User");
     }
     catch (SqlException)
     {
         return RedirectToAction("ErrorMessage", "User");
     }
 }
Esempio n. 2
0
 public ActionResult Login(User u)
 {
     try
     {
         ViewData["UserName"] = Request.Form["UserName"].ToString();
         ViewData["Password"] = Request.Form["Password"].ToString();
         String UserName = Request.Form["UserName"].ToString();
         String Password = Request.Form["Password"].ToString();
         var user = userService.GetByUserNameAndPassword(UserName, Password);
         if (user != null)
         {
             Session["LogedUserID"] = user.UserId.ToString();
             Session["LogedUserFullName"] = user.Name.ToString();
             return RedirectToAction("ShowNotes", "Note");
         }
         else
         {
             ViewData["ErrorMessage"] = "Invalid name or password";
             return View(u);
         }
     }
     catch (NullReferenceException)
     {
         return RedirectToAction("ErrorMessage", "User");
     }
     catch (SqlException)
     {
         return RedirectToAction("ErrorMessage", "User");
     }
 }
Esempio n. 3
0
 public void Update(User user)
 {
     db.Entry(user).State = EntityState.Modified;
 }
Esempio n. 4
0
 public bool IsExists(User user)
 {
     var users = db.Users.Where(a => a.Name == user.Name && a.Password == user.Password).FirstOrDefault();
     return users != null ? true : false;
 }
Esempio n. 5
0
 public User Add(User user)
 {
     return db.Users.Add(user);
 }
Esempio n. 6
0
 public void Add(User user, Note note)
 {
     User findUser = db.Users.Find(user.UserId);
     findUser.Notes.Add(note);
 }