diff --git a/Dania.Flashcards/Controllers/FlashcardController.cs b/Dania.Flashcards/Controllers/FlashcardController.cs new file mode 100644 index 00000000..76733c20 --- /dev/null +++ b/Dania.Flashcards/Controllers/FlashcardController.cs @@ -0,0 +1,178 @@ +using Flashcards.Models; + +namespace Flashcards.Controllers +{ + internal class FlashcardController + { + List flashcards = new List(); + DatabaseManager databaseManager; + Helpers helpers = new Helpers(); + + public FlashcardController(DatabaseManager databaseManager) + { + this.databaseManager = databaseManager; + } + + internal void ViewFlashcards(Stack stack) + { + GetFlashcards(stack); + + Console.WriteLine("\nPress Enter to return to the manage flashcard menu..."); + Console.ReadLine(); + } + + internal void CreateFlashcards(Stack stack) + { + Console.Clear(); + Console.WriteLine($"---Create flashcards in Stack: {stack.Name}---"); + + Console.WriteLine("Enter the question for the flashcard: "); + string question = Console.ReadLine(); + + if (question == "0") return; + + Console.WriteLine("\nEnter the answer for the flashcard: "); + string answer = Console.ReadLine(); + + if (answer == "0") return; + + databaseManager.CreateFlashcard(stack.Id, question, answer); + Console.WriteLine("\nFlashcard created successfully!"); + + Console.Write("Would you like to create another flashcard? (y/n): "); + string input = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(input) && input.ToLower() == "y") + CreateFlashcards(stack); + else + { + Console.WriteLine("\nPress Enter to return to the manage flashcard menu..."); + Console.ReadLine(); + } + } + + internal void UpdateFlashcards(Stack stack) + { + Console.Clear(); + Console.WriteLine("---Update flashcards---"); + GetFlashcards(stack); + if (flashcards.Count > 0) + { + Console.WriteLine("\nEnter the flashcard id to update: "); + int flashcardDisplayId = helpers.CheckIntInput(); + + if (flashcardDisplayId == 0) return; + + var flashcard = flashcards.FirstOrDefault(f => f.DisplayId == flashcardDisplayId); + + if (flashcard == null) + Console.WriteLine($"Flashcard with ID '{flashcardDisplayId}' does not exist. Please try again."); + else + { + Console.WriteLine($"\nCurrent question: {flashcard.Question}"); + Console.WriteLine("Enter the new question for the flashcard (Press Enter to keep the current question): "); + string newQuestion = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(newQuestion)) + flashcard.Question = newQuestion; + + Console.WriteLine($"\nCurrent answer: {flashcard.Answer}"); + Console.WriteLine("Enter the new answer for the flashcard (Press Enter to keep the current answer): "); + string newAnswer = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(newAnswer)) + flashcard.Answer = newAnswer; + + databaseManager.UpdateFlashcard(flashcard.Id, flashcard.Question, flashcard.Answer); + Console.WriteLine($"\nFlashcard with ID '{flashcardDisplayId}' updated successfully!"); + } + + Console.WriteLine("\nWould you like to update another flashcard? (y/n): "); + string input = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(input) && input.ToLower() == "y") + UpdateFlashcards(stack); + else + { + Console.WriteLine("\nPress Enter to return to the manage flashcard menu..."); + Console.ReadLine(); + } + } + else + { + Console.WriteLine("\nPress Enter to return to the manage flashcard menu..."); + Console.ReadLine(); + } + } + + internal void DeleteFlashcards(Stack stack) + { + Console.Clear(); + Console.WriteLine("---Delete flashcards---"); + + GetFlashcards(stack); + if (flashcards.Count > 0) + { + Console.WriteLine("\nEnter the flashcard id to delete: "); + int flashcardDisplayId = helpers.CheckIntInput(); + + if (flashcardDisplayId == 0) return; + + // Find the flashcard by its display ID + var flashcard = flashcards.FirstOrDefault(f => f.DisplayId == flashcardDisplayId); + + if (flashcard == null) + Console.WriteLine($"Flashcard with ID '{flashcardDisplayId}' does not exist. Please try again."); + else + { + Console.WriteLine($"\nAre you sure you want to delete flashcard with ID '{flashcardDisplayId}'? (y/n): "); + string confirmation = Console.ReadLine(); + + if (confirmation.Trim().ToLower() == "y") + { + databaseManager.DeleteFlashcard(flashcard.Id); + Console.WriteLine($"\nFlashcard with ID '{flashcardDisplayId}' deleted successfully!"); + } + else + Console.WriteLine("\nDeletion cancelled."); + + } + + Console.WriteLine("\nWould you like to delete another flashcard? (y/n): "); + string input = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(input) && input.ToLower() == "y") + DeleteFlashcards(stack); + else + { + Console.WriteLine("\nPress Enter to return to the manage flashcard menu..."); + Console.ReadLine(); + } + } + else + { + Console.WriteLine("\nPress Enter to return to the manage flashcard menu..."); + Console.ReadLine(); + } + } + + + + internal void GetFlashcards(Stack stack) + { + flashcards.Clear(); + flashcards = databaseManager.GetFlashcardsByStackId(stack.Id); + + Console.Clear(); + Console.WriteLine($"---Flashcards in Stack: {stack.Name}---"); + if (flashcards.Count == 0) + { + Console.WriteLine("No flashcards found in this stack."); + } + else + { + Console.WriteLine("{0,-7} {1,-15} {2,-15}", "ID", "Question", "Answer"); + foreach (var flashcard in flashcards) + { + Console.WriteLine("{0,-7} {1,-15} {2,-15}", flashcard.DisplayId, flashcard.Question, flashcard.Answer); + + } + } + } + } +} diff --git a/Dania.Flashcards/Controllers/StackController.cs b/Dania.Flashcards/Controllers/StackController.cs new file mode 100644 index 00000000..bd9670ac --- /dev/null +++ b/Dania.Flashcards/Controllers/StackController.cs @@ -0,0 +1,125 @@ +using Flashcards.Models; + +namespace Flashcards.Controllers +{ + internal class StackController + { + List stacks = new List(); + DatabaseManager databaseManager; + + public StackController(DatabaseManager databaseManager) + { + this.databaseManager = databaseManager; + } + + internal void CreateStack() + { + Console.Clear(); + Console.WriteLine("---Create a new Stack---"); + + Console.WriteLine("Enter the name of the new stack (Press 0 to return to the manage stacks menu): "); + string name = Console.ReadLine(); + + if (name == "0") return; + + Console.WriteLine(); + if (string.IsNullOrWhiteSpace(name)) + { + Console.WriteLine("Stack name cannot be empty. Please try again."); + } + else + { + if (databaseManager.CheckStackExist(name)) + Console.WriteLine($"Stack '{name}' already exists. Please choose a different name."); + else + { + databaseManager.CreateStack(name); + Console.WriteLine($"Stack '{name}' created successfully!"); + } + } + + Console.WriteLine("\nWould you like to create another stack? (y/n): "); + string input = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(input) && input.ToLower() == "y") + CreateStack(); + else + { + Console.WriteLine("\nPress Enter to return to the manage stacks menu..."); + Console.ReadLine(); + } + } + + internal void DeleteStack() + { + Console.Clear(); + Console.WriteLine("---Delete Stacks---"); + + if (GetStacks() > 0) + { + Console.WriteLine("\nEnter the stack name to delete (Press 0 to return to the manage stacks menu):"); + string stackName = Console.ReadLine(); + + if (stackName == "0") return; + + Stack stack = GetStackByName(stackName); + if (stack != null) + { + Console.WriteLine($"\nAre you sure you want to delete stack '{stackName}' and all its flashcards? (y/n): "); + string confirmation = Console.ReadLine(); + + if (confirmation.Trim().ToLower() == "y") + { + databaseManager.DeleteStack(stack.Id); + Console.WriteLine($"\nStack '{stackName}' and all its flashcards deleted successfully!"); + } + else + Console.WriteLine("\nDeletion cancelled."); + } + + Console.WriteLine("\nWould you like to delete another stack? (y/n): "); + string input = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(input) && input.ToLower() == "y") + DeleteStack(); + else + { + Console.WriteLine("\nPress Enter to return to the manage stack menu..."); + Console.ReadLine(); + } + } + else + { + Console.WriteLine("\nPress Enter to return to the manage stack menu..."); + Console.ReadLine(); + } + } + + internal int GetStacks() + { + stacks.Clear(); + stacks = databaseManager.GetStacks(); + + if (stacks.Count == 0) + Console.WriteLine("No stacks found. Please create a stack first."); + else + { + foreach (var stack in stacks) + { + Console.WriteLine($"- {stack.Name}"); + } + } + + return stacks.Count; + } + + internal Stack GetStackByName(string stackName) + { + // Use case-insensitive comparison to find the stack by name + var stack = stacks.FirstOrDefault(s => s.Name.Equals(stackName, StringComparison.OrdinalIgnoreCase)); + + if (stack == null) + Console.WriteLine($"\nStack '{stackName}' does not exist. Please try again."); + + return stack; + } + } +} diff --git a/Dania.Flashcards/Controllers/StudySessionController.cs b/Dania.Flashcards/Controllers/StudySessionController.cs new file mode 100644 index 00000000..241051e7 --- /dev/null +++ b/Dania.Flashcards/Controllers/StudySessionController.cs @@ -0,0 +1,130 @@ +using Flashcards.Models; + +namespace Flashcards.Controllers +{ + internal class StudySessionController + { + DatabaseManager databaseManager; + StackController stackController; + + List flashcards = new List(); + List studySessions = new List(); + int score = 0; + + public StudySessionController(DatabaseManager databaseManager, StackController stackController) + { + this.databaseManager = databaseManager; + this.stackController = stackController; + } + + internal void PrepareStudySession() + { + Stack currentStack = null; + + Console.Clear(); + Console.WriteLine("---Start a study session---"); + + if (stackController.GetStacks() > 0) + { + Console.WriteLine("\nEnter the stack name to start a study session (Press 0 to return to the main menu):"); + string stackName = Console.ReadLine(); + + if (stackName == "0") return; + + currentStack = stackController.GetStackByName(stackName); + + if (currentStack != null) + { + flashcards.Clear(); + flashcards = databaseManager.GetFlashcardsByStackId(currentStack.Id); + + if (flashcards.Count == 0) + { + Console.WriteLine("\nNo flashcards found in this stack."); + } + else + { + StartStudySession(currentStack); + } + } + } + + Console.WriteLine("\nPress Enter to return to the study session menu..."); + Console.ReadLine(); + } + + internal void StartStudySession(Stack currentStack) + { + Console.WriteLine("\nStarting study session..."); + score = 0; + + //Shuffle and take only the first 10 flashcards for the session, or all if there are less than 10 + var studySelection = flashcards.OrderBy(f => Guid.NewGuid()).Take(10).ToList(); + + foreach (var flashcard in studySelection) + { + Console.Clear(); + Console.WriteLine($"---Studying: {currentStack.Name}---"); + Console.WriteLine($"Question: {flashcard.Question}"); + Console.Write("What is the answer?: "); + string answer = Console.ReadLine(); + + if (answer == flashcard.Answer) + { + Console.WriteLine("\nCorrect!"); + score++; + } + else + Console.WriteLine($"\nThe answer is {flashcard.Answer}."); + + Console.ReadLine(); + } + + Console.Clear(); + Console.WriteLine($"---Studying: {currentStack.Name}---"); + Console.WriteLine("Session completed!"); + Console.WriteLine($"Your score: {score}/{studySelection.Count} ({(double)score / studySelection.Count * 100:0.00}%)"); + databaseManager.CreateStudySession(currentStack.Id, score, studySelection.Count); + + Console.WriteLine($"\nWould you like to study {currentStack.Name} again? y/n"); + string selectInput = Console.ReadLine(); + if (!string.IsNullOrWhiteSpace(selectInput) && selectInput.ToLower() == "y") + StartStudySession(currentStack); + + } + + internal void StudySessionRecords() + { + studySessions.Clear(); + studySessions = databaseManager.GetStudySessions(); + + Console.Clear(); + Console.WriteLine("---Study Session Records---"); + if (studySessions.Count <= 0) + { + Console.WriteLine("No study sessions recorded"); + } + else + { + Console.WriteLine("{0,-20} {1,-15} {2,-10} {3,-10}", "Date", "Stack", "Score", "Result"); + + foreach (var session in studySessions) + { + double percent = ((double)session.Score / session.TotalQuestions) * 100; + + Console.WriteLine("{0,-20} {1,-15} {2,-10} {3,-10}", + session.Date.ToString("yyyy-MM-dd HH:mm"), + session.StackName, + $"{session.Score}/{session.TotalQuestions}", + $"{percent:0}%"); + + } + + } + + Console.WriteLine("\nPress Enter to return to the study session menu..."); + Console.ReadLine(); + } + + } +} diff --git a/Dania.Flashcards/DatabaseManager.cs b/Dania.Flashcards/DatabaseManager.cs new file mode 100644 index 00000000..c197b78a --- /dev/null +++ b/Dania.Flashcards/DatabaseManager.cs @@ -0,0 +1,196 @@ +using Dapper; +using Microsoft.Data.SqlClient; +using Microsoft.Extensions.Configuration; +using Flashcards.Models; + +namespace Flashcards +{ + internal class DatabaseManager + { + //Appsetting.json config connection + internal string GetConnectionString() + { + IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); + string connectionString = config.GetConnectionString("DefaultConnection"); + + return connectionString; + + } + + internal bool TestConnection() + { + try + { + using (var connection = new SqlConnection(GetConnectionString())) + { + connection.Open(); + return true; // Connection successful + } + } + catch (Exception ex) + { + Console.WriteLine($"Database connection failed: {ex.Message}"); + return false; // Connection failed + } + } + + internal void CreateTable() + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = @"IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Stacks') + BEGIN + CREATE TABLE Stacks ( + Id INT PRIMARY KEY IDENTITY(1,1), + Name NVARCHAR(255) UNIQUE NOT NULL + ); + END + + IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Flashcards') + BEGIN + CREATE TABLE Flashcards ( + Id INT PRIMARY KEY IDENTITY(1,1), + StackId INT NOT NULL, + Question NVARCHAR(MAX) NOT NULL, + Answer NVARCHAR(MAX) NOT NULL, + FOREIGN KEY (StackId) REFERENCES Stacks(Id) ON DELETE CASCADE + ); + END + + IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'StudySessions') + BEGIN + CREATE TABLE StudySessions( + Id INT PRIMARY KEY IDENTITY(1,1), + StackId INT NOT NULL, + Date DATETIME NOT NULL, + Score INT NOT NULL, + TotalQuestions INT NOT NULL, + FOREIGN KEY (StackId) REFERENCES Stacks(Id) ON DELETE CASCADE + ); + END"; + + connection.Execute(sql); + } + } + + internal void CreateStack(string stackName) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "INSERT INTO Stacks (Name) VALUES (@Name)"; + + connection.Execute(sql, new { Name = stackName }); + } + } + + internal List GetStacks() + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "SELECT * FROM Stacks ORDER BY Id ASC"; + + return connection.Query(sql).ToList(); + } + + } + + internal void DeleteStack(int stackId) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "DELETE FROM Stacks WHERE Id = @Id"; + connection.Execute(sql, new { Id = stackId }); + } + } + + internal void CreateFlashcard(int stackId, string question, string answer) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "INSERT INTO Flashcards (StackId, Question, Answer) VALUES (@StackId, @Question, @Answer)"; + + connection.Execute(sql, new { StackId = stackId, Question = question, Answer = answer }); + } + + } + + internal List GetFlashcardsByStackId(int stackId) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = @"SELECT Id, + ROW_NUMBER() OVER (ORDER BY Id ASC) AS DisplayId, + Question, + Answer + FROM Flashcards WHERE StackId = @StackId"; + + return connection.Query(sql, new { StackId = stackId }).ToList(); + } + } + + internal void UpdateFlashcard(int flashcardId, string question, string answer) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "UPDATE Flashcards SET Question = @Question, Answer = @Answer WHERE Id = @Id"; + connection.Execute(sql, new { Id = flashcardId, Question = question, Answer = answer }); + } + } + + internal void DeleteFlashcard(int flashcardId) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "DELETE FROM Flashcards WHERE Id = @Id"; + connection.Execute(sql, new { Id = flashcardId }); + } + } + + internal bool CheckStackExist(string stackname) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "SELECT COUNT(1) FROM Stacks WHERE Name = @Name"; + + int count = connection.ExecuteScalar(sql, new { Name = stackname }); + return count > 0; + } + } + + internal bool CheckStackExist(int id) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "SELECT COUNT(1) FROM Stacks WHERE Id = @Id"; + + int count = connection.ExecuteScalar(sql, new { Id = id }); + return count > 0; + } + } + + internal void CreateStudySession(int stackId, int score, int totalQuestions) + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = "INSERT INTO StudySessions (StackId, Date, Score, TotalQuestions) VALUES (@StackId, @Date, @Score, @TotalQuestions)"; + connection.Execute(sql, new { StackId = stackId, Date = DateTime.Now, Score = score, TotalQuestions = totalQuestions }); + } + } + + internal List GetStudySessions() + { + using (var connection = new SqlConnection(GetConnectionString())) + { + var sql = @"SELECT + Stacks.Name AS StackName, + StudySessions.Date, + StudySessions.Score, + StudySessions.TotalQuestions + FROM StudySessions JOIN Stacks ON StudySessions.StackId = Stacks.Id"; + + return connection.Query(sql).ToList(); + } + + } + } +} diff --git a/Dania.Flashcards/Flashcards.csproj b/Dania.Flashcards/Flashcards.csproj new file mode 100644 index 00000000..58c69e74 --- /dev/null +++ b/Dania.Flashcards/Flashcards.csproj @@ -0,0 +1,22 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + + + + + PreserveNewest + + + + diff --git a/Dania.Flashcards/Flashcards.slnx b/Dania.Flashcards/Flashcards.slnx new file mode 100644 index 00000000..16eaf520 --- /dev/null +++ b/Dania.Flashcards/Flashcards.slnx @@ -0,0 +1,3 @@ + + + diff --git a/Dania.Flashcards/Helpers.cs b/Dania.Flashcards/Helpers.cs new file mode 100644 index 00000000..2e13b5b0 --- /dev/null +++ b/Dania.Flashcards/Helpers.cs @@ -0,0 +1,24 @@ +namespace Flashcards +{ + internal class Helpers + { + internal int CheckIntInput() + { + int number = 0; + bool isValid = false; + + do + { + string input = Console.ReadLine(); + input = input.Trim().ToLower(); + isValid = int.TryParse(input, out number); + + if (!isValid) + Console.WriteLine("\nPlease input a number!"); + + } while(!isValid); + + return number; + } + } +} diff --git a/Dania.Flashcards/Models/FlashcardDto.cs b/Dania.Flashcards/Models/FlashcardDto.cs new file mode 100644 index 00000000..0a7ca1bd --- /dev/null +++ b/Dania.Flashcards/Models/FlashcardDto.cs @@ -0,0 +1,10 @@ +namespace Flashcards.Models +{ + internal class FlashcardDto + { + public int Id { get; set; } + public int DisplayId { get; set; } + public string Question { get; set; } + public string Answer { get; set; } + } +} diff --git a/Dania.Flashcards/Models/Stack.cs b/Dania.Flashcards/Models/Stack.cs new file mode 100644 index 00000000..d7e59709 --- /dev/null +++ b/Dania.Flashcards/Models/Stack.cs @@ -0,0 +1,8 @@ +namespace Flashcards.Models +{ + internal class Stack + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Dania.Flashcards/Models/StudySession.cs b/Dania.Flashcards/Models/StudySession.cs new file mode 100644 index 00000000..964d7f89 --- /dev/null +++ b/Dania.Flashcards/Models/StudySession.cs @@ -0,0 +1,11 @@ +namespace Flashcards.Models +{ + internal class StudySession + { + public string StackName { get; set; } + public DateTime Date { get; set; } + public int Score { get; set; } + public int TotalQuestions { get; set; } + + } +} diff --git a/Dania.Flashcards/Program.cs b/Dania.Flashcards/Program.cs new file mode 100644 index 00000000..fb839c83 --- /dev/null +++ b/Dania.Flashcards/Program.cs @@ -0,0 +1,18 @@ +namespace Flashcards +{ + internal class Program + { + static void Main(string[] args) + { + //In case of any issues with encoding, this will ensure that the console can handle UTF-8 characters properly. + Console.InputEncoding = System.Text.Encoding.UTF8; + Console.OutputEncoding = System.Text.Encoding.UTF8; + + DatabaseManager databaseManager = new DatabaseManager(); + UserInterface userInterface = new UserInterface(); + + databaseManager.CreateTable(); + userInterface.MainMenu(databaseManager); + } + } +} diff --git a/Dania.Flashcards/UserInterface.cs b/Dania.Flashcards/UserInterface.cs new file mode 100644 index 00000000..a46dcbf7 --- /dev/null +++ b/Dania.Flashcards/UserInterface.cs @@ -0,0 +1,196 @@ +using Flashcards.Controllers; +using Flashcards.Models; + +namespace Flashcards +{ + internal class UserInterface + { + StackController stackController = null; + FlashcardController flashcardController = null; + StudySessionController studySessionController = null; + + internal void MainMenu(DatabaseManager databaseManager) + { + stackController = new StackController(databaseManager); + flashcardController = new FlashcardController(databaseManager); + studySessionController = new StudySessionController(databaseManager, stackController); + + bool isCloseApp = false; + + while (!isCloseApp) + { + Console.Clear(); + Console.WriteLine("---Welcome to Flashcards!---"); + Console.WriteLine("1 - Manage Stacks"); + Console.WriteLine("2 - Manage Flashcards"); + Console.WriteLine("3 - Study Room"); + Console.WriteLine("0 - Exit"); + Console.Write("Please select an option: "); + + string input = Console.ReadLine(); + + switch (input) + { + case "0": + isCloseApp = true; + break; + case "1": + ManageStacks(); + break; + case "2": + ManageFlashcards(); + break; + case "3": + StudySession(); + break; + default: + Console.WriteLine("Invalid option. Please try again."); + Console.ReadLine(); + break; + } + } + + } + + private void ManageStacks() + { + bool isCloseManageStacks = false; + + while (!isCloseManageStacks) + { + Console.Clear(); + Console.WriteLine("---Manage Stacks---"); + Console.WriteLine("1 - Create stacks"); + Console.WriteLine("2 - Delete stacks"); + Console.WriteLine("0 - Return to main menu"); + Console.Write("Please select an option: "); + + string input = Console.ReadLine(); + + switch (input) + { + case "0": + isCloseManageStacks = true; + break; + case "1": + stackController.CreateStack(); + break; + case "2": + stackController.DeleteStack(); + break; + default: + Console.WriteLine("Invalid option. Please try again."); + Console.ReadLine(); + break; + } + + } + } + + private void ManageFlashcards() + { + Stack currentStack = null; + + Console.Clear(); + Console.WriteLine("---Manage Flashcards---"); + + if (stackController.GetStacks() > 0) + { + Console.WriteLine("\nEnter the stack name to manage (Press 0 to return to the main menu):"); + string stackName = Console.ReadLine(); + + if (stackName == "0") return; + + currentStack = stackController.GetStackByName(stackName); + + if (currentStack == null) + { + Console.WriteLine("\nPress Enter to return to the main menu..."); + Console.ReadLine(); + } + } + else + { + Console.WriteLine("\nPress Enter to return to the main menu..."); + Console.ReadLine(); + } + + if (currentStack != null) + { + bool isCloseManageFlashcards = false; + while (!isCloseManageFlashcards) + { + Console.Clear(); + Console.WriteLine($"---Manage Flashcards for Stack: {currentStack.Name}---"); + Console.WriteLine("1 - View flashcards"); + Console.WriteLine("2 - Create flashcards"); + Console.WriteLine("3 - Update flashcards"); + Console.WriteLine("4 - Delete flashcards"); + Console.WriteLine("0 - Return to main menu"); + Console.Write("Please select an option: "); + + string input = Console.ReadLine(); + + switch(input) + { + case "0": + isCloseManageFlashcards = true; + break; + case "1": + flashcardController.ViewFlashcards(currentStack); + break; + case "2": + flashcardController.CreateFlashcards(currentStack); + break; + case "3": + flashcardController.UpdateFlashcards(currentStack); + break; + case "4": + flashcardController.DeleteFlashcards(currentStack); + break; + default: + Console.WriteLine("Invalid option. Please try again."); + Console.ReadLine(); + break; + } + + } + + } + } + + private void StudySession() + { + bool isCloseStudySession = false; + + while (!isCloseStudySession) + { + Console.Clear(); + Console.WriteLine("---Study Room---"); + Console.WriteLine("1 - Start a study session"); + Console.WriteLine("2 - View study session records"); + Console.WriteLine("0 - Return to main menu"); + Console.Write("Please select an option: "); + + string input = Console.ReadLine(); + + switch (input) + { + case "0": + isCloseStudySession = true; + break; + case "1": + studySessionController.PrepareStudySession(); + break; + case "2": + studySessionController.StudySessionRecords(); + break; + default: + Console.WriteLine("Invalid option. Please try again."); + Console.ReadLine(); + break; + } + } + } + } +} diff --git a/Dania.Flashcards/appsettings.json b/Dania.Flashcards/appsettings.json new file mode 100644 index 00000000..a2c8a091 --- /dev/null +++ b/Dania.Flashcards/appsettings.json @@ -0,0 +1,5 @@ +{ + "ConnectionStrings": { + "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=FlashcardsDB;Trusted_Connection=True;" + } +} \ No newline at end of file