public IActionResult Login(Registered person)
        {
            if (person == null)
            {
                return(View());
            }
            try {
                if (person.NickName.Equals("quest") && person.Password.Equals("password"))
                {
                    return(RedirectToAction("Guest"));
                }
            }
            catch (NullReferenceException nrEx)
            {
                return(RedirectToAction("Login", new Registered()));
            }
            Registered repositoryPerson = null;

            try
            {
                repository.Connect();
                repositoryPerson = repository.getByNickname(person.NickName);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(nameof(Person.NickName), "Nickname doesn't exists!");
                return(View());
            }

            ValidateLogin(person, repositoryPerson);

            if (ModelState.IsValid)
            {
                HttpContext.Session.SetString(KeyLoggedIn, "" + repositoryPerson.GetPersonType());
                return(RedirectToAction("Index"));
            }

            return(View());
        }
        public bool Update(int id, Registered person)
        {
            if (person == null)
            {
                return(false);
            }
            else if (connection.State == ConnectionState.Open)
            {
                DbCommand query = connection.CreateCommand();
                query.CommandText = "UPDATE Person set nickName = @nickName, password = @password, firstName = @firstName, lastName = @lastName, accessLevel = @accesLevel where id = @id;";
                query.Parameters.Add(MakeDbParameter(query, "nickName", DbType.String, person.NickName));
                query.Parameters.Add(MakeDbParameter(query, "password", DbType.String, person.Password));
                query.Parameters.Add(MakeDbParameter(query, "firstName", DbType.Int32, person.FirstName));
                query.Parameters.Add(MakeDbParameter(query, "lastName", DbType.Int32, person.LastName));
                query.Parameters.Add(MakeDbParameter(query, "accessLevel", DbType.Int32, person.GetPersonType()));
                query.Parameters.Add(MakeDbParameter(query, "id", DbType.Int32, id));

                return(query.ExecuteNonQuery() == 1);
            }
            return(false);
        }
 public bool Insert(Registered person)
 {
     if (person == null)
     {
         return(false);
     }
     else if (connection.State == ConnectionState.Open)
     {
         DbCommand query = connection.CreateCommand();
         query.CommandText = "INSERT Person VALUES(null, @nickName, @password, @firstName, @lastName, @accessLevel, null);";
         query.Parameters.Add(MakeDbParameter(query, "nickName", DbType.String, person.NickName));
         query.Parameters.Add(MakeDbParameter(query, "password", DbType.String, person.Password));
         query.Parameters.Add(MakeDbParameter(query, "firstName", DbType.String, person.FirstName));
         query.Parameters.Add(MakeDbParameter(query, "lastName", DbType.String, person.LastName));
         query.Parameters.Add(MakeDbParameter(query, "accessLevel", DbType.Int32, person.GetPersonType()));
         query.ToString();
         return(query.ExecuteNonQuery() == 1);
     }
     return(false);
 }