Esempio n. 1
0
        public ActionResult Login(User logUser)
        {
            using (TajnyProjektDbContext db = new TajnyProjektDbContext())
            {
                User usr = db.Users.FirstOrDefault(x => x.Password == logUser.Password);
                if (usr != null)
                {
                    Session["UserID"] = usr.UserId.ToString();
                    Session["Username"] = usr.Name.ToString();
                 return RedirectToAction("LoggedIn");
                }

                    ModelState.AddModelError("","User Name or Password incorrect");
                
            }
            return View();
        }
Esempio n. 2
0
        public ActionResult Register(User user)
        {
            if (ModelState.IsValid)
            {
                using (TajnyProjektDbContext db = new TajnyProjektDbContext())
                {
                    const string chars = "0123456789";
                    var random = new Random();
                    user.UserId =random.Next(0,1000).ToString();
                    db.Users.Add(user);
                    db.SaveChanges();
                }
                ModelState.Clear();
                ViewBag.Message = user.Name + " " + user.Surname + " succesfuil registred";
            }

            return View();
        }
Esempio n. 3
0
        public ActionResult Edit(User user)
        {
            if (ModelState.IsValid)
            {
                using (TajnyProjektDbContext db = new TajnyProjektDbContext())
                {
                    user.UserId = Session["UserId"].ToString();     
                    db.Entry(user).State = EntityState.Modified;
                    db.SaveChanges();
                    
                }
                 ModelState.Clear();
                ViewBag.Message = "Edit Succesfull";
                return RedirectToAction("Edit");
            }


            return View();
        }