Example #1
0
        public bool UpdateUserData(AuthModel authModel, Dictionary <string, string> userDictionary, out AuthModel newModel, bool isNewUser = true)
        {
            System.Console.WriteLine("update logic: dictionary:");
            System.Console.WriteLine(userDictionary);
            System.Console.WriteLine("userDictionary[\"email\"]");
            System.Console.WriteLine(userDictionary["email"]);
            // todo: if we give user more data, assign here
            User user     = authModel.GetMappedUser();
            User authUser = _getUpdatedUserFromDictionary(userDictionary);

            authUser.Firstname    = user.Firstname;
            authUser.Lastname     = user.Lastname;
            authUser.PasswordHash = "";
            authUser.PasswordSalt = "";
            authUser.Username     = authUser.Email;
            bool success = false;

            if (isNewUser)
            {
                authUser.DateCreated = DateTime.Now;
                success = _repo.SaveNewUser(authUser, out user);
                if (success)
                {
                    newModel = AuthModel.GetFromUser(user);
                }
                else
                {
                    newModel = null;
                }
            }
            else
            {
                if (_repo.UpdateUserPrimaryData(authUser, out user))
                {
                    newModel = AuthModel.GetFromUser(user);
                    success  = true;
                }
                else
                {
                    newModel = null;
                }
            }
            return(success);
        }