Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Flashcards.Ledana/Controllers/FlashCardController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Flashcards.Ledana.DTOs;
using Flashcards.Ledana.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace Flashcards.Ledana.Controllers
{
internal class FlashCardController
{
internal static void AddFlashCard(FlashCard card)
{
using var db = new FlashcardsContext();
db.Flashcards.Add(card);
db.SaveChanges();
}

internal static void DeleteCard(FlashCard card)
{
using var db = new FlashcardsContext();
db.Flashcards.Remove(card);
db.SaveChanges();
}

internal static List<FlashCardDTO> GetFlashCardDTOs(int id)
{
try
{
using var db = new FlashcardsContext();
var cards = db.Flashcards
.AsEnumerable()
.Where(f => f.StackId == id)
.Select((f, index) => new FlashCardDTO
{
Id = index + 1,
Front = f.Front
})
.ToList();
return cards;
}
catch (Exception e)
{
Console.WriteLine("Query didn't work. " + e.Message);
return [];
}
}

internal static int GetFlashCardNumberPerStack(int id)
{
using var db = new FlashcardsContext();
return db.Flashcards
.Where(f => f.StackId == id)
.Count();
}

internal static List<FlashCard> GetFlashCards(int id)
{
using var db = new FlashcardsContext();
return db.Flashcards
.Where(f => f.StackId == id)
.ToList();
}
}
}
33 changes: 33 additions & 0 deletions Flashcards.Ledana/Controllers/StackController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Flashcards.Ledana.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace Flashcards.Ledana.Controllers
{
internal static class StackController
{
internal static void AddStack(Stack stack)
{
using var db = new FlashcardsContext();
db.Stacks.Add(stack);
db.SaveChanges();
}

internal static void DeleteStack(Stack stack)
{
using var db = new FlashcardsContext();
db.Stacks.Remove(stack);
db.SaveChanges();
}

internal static List<Stack> GetAllStacks()
{
using var db = new FlashcardsContext();
return db.Stacks
.Include(s => s.Flashcards)
.ToList();
}
}
}
57 changes: 57 additions & 0 deletions Flashcards.Ledana/Controllers/StudySessionController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Flashcards.Ledana.DTOs;
using Flashcards.Ledana.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace Flashcards.Ledana.Controllers
{
internal class StudySessionController
{
internal static void AddStudySession(StudySession studySession)
{
try
{
using var db = new FlashcardsContext();
db.StudySessions.Add(studySession);
db.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine("Query didn't work to add study session " + e.Message);
}
}

internal static List<StudySessionDTO> GetSessions()
{
try
{
using var db = new FlashcardsContext();
var sessions = db.StudySessions
.Select(s => new StudySessionDTO
{
StackName = s.FlashCard.Stack.Name,
FrontCard = s.FlashCard.Front,
BackCard = s.FlashCard.Back,
Answer = s.Answer,
Score = s.Score
})
.ToList();
return sessions;
}
catch (Exception e)
{
Console.WriteLine("Query didn't work. " + e.Message);
return [];
}
}

internal static bool ValidateAnswer(int id, string answer)
{
using var db = new FlashcardsContext();
var result = db.Flashcards
.Any(f => f.Id == id && f.Back == answer);
return result;
}
}
}
12 changes: 12 additions & 0 deletions Flashcards.Ledana/DTOs/FlashCardDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Flashcards.Ledana.DTOs
{
internal class FlashCardDTO
{
public int Id { get; set; }
public string Front { get; set; } = null!;
}
}
10 changes: 10 additions & 0 deletions Flashcards.Ledana/DTOs/StudySessionDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Flashcards.Ledana.DTOs;
internal class StudySessionDTO
{
public string StackName { get; set; } = null!;
public DateTime DateTime { get; set; }
public string FrontCard { get; set; } = null!;
public string BackCard { get; set; } = null!;
public string Answer { get; set; } = null!;
public string Score { get; set; } = null!;
}
32 changes: 32 additions & 0 deletions Flashcards.Ledana/Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Flashcards.Ledana
{
internal class Enums
{
internal enum MainMenuOptions
{
ManageStacks,
ManageFlashCards,
Study,
ViewStudySession,
Quit
}
internal enum ManageStacksOptions
{
AddStack,
DeleteStack,
ViewStack,
ViewAllStacks,
GoBack
}
internal enum ManageFlashCardsOptions
{
AddFlashCard,
DeleteFlashCard,
GoBack
}
}
}
24 changes: 24 additions & 0 deletions Flashcards.Ledana/Flashcards.Ledana.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Spectre.Console" Version="0.55.2" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions Flashcards.Ledana/Flashcards.Ledana.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Flashcards.Ledana.csproj" />
</Solution>
16 changes: 16 additions & 0 deletions Flashcards.Ledana/FlashcardsContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Flashcards.Ledana.Models;
using Microsoft.EntityFrameworkCore;

namespace Flashcards.Ledana;

internal class FlashcardsContext : DbContext
{
public DbSet<FlashCard> Flashcards { get; set; }
public DbSet<Stack> Stacks { get; set; }
public DbSet<StudySession> StudySessions { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=FlashCardDb;");
}
}
127 changes: 127 additions & 0 deletions Flashcards.Ledana/Migrations/20260423194041_InitailCreate.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading