Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

234 users #250

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions app/DbContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;

using Lms.Models;
using lms.models;

namespace Lms;

Expand All @@ -22,6 +23,8 @@ public class LmsDbContext : Microsoft.EntityFrameworkCore.DbContext
{

// DB Sets (Tables in Database)

public DbSet<User> Users { get; set; }
public DbSet<Models.Progress> Progresses { get; set; }
public DbSet<Models.WorkItem> WorkItems { get; set; }
public DbSet<Block> Blockers { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions app/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Dynamic;
using Lms;

// Initialize the parser
CommandLineParser parser = new CommandLineParser();

((Noun noun, Verb verb), string[] commandArgs) = parser.ParseWithArgs(args);
Expand All @@ -22,6 +23,9 @@
// Initialize DBContext
var dbContext = new LmsDbContext();

// Initialize UserManager
var userManager = new UserManager();

switch (noun)
{
case Noun.Invalid:
Expand Down
57 changes: 57 additions & 0 deletions app/UserManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using lms.models;


public class UserManager
{
// Properties
private const string DELIMITER = "|";
private const string ActiveUserFilePath = "activeUser.txt"; // Path to Active User File
public User? ActiveUser { get; set; } // Active User

public UserManager()
{
// Create Active User File if not exists
if (!File.Exists(ActiveUserFilePath))
{
File.Create(ActiveUserFilePath);
}
else
{
FetchActiveUser();
}
}

// Get Active User from File
public void FetchActiveUser()
{
using(StreamReader sr = new StreamReader(ActiveUserFilePath))
{
string userString = sr.ReadLine();
ActiveUser = ParseUser(userString);
}
}

// Update/Change Active User (Store Active User to the File)
public void UpdateActiveUser(User user)
{
ActiveUser = user;
using (StreamWriter sw = new StreamWriter(ActiveUserFilePath, false)) // Overwrites the file
{
sw.WriteLine(ComposeUser(user));
}
}

// Compose User
public string ComposeUser(User user)
{
return $"{user.Id}{DELIMITER}{user.Username}";
}

// Parse User
public User ParseUser(string userString)
{
string[] userProps = userString.Split(DELIMITER);
return new User { Id = int.Parse(userProps[0]), Username = userProps[1] };
}
}

15 changes: 15 additions & 0 deletions app/models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lms.models
{
public class User
{
// Fields
public int Id { get; set; }
public string Username { get; set; }
}
}