Exemple #1
0
        public ActionResult Register(RegisterModel model)
        {

            if (!ModelState.IsValid)
            {
                return View();
            }

            var completed = true;

            if (!completed)
            {
                ModelState.AddModelError("", "Fel fan");
                return View();
            }

            Profiles profile = new Profiles();
            profile.About = model.About;
            profile.Age = Int32.Parse(model.Age);
            profile.Email = model.Email;
            profile.Gender = model.Gender;
            profile.Lastname = model.Lastname;
            profile.Firstname = model.Firstname;

            SECURITY security = new SECURITY();
            security.USERNAME = model.Username;
            security.PASSWORD = model.Password;
            security.VISIBILITY = true;

            _usersRepository.insertUser(profile, security);

            return RedirectToAction("Index", "Home");
        }
Exemple #2
0
 /// <summary>
 /// Lägger till en användare i databasen
 /// </summary>
 public void insertUser(Profiles profile, SECURITY security)
 {
     try
     {
         using (var context = new UserDBEntities())
         {
             context.Database.Connection.Open();
             context.Profiles.Add(profile);
             context.SaveChanges();
             security.PID = profile.Id;
             context.SECURITY.Add(security);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
     }
 }
Exemple #3
0
        public SECURITY loginUser(SECURITY user)
        {
            using (var context = new UserDBEntities())
            {
                context.Database.Connection.Open();
                SECURITY usr = null;
                try
                {
                    usr = context.SECURITY.Single(u => u.USERNAME == user.USERNAME && u.PASSWORD == user.PASSWORD);
                }
                catch
                {
                    usr = null;
                }

                return(usr);
            }
        }
Exemple #4
0
        public ActionResult Login(LoginModel user)
        {

            SECURITY _user = new SECURITY();
            _user.USERNAME = user.Username;
            _user.PASSWORD = user.Password;
            var usr = _usersRepository.loginUser(_user);

            if (usr != null)
            {
            Session["UserID"] = usr.PID.ToString();
            Session["Username"] = usr.USERNAME.ToString();
                return RedirectToAction("LoggedIn");
            }
            else
            {
                ModelState.AddModelError("", "Username or password is invalid.");
            }

            return View();
        }
Exemple #5
0
        /// <summary>
        /// Lägger till en användare i databasen
        /// </summary>
        public void insertUser(Profiles profile, SECURITY security)
        {
            try
            {
                using (var context = new UserDBEntities())
                {
                    context.Database.Connection.Open();
                    context.Profiles.Add(profile);
                    context.SaveChanges();
                    security.PID = profile.Id;
                    context.SECURITY.Add(security);
                    context.SaveChanges();
                    
                }
            }
            catch (Exception e)
            {

            }

        }
Exemple #6
0
        public SECURITY loginUser(SECURITY user)
        {
            using (var context = new UserDBEntities())
            {
                context.Database.Connection.Open();
                SECURITY usr = null;
                try
                {
                     usr = context.SECURITY.Single(u => u.USERNAME == user.USERNAME && u.PASSWORD == user.PASSWORD);
                }
                catch
                {
                    usr = null;
                }

                return usr;
            }
            
        }