Implemented a more efficient way to display results
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Reflection;
|
||||||
using ConsoleTools;
|
using ConsoleTools;
|
||||||
using WD7UVN_HFT_2023241.Models;
|
using WD7UVN_HFT_2023241.Models;
|
||||||
|
|
||||||
@@ -6,756 +9,74 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
{
|
{
|
||||||
public class CRUD
|
public class CRUD
|
||||||
{
|
{
|
||||||
private enum Models
|
public delegate void CRUDMethod<T>(T obj);
|
||||||
{
|
|
||||||
Customer,
|
|
||||||
Employee,
|
|
||||||
Service,
|
|
||||||
MaintainerTeam
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void MethodChooser(CRUDActions action, Models model)
|
private static void MethodChooser<T>(CRUDActions action)
|
||||||
{
|
{
|
||||||
switch (model)
|
CRUDMethod<T> method = null;
|
||||||
|
switch (action)
|
||||||
{
|
{
|
||||||
case Models.Customer:
|
case CRUDActions.GetAll:
|
||||||
switch (action)
|
method = View.Display;
|
||||||
{
|
|
||||||
case CRUDActions.GetAll:
|
|
||||||
ReadAll.Customer();
|
|
||||||
break;
|
|
||||||
case CRUDActions.GetById:
|
|
||||||
Read.Customer();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Create:
|
|
||||||
Create.Customer();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Update:
|
|
||||||
Update.Customer();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Delete:
|
|
||||||
Delete.Customer();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Models.Employee:
|
case CRUDActions.GetById:
|
||||||
switch (action)
|
method = View.Display;
|
||||||
{
|
|
||||||
case CRUDActions.GetAll:
|
|
||||||
ReadAll.Employee();
|
|
||||||
break;
|
|
||||||
case CRUDActions.GetById:
|
|
||||||
Read.Employee();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Create:
|
|
||||||
Create.Employee();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Update:
|
|
||||||
Update.Employee();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Delete:
|
|
||||||
Delete.Employee();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Models.Service:
|
case CRUDActions.Create:
|
||||||
switch (action)
|
method = Modify.Create;
|
||||||
{
|
|
||||||
case CRUDActions.GetAll:
|
|
||||||
ReadAll.Service();
|
|
||||||
break;
|
|
||||||
case CRUDActions.GetById:
|
|
||||||
Read.Service();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Create:
|
|
||||||
Create.Service();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Update:
|
|
||||||
Update.Service();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Delete:
|
|
||||||
Delete.Service();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case Models.MaintainerTeam:
|
case CRUDActions.Update:
|
||||||
switch (action)
|
method = Modify.Update;
|
||||||
{
|
break;
|
||||||
case CRUDActions.GetAll:
|
case CRUDActions.Delete:
|
||||||
ReadAll.MaintainerTeam();
|
method = Modify.Delete;
|
||||||
break;
|
|
||||||
case CRUDActions.GetById:
|
|
||||||
Read.MaintainerTeam();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Create:
|
|
||||||
Create.MaintainerTeam();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Update:
|
|
||||||
Update.MaintainerTeam();
|
|
||||||
break;
|
|
||||||
case CRUDActions.Delete:
|
|
||||||
Delete.MaintainerTeam();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ShowMenu<T>(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TypeSelectorMenu(CRUDActions action)
|
public static void TypeSelectorMenu(CRUDActions action)
|
||||||
{
|
{
|
||||||
var menu = new ConsoleMenu();
|
var menu = new ConsoleMenu();
|
||||||
menu.Add("Customer", () => MethodChooser(action, Models.Customer));
|
menu.Add("Customer", () => MethodChooser<Customer>(action));
|
||||||
menu.Add("Employee", () => MethodChooser(action, Models.Employee));
|
menu.Add("Employee", () => MethodChooser<Employee>(action));
|
||||||
menu.Add("Service", () => MethodChooser(action, Models.Service));
|
menu.Add("Service", () => MethodChooser<Service>(action));
|
||||||
menu.Add("Maintainer team", () => MethodChooser(action, Models.MaintainerTeam));
|
menu.Add("Maintainer team", () => MethodChooser<MaintainerTeam>(action));
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
menu.Add("Back", ConsoleMenu.Close);
|
||||||
menu.Show();
|
menu.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
//generic methods are nice and all, but in this instance they would be a pain to implement as they would neccessitate a lot of reflection
|
public static void ShowMenu<T>(CRUDMethod<T> method)
|
||||||
// public static void Read<T>()
|
|
||||||
// {
|
|
||||||
// var menu = new ConsoleMenu();
|
|
||||||
// foreach (T c in RestService.Get<T>("/api/" + typeof(T).Name + "/"))
|
|
||||||
// {
|
|
||||||
// menu.Add($"{c}", () => Console.WriteLine(c));
|
|
||||||
// }
|
|
||||||
// menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
// menu.Show();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Read
|
|
||||||
{
|
|
||||||
private static void RESTCustomer(int id)
|
|
||||||
{
|
{
|
||||||
Customer res = RestService.Get<Customer>(id, "/api/Customer/");
|
var menu = new ConsoleMenu();
|
||||||
if (res != null)
|
|
||||||
|
if (method != Modify.Create && method != View.DisplayAll)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Name: " + res.NAME);
|
foreach (T c in RestService.Get<T>("/api/" + typeof(T).Name + "/"))
|
||||||
Console.WriteLine("ID: " + res.ID);
|
{
|
||||||
Console.WriteLine("Email: " + res.EMAIL);
|
menu.Add($"{c.GetType().GetProperty("NAME").GetValue(c)}: {c.GetType().GetProperty("ID").GetValue(c)}", () => method(c));
|
||||||
Console.WriteLine("Phone: " + res.PHONE);
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("No such database entry was found :/");
|
method(default);
|
||||||
}
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
public static void Customer()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (Customer c in RestService.Get<Customer>("/api/Customer/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTCustomer(c.ID));
|
|
||||||
}
|
}
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
menu.Add("Back", ConsoleMenu.Close);
|
||||||
menu.Show();
|
menu.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RESTEmployee(int id)
|
|
||||||
{
|
|
||||||
Employee res = RestService.Get<Employee>(id, "/api/Employee/");
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Name: " + res.NAME);
|
|
||||||
Console.WriteLine("ID: " + res.ID);
|
|
||||||
Console.WriteLine("Email: " + res.EMAIL);
|
|
||||||
Console.WriteLine("Phone: " + res.PHONE);
|
|
||||||
Console.WriteLine("Maintainer team's ID: " + res.MAINTAINER_ID);
|
|
||||||
Console.WriteLine("Manager's ID: " + res.MANAGER_ID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("No such database entry was found :/");
|
|
||||||
}
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
public static void Employee()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (Employee c in RestService.Get<Employee>("/api/Employee/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTEmployee(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RESTService(int id)
|
|
||||||
{
|
|
||||||
Service res = RestService.Get<Service>(id, "/api/Service/");
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Name: " + res.NAME);
|
|
||||||
Console.WriteLine("ID: " + res.ID);
|
|
||||||
Console.WriteLine("Account: " + res.ACCOUNT);
|
|
||||||
Console.WriteLine("IP: " + res.IP);
|
|
||||||
Console.WriteLine("Port: " + res.PORT);
|
|
||||||
Console.WriteLine("Notes: " + res.NOTES);
|
|
||||||
Console.WriteLine("Service domain: " + res.SERVICE_DOMAIN);
|
|
||||||
Console.WriteLine("Version: " + res.VERSION);
|
|
||||||
Console.WriteLine("Maintainer team's ID: " + res.MAINTAINER_ID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("No such database entry was found :/");
|
|
||||||
}
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
public static void Service()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (Service c in RestService.Get<Service>("/api/Service/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTService(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RESTMaintainerTeam(int id)
|
|
||||||
{
|
|
||||||
MaintainerTeam res = RestService.Get<MaintainerTeam>(id, "/api/MaintainerTeam/");
|
|
||||||
if (res != null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Name: " + res.NAME);
|
|
||||||
Console.WriteLine("ID: " + res.ID);
|
|
||||||
Console.WriteLine("Email: " + res.EMAIL);
|
|
||||||
Console.WriteLine("Leader's ID: " + res.LEADER_ID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("No such database entry was found :/");
|
|
||||||
}
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
public static void MaintainerTeam()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (MaintainerTeam c in RestService.Get<MaintainerTeam>("/api/MaintainerTeam/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTMaintainerTeam(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ReadAll
|
|
||||||
{
|
|
||||||
public static void Customer()
|
|
||||||
{
|
|
||||||
foreach (Customer c in RestService.Get<Customer>("/api/Customer/"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("ID: " + c.ID);
|
|
||||||
Console.WriteLine("Email: " + c.EMAIL);
|
|
||||||
Console.WriteLine("Phone: " + c.PHONE);
|
|
||||||
Console.WriteLine("ID of used service: " + c.SERVICE_ID);
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Employee()
|
|
||||||
{
|
|
||||||
foreach (Employee c in RestService.Get<Employee>("/api/Employee/"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("ID: " + c.ID);
|
|
||||||
Console.WriteLine("Email: " + c.EMAIL);
|
|
||||||
Console.WriteLine("Phone: " + c.PHONE);
|
|
||||||
Console.WriteLine("Maintainer team's ID: " + c.MAINTAINER_ID);
|
|
||||||
Console.WriteLine("Manager's ID: " + c.MANAGER_ID);
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Service()
|
|
||||||
{
|
|
||||||
foreach (Service c in RestService.Get<Service>("/api/Service/"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("ID: " + c.ID);
|
|
||||||
Console.WriteLine("Account: " + c.ACCOUNT);
|
|
||||||
Console.WriteLine("IP: " + c.IP);
|
|
||||||
Console.WriteLine("Port: " + c.PORT);
|
|
||||||
Console.WriteLine("Notes: " + c.NOTES);
|
|
||||||
Console.WriteLine("Service domain: " + c.SERVICE_DOMAIN);
|
|
||||||
Console.WriteLine("Version: " + c.VERSION);
|
|
||||||
Console.WriteLine("Maintainer team's ID: " + c.MAINTAINER_ID);
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void MaintainerTeam()
|
|
||||||
{
|
|
||||||
foreach (MaintainerTeam c in RestService.Get<MaintainerTeam>("/api/MaintainerTeam/"))
|
|
||||||
{
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("ID: " + c.ID);
|
|
||||||
Console.WriteLine("Email: " + c.EMAIL);
|
|
||||||
Console.WriteLine("Leader's ID: " + c.LEADER_ID);
|
|
||||||
Console.WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("\nPress any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Create
|
|
||||||
{
|
|
||||||
public static void Customer()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("ID (integer): ");
|
|
||||||
int id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Email (text): ");
|
|
||||||
string email = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Phone (text): ");
|
|
||||||
string phone = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("ServiceID (integer): ");
|
|
||||||
int service_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Customer c = new Customer()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
EMAIL = email,
|
|
||||||
PHONE = phone,
|
|
||||||
SERVICE_ID = service_id
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Put<Customer>(c, "/api/Customer/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully created Customer with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Employee()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("ID (integer): ");
|
|
||||||
int id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Email (text): ");
|
|
||||||
string email = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Phone (text): ");
|
|
||||||
string phone = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Team ID (integer): ");
|
|
||||||
int maintainer_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Manager's ID (integer): ");
|
|
||||||
int manager_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Employee c = new Employee()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
EMAIL = email,
|
|
||||||
PHONE = phone,
|
|
||||||
MAINTAINER_ID = maintainer_id,
|
|
||||||
MANAGER_ID = manager_id
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Put<Employee>(c, "/api/Employee/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully created Employee with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Service()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("ID (integer): ");
|
|
||||||
int id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Maintainer team's ID (integer): ");
|
|
||||||
int maintainer_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Version (string): ");
|
|
||||||
string version = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("IP (text): ");
|
|
||||||
string ip = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Port (integer): ");
|
|
||||||
int port = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Service account (text): ");
|
|
||||||
string account = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Service domain (text): ");
|
|
||||||
string domain = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Note(s) (text): ");
|
|
||||||
string notes = Console.ReadLine();
|
|
||||||
|
|
||||||
Service c = new Service()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
MAINTAINER_ID = maintainer_id,
|
|
||||||
PORT = port,
|
|
||||||
IP = ip,
|
|
||||||
SERVICE_DOMAIN = domain,
|
|
||||||
ACCOUNT = account,
|
|
||||||
NOTES = notes,
|
|
||||||
VERSION = version
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Put<Service>(c, "/api/Service/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully created Service with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void MaintainerTeam()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("ID (integer): ");
|
|
||||||
int id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Email (text): ");
|
|
||||||
string email = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Leader's ID (integer): ");
|
|
||||||
int leader_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
MaintainerTeam c = new MaintainerTeam()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
LEADER_ID = leader_id,
|
|
||||||
EMAIL = email
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Put<MaintainerTeam>(c, "/api/MaintainerTeam/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully created Team with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Update
|
public class Modify
|
||||||
{
|
{
|
||||||
private static void RESTCustomer(int id)
|
public static void Delete<T>(T c)
|
||||||
{
|
|
||||||
Customer c = RestService.Get<Customer>(id, "/api/Customer/");
|
|
||||||
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("Email: " + c.EMAIL);
|
|
||||||
Console.WriteLine("Phone: " + c.PHONE);
|
|
||||||
Console.WriteLine("ID of used service: " + c.SERVICE_ID);
|
|
||||||
|
|
||||||
Console.WriteLine("Now you can modify these fields, except for the ID.");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Email (text): ");
|
|
||||||
string email = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Phone (text): ");
|
|
||||||
string phone = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("ServiceID (integer): ");
|
|
||||||
int service_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
c = new Customer()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
EMAIL = email,
|
|
||||||
PHONE = phone,
|
|
||||||
SERVICE_ID = service_id
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Post<Customer>(c, "/api/Customer/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully updated Customer with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void Customer()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (Customer c in RestService.Get<Customer>("/api/Customer/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTCustomer(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RESTEmployee(int id)
|
|
||||||
{
|
|
||||||
Employee c = RestService.Get<Employee>(id, "/api/Employee/");
|
|
||||||
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("Email: " + c.EMAIL);
|
|
||||||
Console.WriteLine("Phone: " + c.PHONE);
|
|
||||||
Console.WriteLine("Maintainer team's ID: " + c.MAINTAINER_ID);
|
|
||||||
Console.WriteLine("Manager's ID: " + c.MANAGER_ID);
|
|
||||||
|
|
||||||
Console.WriteLine("Now you can modify these fields, except for the ID.");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Email (text): ");
|
|
||||||
string email = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Phone (text): ");
|
|
||||||
string phone = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Team ID (integer): ");
|
|
||||||
int maintainer_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Manager's ID (integer): ");
|
|
||||||
int manager_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
c = new Employee()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
EMAIL = email,
|
|
||||||
PHONE = phone,
|
|
||||||
MANAGER_ID = manager_id,
|
|
||||||
MAINTAINER_ID = maintainer_id
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Post<Employee>(c, "/api/Employee/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully updated Employee with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void Employee()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (Employee c in RestService.Get<Employee>("/api/Employee/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTEmployee(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RESTService(int id)
|
|
||||||
{
|
|
||||||
Service c = RestService.Get<Service>(id, "/api/Service/");
|
|
||||||
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("ID: " + c.ID);
|
|
||||||
Console.WriteLine("Account: " + c.ACCOUNT);
|
|
||||||
Console.WriteLine("IP: " + c.IP);
|
|
||||||
Console.WriteLine("Port: " + c.PORT);
|
|
||||||
Console.WriteLine("Notes: " + c.NOTES);
|
|
||||||
Console.WriteLine("Service domain: " + c.SERVICE_DOMAIN);
|
|
||||||
Console.WriteLine("Version: " + c.VERSION);
|
|
||||||
Console.WriteLine("Maintainer team's ID: " + c.MAINTAINER_ID);
|
|
||||||
|
|
||||||
Console.WriteLine("Now you can modify these fields, except for the ID.");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Maintainer team's ID (integer): ");
|
|
||||||
int maintainer_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Version (string): ");
|
|
||||||
string version = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("IP (text): ");
|
|
||||||
string ip = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Port (integer): ");
|
|
||||||
int port = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
Console.Write("Service account (text): ");
|
|
||||||
string account = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Service domain (text): ");
|
|
||||||
string domain = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Note(s) (text): ");
|
|
||||||
string notes = Console.ReadLine();
|
|
||||||
|
|
||||||
c = new Service()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
MAINTAINER_ID = maintainer_id,
|
|
||||||
PORT = port,
|
|
||||||
IP = ip,
|
|
||||||
SERVICE_DOMAIN = domain,
|
|
||||||
ACCOUNT = account,
|
|
||||||
NOTES = notes,
|
|
||||||
VERSION = version
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Post<Service>(c, "/api/Service/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully updated Service with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void Service()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (Service c in RestService.Get<Service>("/api/Service/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTService(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RESTMaintainerTeam(int id)
|
|
||||||
{
|
|
||||||
MaintainerTeam c = RestService.Get<MaintainerTeam>(id, "/api/MaintainerTeam/");
|
|
||||||
|
|
||||||
Console.WriteLine("Name: " + c.NAME);
|
|
||||||
Console.WriteLine("ID: " + c.ID);
|
|
||||||
Console.WriteLine("Email: " + c.EMAIL);
|
|
||||||
Console.WriteLine("Leader's ID: " + c.LEADER_ID);
|
|
||||||
|
|
||||||
Console.WriteLine("Now you can modify these fields, except for the ID.");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Console.Write("Name (text): ");
|
|
||||||
string name = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Email (text): ");
|
|
||||||
string email = Console.ReadLine();
|
|
||||||
|
|
||||||
Console.Write("Leader's ID (integer): ");
|
|
||||||
int leader_id = Convert.ToInt32(Console.ReadLine());
|
|
||||||
|
|
||||||
c = new MaintainerTeam()
|
|
||||||
{
|
|
||||||
ID = id,
|
|
||||||
NAME = name,
|
|
||||||
LEADER_ID = leader_id,
|
|
||||||
EMAIL = email
|
|
||||||
};
|
|
||||||
|
|
||||||
RestService.Post<MaintainerTeam>(c, "/api/MaintainerTeam/");
|
|
||||||
|
|
||||||
Console.WriteLine("\nSuccessfully updated Team with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (FormatException)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Invalid format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void MaintainerTeam()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (MaintainerTeam c in RestService.Get<MaintainerTeam>("/api/MaintainerTeam/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTMaintainerTeam(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Delete
|
|
||||||
{
|
|
||||||
private static void RESTCustomer(int id)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RestService.Delete(id, "/api/Customer/");
|
int key = (int)c.GetType().GetProperty("ID").GetValue(c);
|
||||||
Console.WriteLine("Successfully deleted Customer with ID {0}", id);
|
|
||||||
|
RestService.Delete(key, "/api/" + typeof(T).Name + "/");
|
||||||
|
Console.WriteLine("Successfully deleted {0} with ID {1}", typeof(T).Name, key);
|
||||||
Console.WriteLine("Press any key to continue.");
|
Console.WriteLine("Press any key to continue.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
@@ -767,99 +88,118 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void Customer()
|
|
||||||
|
public static void Update<T>(T item)
|
||||||
{
|
{
|
||||||
var menu = new ConsoleMenu();
|
View.Display(item);
|
||||||
foreach (Customer c in RestService.Get<Customer>("/api/Customer/"))
|
Console.WriteLine("Now you can modify these fields, except for the ID.");
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTCustomer(c.ID));
|
foreach (PropertyInfo p in item.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
if (p.Name != "ID")
|
||||||
|
{
|
||||||
|
Console.Write(p.Name + " (" + p.PropertyType.Name + "): ");
|
||||||
|
string input = Console.ReadLine();
|
||||||
|
if (p.PropertyType.Name == "Int32")
|
||||||
|
{
|
||||||
|
p.SetValue(item, Convert.ToInt32(input));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p.SetValue(item, input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RestService.Post<T>(item, "/api/" + typeof(T).Name + "/");
|
||||||
|
|
||||||
|
Console.WriteLine("\nSuccessfully updated {0} with ID {1}", typeof(T).Name, item.GetType().GetProperty("ID").GetValue(item));
|
||||||
|
Console.WriteLine("Press any key to continue.");
|
||||||
|
Console.ReadKey();
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
}
|
}
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RESTEmployee(int id)
|
public static void Create<T>(T? dummy = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RestService.Delete(id, "/api/Employee/");
|
T item = (T)Activator.CreateInstance(typeof(T));
|
||||||
Console.WriteLine("Successfully deleted Employee with ID {0}", id);
|
|
||||||
|
Console.WriteLine("Please supply all neccessary fields!");
|
||||||
|
|
||||||
|
foreach (PropertyInfo p in item.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
Console.Write(p.Name + " (" + p.PropertyType.Name + "): ");
|
||||||
|
string input = Console.ReadLine();
|
||||||
|
if (p.PropertyType.Name == "Int32")
|
||||||
|
{
|
||||||
|
p.SetValue(item, Convert.ToInt32(input));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p.SetValue(item, input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RestService.Put<T>(item, "/api/" + typeof(T).Name + "/");
|
||||||
|
|
||||||
|
Console.WriteLine("\nSuccessfully created {0} with ID {1}", typeof(T).Name, item.GetType().GetProperty("ID").GetValue(item));
|
||||||
Console.WriteLine("Press any key to continue.");
|
Console.WriteLine("Press any key to continue.");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (FormatException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("The following error occured:");
|
Console.WriteLine("Invalid format!");
|
||||||
Console.WriteLine(e.Message);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void Employee()
|
}
|
||||||
|
|
||||||
|
internal class View
|
||||||
|
{
|
||||||
|
internal static void Display<T>(T c)
|
||||||
{
|
{
|
||||||
var menu = new ConsoleMenu();
|
if (c != null)
|
||||||
foreach (Employee c in RestService.Get<Employee>("/api/Employee/"))
|
|
||||||
{
|
{
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTEmployee(c.ID));
|
foreach (PropertyInfo p in c.GetType().GetProperties())
|
||||||
|
{
|
||||||
|
Console.WriteLine(p.Name + ": " + p.GetValue(c));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
else
|
||||||
menu.Show();
|
{
|
||||||
|
Console.WriteLine("No such database entry was found :/");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("\nPress any key to continue.");
|
||||||
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RESTService(int id)
|
internal static void DisplayAll<T>(T? dummy = default)
|
||||||
{
|
{
|
||||||
try
|
var items = RestService.Get<T>("/api/" + typeof(T).Name + "/");
|
||||||
|
if (items != null)
|
||||||
{
|
{
|
||||||
RestService.Delete(id, "/api/Service/");
|
foreach (T item in items)
|
||||||
Console.WriteLine("Successfully deleted Service with ID {0}", id);
|
{
|
||||||
Console.WriteLine("Press any key to continue.");
|
foreach (PropertyInfo p in item.GetType().GetProperties())
|
||||||
Console.ReadKey();
|
{
|
||||||
|
Console.WriteLine(p.Name + ": " + p.GetValue(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("The following error occured:");
|
Console.WriteLine("No such database entry was found :/");
|
||||||
Console.WriteLine(e.Message);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
public static void Service()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (Service c in RestService.Get<Service>("/api/Service/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTService(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RESTMaintainerTeam(int id)
|
Console.WriteLine("\nPress any key to continue.");
|
||||||
{
|
Console.ReadKey();
|
||||||
try
|
|
||||||
{
|
|
||||||
RestService.Delete(id, "/api/MaintainerTeam/");
|
|
||||||
Console.WriteLine("Successfully deleted MaintainerTeam with ID {0}", id);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("The following error occured:");
|
|
||||||
Console.WriteLine(e.Message);
|
|
||||||
Console.WriteLine("Press any key to continue.");
|
|
||||||
Console.ReadKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static void MaintainerTeam()
|
|
||||||
{
|
|
||||||
var menu = new ConsoleMenu();
|
|
||||||
foreach (MaintainerTeam c in RestService.Get<MaintainerTeam>("/api/MaintainerTeam/"))
|
|
||||||
{
|
|
||||||
menu.Add($"{c.NAME}: {c.ID}", () => RESTMaintainerTeam(c.ID));
|
|
||||||
}
|
|
||||||
menu.Add("Back", ConsoleMenu.Close);
|
|
||||||
menu.Show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user