Beispiel #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");
        }
Beispiel #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)
            {

            }

        }