Exemplo n.º 1
0
        public ActionResult Login(User u)
        {
            //This action is for handle Post (login)
            if (ModelState.IsValid)
            {
              using (DATABASE_MOVIESHELFEntities1 store_Db = new DATABASE_MOVIESHELFEntities1())
              {
                var v= store_Db.Users.Where(a=>a.Username.Equals(u.Username) && a.Password.Equals(u.Password)).FirstOrDefault();
                  if (v!=null)
                  {
                      Session["LogedUserId"] = v.IdUsers.ToString();
                      Session["LogedUsername"] = v.Username.ToString();
                      return RedirectToAction("Index", "Store");

                  }
                  else
                  { ModelState.AddModelError("", "Invalid username or password");
                  return RedirectToAction("Login", "Home");
                  }
              }

            }
            return RedirectToAction("Login", "Home");
        }
Exemplo n.º 2
0
        public ActionResult register(User u)
        {
            if (ModelState.IsValid)
            {
                using (DATABASE_MOVIESHELFEntities1 store_Db = new DATABASE_MOVIESHELFEntities1())
                {
                    store_Db.Users.Add(u);
                    store_Db.SaveChanges();
                    ModelState.Clear();
                    u = null;
                    ViewBag.Message = "You have been succesfully registered";
                }

            }
            return View(u);
        }