示例#1
0
        private void StorePost(Post post)
        {
            Filemanager fileManager = new Filemanager();
            string      json        = System.Text.Json.JsonSerializer.Serialize(post);

            fileManager.CreateFolder(FolderPath);
            fileManager.CreateFile(FilePathPosts);
            fileManager.WriteDataToFile(json, FilePathPosts);
        }
示例#2
0
        private void UpdateDb(List <Post> posts)
        {
            Filemanager fileManager = new Filemanager();

            fileManager.DeleteFile(FilePathPosts);
            foreach (var post in posts)
            {
                StorePost(post);
            }
        }
示例#3
0
        private User MakeNewAccount(string eMail)
        {
            userIO.PadLeft("Enter username", 2);
            string userName = userIO.GetUserString();

            userIO.PadLeft("Enter firstname", 2);
            string firstName = userIO.GetUserString();

            userIO.PadLeft("Enter lastname", 2);
            string lastName = userIO.GetUserString();

            userIO.PadLeft("Enter password", 2);
            string password = GetPassword();

            userIO.PadLeft("Confirm password", 2);
            string confirmPassword = GetPassword();

            if (password != confirmPassword)
            {
                userIO.PadLeft("Passwords did not match. Press enter and try again", 2, ConsoleColor.DarkRed);
                Console.ReadLine();
                bool validPassword = false;

                while (!validPassword)
                {
                    userIO.PadLeft("Enter password", 2);
                    password = GetPassword();

                    userIO.PadLeft("Confirm password", 2);
                    confirmPassword = GetPassword();

                    if (password == confirmPassword)
                    {
                        validPassword = true;
                    }
                }
            }

            // make unique id;
            Filemanager fileManager = new Filemanager();
            int         newId       = fileManager.CountLinesFile(FilePathUsers) + 1;

            User newUser = new User();

            newUser.UserName       = userName;
            newUser.FirstName      = firstName;
            newUser.LastName       = lastName;
            newUser.Email          = eMail;
            newUser.Password       = password;
            newUser.dateRegistered = DateTime.Now;
            newUser.Id             = newId;

            return(newUser);
        }
示例#4
0
        public List <Post> LoadPosts()
        {
            Filemanager   fileManager = new Filemanager();
            List <string> postsJson   = new List <string>();
            List <Post>   Posts       = new List <Post>();

            fileManager.CreateFolder(FolderPath);
            fileManager.CreateFile(FilePathPosts);
            postsJson = fileManager.LoadAllFiles(FilePathPosts);

            for (int i = 0; i < postsJson.Count; i++)
            {
                string json   = postsJson[i];
                Post   result = JsonConvert.DeserializeObject <Post>(json);
                Posts.Add(result);
            }
            return(Posts);
        }