DataManipulator

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MTP_UManager
{
static class DataManipulator
{
// Initializating.
public static Person user;
public static void Login()
{
string username = "",
password = "";
Console.Write("Пользователь: ");
username = Console.ReadLine();
Console.WriteLine();
Console.Write("Пароль: ");
password = Console.ReadLine();
DataGetter.GetLoginedUserFromDatabase(username, password);
}
public static void SetUpCurrentUser(string username) /**/
{
string[] userData = Database.GetTheUserFromDatabase(username,
out List<string> coursesUserTook, out List<string> coursesUserSee, out List<string> coursesUserEnded);
string status = userData[1];
if (status == "student")
{
user = new Student(username, "студент")
{
AvailableCoursesID = coursesUserSee,
TakenCoursesID = coursesUserTook,
FinishedCoursesID = coursesUserEnded
};
}
else if (/*Status is teacher*/ false)
{
//TODO
}
else if (/*Status is rector*/false)
{
//TODO
}
Renderer.RenderMainPage(user);
}
// Main Page Menu.
public static void CheckUserChoiceInMainPageMenu(Student user, string userChoice)
{
switch (userChoice)
{
case "1":
Renderer.RenderCoursesListPage(user);
break;
case "2":
Renderer.RenderStudentStatsPage(user);
break;
case "3":
Quit();
break;
default:
Renderer.RenderMainPageMessage(user);
CheckUserChoiceInMainPageMenu(user, Renderer.RenderMenu(DataGetter.GetMainPageMenuItems()));//
break;
}
}
// Course List Page.
public static void CheckUserChoiceInCoursesListPageMenu(Student user, string userChoice)
{
switch (userChoice)
{
case "1":
Renderer.RenderSignUpForCoursePageMessage(user);
CheckUserChoiceInMainPageMenu(user, Renderer.RenderMenu(DataGetter.GetMainPageMenuItems()));
break;
case "2":
Renderer.RenderLeaveCoursePageMessage(user);
CheckUserChoiceInMainPageMenu(user, Renderer.RenderMenu(DataGetter.GetMainPageMenuItems()));
break;
case "3":
Renderer.RenderMainPageMessage(user);
CheckUserChoiceInMainPageMenu(user, Renderer.RenderMenu(DataGetter.GetMainPageMenuItems()));
break;
default:
Renderer.RenderCoursesListPage(user);
break;
}
}
public static void SignUpForCourse(Student user, string courseID)
{
if ((!user.FinishedCoursesID.Contains(courseID)) && (!user.TakenCoursesID.Contains(courseID)))
user.TakenCoursesID.Add(courseID);
}
public static void LeaveCourse(Student user, string courseID)
{
user.TakenCoursesID.Remove(courseID);
}
public static void Quit()
{
Renderer.RenderLoginPageMessage();
}
// Course Student Stats.
public static void CheckUserChoiceInStudentStatsPageMenu(Student user, string userChoice)
{
switch (userChoice)
{
case "1":
Renderer.RenderStudentStatsPageMessage(user);
CheckUserChoiceInMainPageMenu(user, Renderer.RenderMenu(DataGetter.GetMainPageMenuItems()));
break;
default:
Renderer.RenderStudentStatsPage(user);
break;
}
}
}
}