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

Batch25 inheritance and interface #7

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions Batch25/Assignments/ClassComment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The project assignment given in class is due for submission on Wednesday and will be used to evaluate the students' performance. However, it has been observed that one of the students(Hassan) is struggling to understand the concepts and is finding it difficult to keep up.
5 changes: 5 additions & 0 deletions Batch25/Assignments/assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
We developed a console-based registration portal for CLH, and the code has been zipped and shared in the Batch 25 WhatsApp group.
Students are expected to complete and submit it by Wednesday, January 22, 2025. Following this, they will begin working on their personal console applications,
which they will present on Wednesday, January 29, 2025.

https://github.com/codelearnershub/clhRegApp.git
1 change: 1 addition & 0 deletions Batch25/Comments/FridayAndMondayClassComment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The project assignment given in class is due for submission on Wednesday and will be used to evaluate the students' performance. However, it has been observed that one of the students is struggling to understand the concepts and is finding it difficult to keep up.
10 changes: 10 additions & 0 deletions Batch25/LessonMaterials/ClhApp/ClhApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
24 changes: 24 additions & 0 deletions Batch25/LessonMaterials/ClhApp/ClhApp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClhApp", "ClhApp.csproj", "{37C30F2E-8DB5-6FB4-EC6F-107B4BE53CC7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{37C30F2E-8DB5-6FB4-EC6F-107B4BE53CC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37C30F2E-8DB5-6FB4-EC6F-107B4BE53CC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37C30F2E-8DB5-6FB4-EC6F-107B4BE53CC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37C30F2E-8DB5-6FB4-EC6F-107B4BE53CC7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2C9F1BCB-F648-4AAA-9D04-1E325BF6DE99}
EndGlobalSection
EndGlobal
30 changes: 30 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Context/ClhAppContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Models;

namespace ClhApp.Context
{
public class ClhAppContext
{
public static List<Batch> Batches = new List<Batch>()
{
new Batch(1, "Batch 19", DateTime.Parse("20/08/2023")),
new Batch(2, "Batch 20", DateTime.Parse("20/01/2024")),
};
public static List<Guardian> Guardians = new List<Guardian>();
public static List<Instructor> Instructors = new List<Instructor>();
public static List<Stack> Stacks = new List<Stack>()
{
new Stack(1,"C#","dotnet"),
new Stack(2,"python","machine language")
};
public static List<Staff> Staffs = new List<Staff>();
public static List<Student> Students = new List<Student>();
public static List<User> Users = new List<User>()
{
new User(1,"[email protected]","pass","clh_SuperAdmin")
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Context;
using ClhApp.Logic.Interfaces;
using ClhApp.Models;

namespace ClhApp.Logic.Implementations
{
public class GuardianLogic : IGuardianLogic
{
IUserLogic userLogic = new UserLogic();
public bool Create(string email, string password, string firstName, string lastName, string address, string phone)
{
var userExist = userLogic.UserExist(email);
if(userExist)
{
return false;
}

var user = new User(ClhAppContext.Users.Count + 1,email,password,"clh_guardian");
ClhAppContext.Users.Add(user);

var guardian = new Guardian(ClhAppContext.Guardians.Count+1,firstName,lastName,email,address,phone);
ClhAppContext.Guardians.Add(guardian);

return true;
}

public List<Guardian> GetAll()
{
return ClhAppContext.Guardians;
}

public Guardian? GetGuardianByEmail(string email)
{
foreach (Guardian guardian in ClhAppContext.Guardians)
{
if(guardian.Email == email)
{
return guardian;
}
}
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Context;
using ClhApp.Logic.Interfaces;
using ClhApp.Models;

namespace ClhApp.Logic.Implementations
{
public class StudentLogic : IStudentLogic
{
IUserLogic userLogic = new UserLogic();
IGuardianLogic guardianLogic = new GuardianLogic();
public bool Create(string email, string password, int batchId, int stackId, string firstName, string lastName, string address, string phone)
{
var exists = userLogic.UserExist(email);
if(exists)
{
return false;
}
var user = new User(ClhAppContext.Users.Count+1,email,password,"clh_student");


var loginUser = userLogic.GetCurrentLogginUser();
if(loginUser == null)
{
return false;
}
var guardian = guardianLogic.GetGuardianByEmail(loginUser.Email);
if(guardian == null)
{
return false;
}
var student = new Student(ClhAppContext.Students.Count+1,guardian.Id,batchId,stackId,firstName,lastName,GenAdminNum(),email,address,phone);

ClhAppContext.Users.Add(user);
ClhAppContext.Students.Add(student);
return true;
}

private string GenAdminNum()
{
return $"CLHH/{DateTime.Now.Year}/{new Random().Next(1000,9999)}";
}

public void Delete(int id)
{
throw new NotImplementedException();
}

public Student Get(int id)
{
throw new NotImplementedException();
}

public List<Student> GetAll()
{
throw new NotImplementedException();
}

public Student Update(int batchId, int stackId, string firstName, string lastName, string address, string phone)
{
throw new NotImplementedException();
}
}
}
45 changes: 45 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Logic/Implementations/UserLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Context;
using ClhApp.Logic.Interfaces;
using ClhApp.Models;

namespace ClhApp.Logic.Implementations
{
public class UserLogic : IUserLogic
{
public static User? CurrentUser = null;

public User? GetCurrentLogginUser()
{
return CurrentUser;
}

public User? Login(string email, string password)
{
foreach(User user in ClhAppContext.Users)
{
if(user.Email == email && user.Password == password)
{
CurrentUser = user;
return user;
}
}
return null;
}

public bool UserExist(string email)
{
foreach (var user in ClhAppContext.Users)
{
if(user.Email == email)
{
return true;
}
}
return false;
}
}
}
17 changes: 17 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Logic/Interfaces/IBatchLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Models;

namespace ClhApp.Logic.Interfaces
{
public interface IBatchLogic
{
public void Create(string name, DateTime resumptiondate);
public Batch Update(int id, DateTime resumptiondate);
public Batch? Get(int id);
public List<Batch> GetAll();
public void Delete(int id);
}
}
15 changes: 15 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Logic/Interfaces/IGuardianLogic.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.Threading.Tasks;
using ClhApp.Models;

namespace ClhApp.Logic.Interfaces
{
public interface IGuardianLogic
{
public bool Create(string email, string password, string firstName, string lastName, string address, string phone);
public Guardian? GetGuardianByEmail(string email);
public List<Guardian> GetAll();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ClhApp.Logic.Interfaces
{
public interface IInstructorLogic
{
public void Create(int staffId,int stackId);
public void Delete(int id);

}
}
18 changes: 18 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Logic/Interfaces/IStackLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Models;
using Microsoft.VisualBasic.FileIO;

namespace ClhApp.Logic.Interfaces
{
public interface IStackLogic
{
public void Create(string name, string description);
public Stack Update(int id,string name, string description);
public Stack Get(int id);
public List<Stack> GetAll();
public void Delete(int id);
}
}
17 changes: 17 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Logic/Interfaces/IStaffLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Models;

namespace ClhApp.Logic.Interfaces
{
public interface IStaffLogic
{
public void Create(string fn, string ln, string email, string staffNumber, string address, string phone);
public Staff Get(int id);
public List<Staff> GetAll();
public Staff Update(string fn, string ln, string staffNumber, string address, string phone);
public void Delete(int id);
}
}
17 changes: 17 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Logic/Interfaces/IStudentLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ClhApp.Models;

namespace ClhApp.Logic.Interfaces
{
public interface IStudentLogic
{
public bool Create(string email, string password, int batchId, int stackId, string firstName, string lastName, string address,string phone);
public Student Get(int id);
public List<Student> GetAll();
public Student Update(int batchId, int stackId, string firstName, string lastName,string address,string phone);
public void Delete(int id);
}
}
15 changes: 15 additions & 0 deletions Batch25/LessonMaterials/ClhApp/Logic/Interfaces/IUserLogic.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.Threading.Tasks;
using ClhApp.Models;

namespace ClhApp.Logic.Interfaces
{
public interface IUserLogic
{
public User? Login(string email, string password);
public User? GetCurrentLogginUser();
public bool UserExist(string email);
}
}
Loading
Loading