public ActionResult registrerAdmin(RegisterAnsattModel ansatt,string stilling)
 {
     if (ModelState.IsValid)
     {
         ansatt.Stilling = stilling;
         _adminBLL.registrer(ansatt);
         return RedirectToAction("Index", "Admin");
     }
     return View();
 }
        //Får å kunne komme her må man være ansatt, eneste untakk er hvis ingen ansatt er registrert.
        public ActionResult registrerAdmin()
        {
            if (!Request.IsAuthenticated)
            {
                if (_adminBLL.ansattTom())//ingen ansatte er registrert
                {
                    var regansatt = new RegisterAnsattModel();
                    regansatt.AnsattNr = setAnr();
                    var list = new List<SelectListItem>();
                    list.Add(new SelectListItem { Text = "Leder", Value = "Leder" });
                    list.Add(new SelectListItem { Text = "Kundeservice", Value = "Kundeservice" });
                    list.Add(new SelectListItem { Text = "LagerArbeider", Value = "LagerArbeider" });
                    list.Add(new SelectListItem { Text = "Innkjøp", Value = "Innkjøp" });
                    ViewBag.stilling = list;

                    return View(regansatt);
                }
                else
                {
                    MessageBox.Show("Registrering av adminbruker må gjøres av en annen admin registrert i systemet. Kun registrering av første admin er tillatt uten å være innlogget i adminsystemet.");
                    return RedirectToAction("logginn", "Admin");
                }
            }
            else
            {
                if (_adminBLL.erAnsatt(User.Identity.Name))
                {
                    var regansatt = new RegisterAnsattModel();
                    regansatt.AnsattNr = setAnr();
                    var list = new List<SelectListItem>();
                    list.Add(new SelectListItem { Text = "Leder", Value = "Leder" });
                    list.Add(new SelectListItem { Text = "Kundeservice", Value = "Kundeservice" });
                    list.Add(new SelectListItem { Text = "LagerArbeider", Value = "LagerArbeider" });
                    list.Add(new SelectListItem { Text = "Innkjøp", Value = "Innkjøp" });
                    ViewBag.stilling = list;
                    return View(regansatt);
                }
                else
                {
                    return RedirectToAction("logginn", "Admin");
                }

            }
        }
 public bool registrer(RegisterAnsattModel ansatt)
 {
     return _repository.RegistrationAnsatt(ansatt);
 }
 public bool RegistrationAnsatt(RegisterAnsattModel user)
 {
     if (user.AnsattNr == null)
     {
         return false;
     }
     return true;
 }
        public void registreradmin_Post_Ok()
        {
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true);
            mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("123");
            var ansatte = new RegisterAnsattModel()
            {
                AnsattNr = "s1",
                Epost = "*****@*****.**",
                Firstname = "Arne",
                Lastname = "Hansen",
                Stilling = "Leder"
            };

            var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()),
                new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub()));
            controller.ControllerContext = mock.Object;
            var viewResult = (RedirectToRouteResult)controller.registrerAdmin(ansatte, "leder");
            Assert.AreEqual("Index", viewResult.RouteValues["Action"]); //<---view som blir vist hvis er requested-->)
            Assert.AreEqual("Admin", viewResult.RouteValues["Controller"]); //<---view som blir vist hvis er requested-->)
        }
        public bool RegistrationAnsatt(RegisterAnsattModel user)
        {
            try
                {
                    if (user == null || user.Password == null || user.Password == "")
                        return false;

                    var crypto = new SimpleCrypto.PBKDF2();
                    var encryPass = crypto.Compute(user.Password);
                    var sysUser = db.Admins.Create();
                    sysUser.AnsattId = user.AnsattNr;
                    sysUser.Password = encryPass;
                    sysUser.PasswordSalt = crypto.Salt;
                    sysUser.Firstname = user.Firstname;
                    sysUser.Lastname = user.Lastname;
                    sysUser.Stilling = user.Stilling;
                    sysUser.Epost = user.Epost;
                    db.Admins.Add(sysUser);
                    db.SaveChanges();
                    //FormsAuthentication.SetAuthCookie(user.AnsattNr, false);
                    return true;
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                    "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
                catch (InvalidOperationException ex)
                {
                    SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
                catch (ArgumentException ex)
                {
                    SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
                catch (NullReferenceException ex)
                {
                    SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                      "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
                catch (SystemException ex)
                {
                    SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
                catch (Exception ex)
                {
                    SWKA.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                    "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    SWKA.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }

                return false;
        }