Skip to content

Commit

Permalink
Teacher and Student Update profile feature created
Browse files Browse the repository at this point in the history
  • Loading branch information
RubaiyadNoorShahriar1999 committed Dec 31, 2022
1 parent fe068aa commit 8aaf73e
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 6 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified AttendanceSystem/.vs/AttendanceSystem/v17/.futdcache.v2
Binary file not shown.
Binary file modified AttendanceSystem/.vs/AttendanceSystem/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
24 changes: 22 additions & 2 deletions AttendanceSystem/AttendanceSystem/HomePages/StudentPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static void StudentOption(Student student)
{
while(true)
{

int i = 0;
Console.WriteLine("\n\t\t\t\tWelcome to your Student Portal " + student.Name);
Console.Write("Services:\n1. Give your Attendance\n2. View your attendance sheet\n3. Logout\nEnter option: ");
Console.Write("Services:\n1. Give your Attendance\n2. View your attendance sheet\n3. Update profile\n4. Logout\nEnter option: ");

int choice = int.Parse(Console.ReadLine().Replace(@"\s", ""));

Expand Down Expand Up @@ -86,6 +86,26 @@ public static void StudentOption(Student student)
}
}
else if (choice == 3)
{
Student student1 = new Student();
student1.Id = student.Id;
student1.UserName = student.UserName;
student1.Password = student.Password;
if(i == 0)
{
bool entity = new StudentServices().UpdateProfile(student1);
if (entity)
{
i++;
Console.WriteLine("Successfully Updated");
}
}
else
{
Console.WriteLine("You need to re-login for further update.");
}
}
else if (choice == 4)
{
break;
}
Expand Down
26 changes: 23 additions & 3 deletions AttendanceSystem/AttendanceSystem/HomePages/TeacherPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static void TeacherOption(Teacher teacher)
{
while (true)
{

int i = 0;
Console.WriteLine("\n\t\t\t\tWelcome to your Portal: " + teacher.Name);
Console.Write("Services:\n1. See attendance list of all students\n2. See attendance of students course wise\n3. See attendance of students Student ID wise\n4. View my courses\n5. Logout\nEnter option: ");
Console.Write("Services:\n1. See attendance list of all students\n2. See attendance of students course wise\n3. See attendance of students Student ID wise\n4. View my courses\n5. Update profile\n6. Logout\nEnter option: ");
int choice = int.Parse(Console.ReadLine().Replace(@"\s", ""));

if (choice == 1)
Expand Down Expand Up @@ -55,7 +55,27 @@ public static void TeacherOption(Teacher teacher)
course.TeacherId = int.Parse(Console.ReadLine().Replace(@"\s", ""));
bool c = new TeacherServices().ViewCourses(course);
}
else if (choice == 5)
else if(choice == 5)
{
Teacher teacher1 = new Teacher();
teacher1.Id = teacher.Id;
teacher1.UserName = teacher.UserName;
teacher1.Password = teacher.Password;
if (i == 0)
{
bool entity = new TeacherServices().Update(teacher1);
if (entity)
{
i++;
Console.WriteLine("Successfully Updated");
}
}
else
{
Console.WriteLine("You need to re-login for further update.");
}
}
else if (choice == 6)
{
break;
}
Expand Down
46 changes: 46 additions & 0 deletions AttendanceSystem/AttendanceSystem/Services/StudentServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,52 @@ public bool Update(Student type)
return db.SaveChanges() > 0;
}

public bool UpdateProfile(Student type)
{
Student student = db.Students.Where(x => x.Id == type.Id).FirstOrDefault();
if (student != null)
{
Console.WriteLine("Update options: 1. Update username 2. Update password");
Console.Write("Enter your choice: ");
int choice = int.Parse(Console.ReadLine().Replace(@"\s", ""));
if (choice == 1)
{
Console.Write("\nEnter new username: ");
student.UserName = Console.ReadLine();
if (student.UserName == type.UserName)
{
Console.WriteLine("You're previous username was same. Please Enter a new username.");
return false;
}
else
{
return db.SaveChanges() > 0;
}
}
else if (choice == 2)
{
Console.Write("\nEnter your new password: ");
student.Password = Console.ReadLine();
if (student.Password == type.Password)
{
Console.WriteLine("You're previous password was same. Please Enter a new password.");
return false;
}
else
{
return db.SaveChanges() > 0;
}
}
else
return false;
}
else
{
Console.WriteLine("Student ID doesn't exist");
return false;
}
}

public List<Student> GetStudentByTeacherId(int id)
{
return db.Students.Where(s => s.TeacherId == id).ToList();
Expand Down
43 changes: 42 additions & 1 deletion AttendanceSystem/AttendanceSystem/Services/TeacherServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,48 @@ public List<Teacher> Read()

public bool Update(Teacher type)
{
throw new NotImplementedException();
Teacher teacher = db.Teachers.Where(x => x.Id== type.Id).FirstOrDefault();
if (teacher != null)
{
Console.WriteLine("Update options: 1. Update username 2. Update password");
Console.Write("Enter your choice: ");
int choice = int.Parse(Console.ReadLine().Replace(@"\s", ""));
if (choice == 1)
{
Console.Write("\nEnter new username: ");
teacher.UserName = Console.ReadLine();
if (teacher.UserName == type.UserName)
{
Console.WriteLine("You're previous username was same. Please Enter a new username.");
return false;
}
else
{
return db.SaveChanges() > 0;
}
}
else if (choice == 2)
{
Console.Write("\nEnter your new password: ");
teacher.Password = Console.ReadLine();
if (teacher.Password == type.Password)
{
Console.WriteLine("You're previous password was same. Please Enter a new password.");
return false;
}
else
{
return db.SaveChanges() > 0;
}
}
else
return false;
}
else
{
Console.WriteLine("Teacher ID doesn't exist");
return false;
}
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 8aaf73e

Please sign in to comment.