public int UpdateUser(VMUserData changedData, string userMail)
        {
            int result = -1;

            using (var db = new LocalDbEntities2())
            {
                User dbUser = db.User.Where(u => u.email == userMail && u.active == true).FirstOrDefault();

                if (!string.IsNullOrEmpty(changedData.FirstName))
                {
                    dbUser.firstname = changedData.FirstName;
                }
                if (!string.IsNullOrEmpty(changedData.LastName))
                {
                    dbUser.lastname = changedData.LastName;
                }
                if (!string.IsNullOrEmpty(changedData.NewPassword))
                {
                    string salt = "";
                    dbUser.password = HashingHelper.SaltAndHashPassword(changedData.NewPassword, out salt);
                    dbUser.salt     = salt;
                }
                db.SaveChanges();
            }
            return(result);
        }
        public ActionResult EditUserData(VMUserData userData)
        {
            int result = -1;

            if (ModelState.IsValid)
            {
                result = AccountService.UpdateUser(userData, User.Identity.Name);
            }


            return(PartialView("_UserDataForm", userData));
        }
        public VMUserData GetUserData(string email)
        {
            VMUserData result = null;

            using (var db = new LocalDbEntities2())
            {
                User dbUser = db.User.Where(u => u.email == email && u.active == true).FirstOrDefault();
                result = new VMUserData
                {
                    FirstName = dbUser.firstname,
                    LastName  = dbUser.lastname
                };
            }
            return(result);
        }
        public static int UpdateUser(VMUserData userData, string userMail)
        {
            int result     = -1;
            int tempResult = -1;
            // Gathers all data which are allowed to be changed
            VMUserData dataValidToChange = new VMUserData();

            if (!string.IsNullOrEmpty(userData.FirstName))
            {
                dataValidToChange.FirstName = userData.FirstName;
            }
            if (!string.IsNullOrEmpty(userData.LastName))
            {
                dataValidToChange.LastName = userData.LastName;
            }

            if (!string.IsNullOrEmpty(userData.OldPassword) && !string.IsNullOrEmpty(userData.NewPassword) && !string.IsNullOrEmpty(userData.ConfirmNewPassword))
            {
                VMLogin testOldPw = new VMLogin
                {
                    Email    = userMail,
                    Password = userData.OldPassword
                };
                if (userData.NewPassword == userData.ConfirmNewPassword)
                {
                    if (context.CheckLogin(testOldPw))
                    {
                        dataValidToChange.NewPassword = userData.NewPassword;
                    }
                }
            }
            tempResult = context.UpdateUser(dataValidToChange, userMail);

            userData.ConfirmNewPassword = "";
            userData.NewPassword        = "";
            userData.OldPassword        = "";
            return(result);
        }
        public ActionResult GetUserData()
        {
            VMUserData model = AccountService.GetUserData(User.Identity.Name);

            return(PartialView("_UserDataForm", model));
        }