Esempio n. 1
0
        public ActionResult Login(LoginPageModel model)
        {
            User user;

            using (var db = new UsersDataContext())
            {
                user = db.Users.FirstOrDefault(x => x.UserName == model.UserName && x.Password == model.Password);
            }

            if (user != null)
            {
                var log = new Log() { DateTime = DateTime.Now, UserId = user.Id };

                using (var db = new LogDataContext())
                {
                    db.Logs.InsertOnSubmit(log);

                    db.SubmitChanges();
                }

                var userModel = new UserModel() {UserId = user.Id};
                return View("Secret", userModel);
            }
            else
            {
                //var errorModel = new LoginPageModel();
                ModelState.AddModelError("Invalid Login", "The user name and password combination is incorrect.  Try again.");
            }

            return View("Index");
        }
Esempio n. 2
0
        public int GetNumberOfLogInAttempts(int userId)
        {
            int numberOfLogInAttempts;
            using (var db = new LogDataContext())
            {
                numberOfLogInAttempts = db.Logs.Count(x => x.UserId == userId);
            }

            return numberOfLogInAttempts;
        }
Esempio n. 3
0
        public Log GetLoginAttempt(int logId)
        {
            Log attempt;

            using (var db = new LogDataContext())
            {
                attempt = db.Logs.FirstOrDefault(x => x.LogId == logId);
            }

            return attempt;
        }
Esempio n. 4
0
 public void DeleteLogInAttempt(int logId)
 {
     using (var db = new LogDataContext())
     {
         var log = db.Logs.FirstOrDefault(x => x.LogId == logId);
         if (log != null)
         {
             db.Logs.DeleteOnSubmit(log);
             db.SubmitChanges();
         }
     }
 }