public void edituserdata_ok()
        {
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true);
            mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("");
            var t = new ChangeUserDataModel()
            {
                Email = "*****@*****.**",
                Firstname = "Hans",
                Lastname = "Hansen",
                Streetadress = "Osloveien 2",
                ZipCode = "1274",
                PhoneNr = "22225555"
            };

            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 = (ViewResult)controller.EditUserData("ad");
            var k = (ChangeUserDataModel)viewResult.Model;

            Assert.AreEqual(t.Email, k.Email);
            Assert.AreEqual(t.Firstname, k.Firstname);
            Assert.AreEqual(t.Lastname, k.Lastname);
            Assert.AreEqual(t.Streetadress, k.Streetadress);
            Assert.AreEqual(t.ZipCode, k.ZipCode);
            Assert.AreEqual(t.PhoneNr, k.PhoneNr);
        }
        public ActionResult EditUserData(ChangeUserDataModel user)
        {
            var email = User.Identity.Name;

            if(_kundeBLL.EditUserData(user, email))
            {
                return RedirectToAction("Index", "Manage");

            }
            ModelState.AddModelError("", "Problem med bytte passord, forsøk igjen");
            return View(user);
        }
        public void edituserdata_feil()
        {
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true);
            mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("");
            var t = new ChangeUserDataModel()
            {
                Email = "0",

            };

            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 = (ViewResult)controller.EditUserData("");
            var k = (ChangeUserDataModel)viewResult.Model;
            Assert.AreEqual(t.Email, k.Email);
        }
        public void edituserdata_post_feil()
        {
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true);
            mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("");
            var t = new ChangeUserDataModel();

            //act
            //assert

            var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()),
                new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub()));
            controller.ControllerContext = mock.Object;
            controller.ViewData.ModelState.AddModelError("", "Feil");

            var viewResult = (ViewResult)controller.EditUserData(t);
            Assert.IsTrue(viewResult.ViewData.ModelState.Count == 1);
            Assert.IsTrue(viewResult.ViewName == "");
        }
        public ActionResult EditUserData(ChangeUserDataModel user)
        {
            if (ModelState.IsValid)
            {
                var email = user.Email;

                if (_kundeBLL.EditUserData(user, email))
                {
                    return RedirectToAction("visAlleKunder", "Admin");

                }
            }
            ModelState.AddModelError("", "Problem med bytte passord, forsøk igjen");
            return View(user);
        }
 public bool EditUserData(ChangeUserDataModel user, string email)
 {
     return _repository.EditUserData(user, email);
 }
        public ChangeUserDataModel hentKundeInfo(string email)
        {
            if (email == "")
            {
                var User = new ChangeUserDataModel()
                {
                    Email = "0",
                };
                return User;
            }

            var UserDB = new ChangeUserDataModel()
            {
                Email = "*****@*****.**",
                Firstname = "Hans",
                Lastname = "Hansen",
                Streetadress = "Osloveien 2",
                ZipCode = "1274",
                PhoneNr = "22225555"

            };
            return UserDB;
        }
        public bool EditUserData(ChangeUserDataModel user, string email)
        {
            if (email == null || user.Email == null)
            {
                return false;

            }
            return true;
        }
        public void edituserdata_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("");
            var t = new ChangeUserDataModel()
            {
                Email = "*****@*****.**",
                Firstname = "Hans",
                Lastname = "Hansen",
                Streetadress = "Osloveien 2",
                ZipCode = "1274",
                PhoneNr = "22225555"
            };

            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.EditUserData(t);
            Assert.AreEqual("visAlleKunder", viewResult.RouteValues["Action"]); //<---view som blir vist hvis er requested-->)
            Assert.AreEqual("Admin", viewResult.RouteValues["Controller"]); //<---view som blir vist hvis er requested-->)
        }
        public ChangeUserDataModel hentKundeInfo(string email)
        {
            try
            {
                if (email == null || email == "")
                    return null;
                var user = db.Users.FirstOrDefault(u => u.Email == email);
                if (user != null)
                {
                    //var model = new List<ChangeUserDataModel>();
                    var UserDB = new ChangeUserDataModel();
                    UserDB.Email = user.Email;
                    UserDB.Firstname = user.Firstname;
                    UserDB.Lastname = user.Lastname;
                    UserDB.Streetadress = user.Streetadress;
                    UserDB.ZipCode = user.Zipcode;
                    UserDB.PhoneNr = user.PhoneNr;

                    //model.Add(UserDB);
                    return UserDB;
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (InvalidOperationException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                 "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (ArgumentException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                 "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (NullReferenceException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                  "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (SystemException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                 "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (Exception ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }

            return null;
        }
        public bool EditUserData(ChangeUserDataModel user, string email)
        {
            try
            {
                if (email == null || email == "")
                {
                    var UserDB = db.Users.FirstOrDefault(u => u.Email == email);
                    if (UserDB != null)
                    {
                        UserDB.Firstname = user.Firstname;
                        UserDB.Lastname = user.Lastname;
                        UserDB.Streetadress = user.Streetadress;
                        UserDB.Zipcode = user.ZipCode;
                        UserDB.PhoneNr = user.PhoneNr;

                        db.SaveChanges();
                        return true;

                    }
                    return false;
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (InvalidOperationException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                 "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (ArgumentException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                 "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (NullReferenceException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                  "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (SystemException ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                 "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }
            catch (Exception ex)
            {
                SWKR.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                SWKR.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
            }

            return false;
        }