Client created
This commit is contained in:
778
WD7UVN_HFT_2023241.Client/CRUD.cs
Normal file
778
WD7UVN_HFT_2023241.Client/CRUD.cs
Normal file
@@ -0,0 +1,778 @@
|
|||||||
|
using System;
|
||||||
|
using WD7UVN_HFT_2023241.Models;
|
||||||
|
|
||||||
|
namespace WD7UVN_HFT_2023241.Client
|
||||||
|
{
|
||||||
|
public class Read
|
||||||
|
{
|
||||||
|
public static void Customer()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the customer's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Customer c = RestService.Get<Customer>(input, "/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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Employee()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the employee's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Employee c = RestService.Get<Employee>(input, "/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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Service()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the service's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Service c = RestService.Get<Service>(input, "/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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MaintainerTeam()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the team's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MaintainerTeam c = RestService.Get<MaintainerTeam>(input, "/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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ReadAll
|
||||||
|
{
|
||||||
|
public static void Customer()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Employee()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Service()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MaintainerTeam()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Create
|
||||||
|
{
|
||||||
|
public static void Customer()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Employee()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Service()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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 (integer): ");
|
||||||
|
int version = Convert.ToInt32(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");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MaintainerTeam()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Update
|
||||||
|
{
|
||||||
|
public static void Customer()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the customer's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Customer c = RestService.Get<Customer>(input, "/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.");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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 = input,
|
||||||
|
NAME = name,
|
||||||
|
EMAIL = email,
|
||||||
|
PHONE = phone,
|
||||||
|
SERVICE_ID = service_id
|
||||||
|
};
|
||||||
|
|
||||||
|
RestService.Post<Customer>(c, "/api/Customer");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Employee()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the employee's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Employee c = RestService.Get<Employee>(input, "/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("Now you can modify these fields, except for the ID.");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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 = input,
|
||||||
|
NAME = name,
|
||||||
|
EMAIL = email,
|
||||||
|
PHONE = phone,
|
||||||
|
MANAGER_ID = manager_id,
|
||||||
|
MAINTAINER_ID = maintainer_id
|
||||||
|
};
|
||||||
|
|
||||||
|
RestService.Post<Employee>(c, "/api/Employee");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Service()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the service's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Service c = RestService.Get<Service>(input, "/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.");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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 (integer): ");
|
||||||
|
int version = Convert.ToInt32(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 = input,
|
||||||
|
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");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MaintainerTeam()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the service's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MaintainerTeam c = RestService.Get<MaintainerTeam>(input, "/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.");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
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 = input,
|
||||||
|
NAME = name,
|
||||||
|
LEADER_ID = leader_id,
|
||||||
|
EMAIL = email
|
||||||
|
};
|
||||||
|
|
||||||
|
RestService.Post<MaintainerTeam>(c, "/api/MaintainerTeam");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid format!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Delete
|
||||||
|
{
|
||||||
|
public static void Customer()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the customer's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RestService.Delete(input, "/api/Customer/");
|
||||||
|
Console.WriteLine("Successfully deleted Customer with ID {0}", input);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Uh-oh...");
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Employee()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the employee's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RestService.Delete(input, "/api/Employee/");
|
||||||
|
Console.WriteLine("Successfully deleted Employee with ID {0}", input);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Uh-oh...");
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Service()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the service's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RestService.Delete(input, "/api/Service/");
|
||||||
|
Console.WriteLine("Successfully deleted Service with ID {0}", input);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Uh-oh...");
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void MaintainerTeam()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
int input;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Enter a number for the team's ID: ");
|
||||||
|
input = Convert.ToInt32(Console.ReadLine());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RestService.Delete(input, "/api/MaintainerTeam/");
|
||||||
|
Console.WriteLine("Successfully deleted MaintainerTeam with ID {0}", input);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Uh-oh...");
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
216
WD7UVN_HFT_2023241.Client/NonCRUD.cs
Normal file
216
WD7UVN_HFT_2023241.Client/NonCRUD.cs
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using WD7UVN_HFT_2023241.Models;
|
||||||
|
|
||||||
|
namespace WD7UVN_HFT_2023241.Client
|
||||||
|
{
|
||||||
|
public class NonCRUD
|
||||||
|
{
|
||||||
|
|
||||||
|
public static void WhoMaintainsService()
|
||||||
|
{
|
||||||
|
foreach (Service s in RestService.Get<Service>("/api/Service"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Service: " + s.NAME);
|
||||||
|
Console.WriteLine("ID: " + s.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = 1;
|
||||||
|
bool flag = true;
|
||||||
|
while (flag)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Your choice: ");
|
||||||
|
id = Convert.ToInt32(Console.ReadLine());
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IQueryable<Employee> res = RestService.WhoMaintainsService(id);
|
||||||
|
if (res.Count() != 0)
|
||||||
|
{
|
||||||
|
foreach (Employee e in res)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Név: " + e.NAME);
|
||||||
|
Console.WriteLine("ID: " + e.ID);
|
||||||
|
Console.WriteLine("Email: " + e.EMAIL);
|
||||||
|
Console.WriteLine("Phone: " + e.PHONE);
|
||||||
|
Console.WriteLine("Manager's ID: " + e.MANAGER_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("No such database entry was found :/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WhoUsesService()
|
||||||
|
{
|
||||||
|
foreach (Service s in RestService.Get<Service>("/api/Service"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Service: " + s.NAME);
|
||||||
|
Console.WriteLine("ID: " + s.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = 1;
|
||||||
|
bool flag = true;
|
||||||
|
while (flag)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Your choice: ");
|
||||||
|
id = Convert.ToInt32(Console.ReadLine());
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IQueryable<Customer> res = RestService.WhoUsesService(id);
|
||||||
|
if (res.Count() != 0)
|
||||||
|
{
|
||||||
|
foreach (Customer c in res)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Name: " + c.NAME);
|
||||||
|
Console.WriteLine("ID: " + c.ID);
|
||||||
|
Console.WriteLine("Email: " + c.EMAIL);
|
||||||
|
Console.WriteLine("Phone: " + c.PHONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("No such database entry was found :/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WhoIsResponsibleForService()
|
||||||
|
{
|
||||||
|
foreach (Service s in RestService.Get<Service>("/api/Service"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Service: " + s.NAME);
|
||||||
|
Console.WriteLine("ID: " + s.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = 1;
|
||||||
|
bool flag = true;
|
||||||
|
while (flag)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Your choice: ");
|
||||||
|
id = Convert.ToInt32(Console.ReadLine());
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Employee? res = RestService.WhoIsResponsibleForService(id);
|
||||||
|
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 ID: " + res.MAINTAINER_ID);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("No such database entry was found :/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void GetSubordinates()
|
||||||
|
{
|
||||||
|
foreach (Employee e in RestService.Get<Employee>("/api/Employee"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Name: " + e.NAME);
|
||||||
|
Console.WriteLine("ID: " + e.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = 1;
|
||||||
|
bool flag = true;
|
||||||
|
while (flag)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Your choice: ");
|
||||||
|
id = Convert.ToInt32(Console.ReadLine());
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IQueryable<Employee> res = RestService.GetSubordinates(id);
|
||||||
|
if (res.Count() != 0)
|
||||||
|
{
|
||||||
|
foreach (Employee e in res)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Név: " + e.NAME);
|
||||||
|
Console.WriteLine("ID: " + e.ID);
|
||||||
|
Console.WriteLine("Email: " + e.EMAIL);
|
||||||
|
Console.WriteLine("Phone: " + e.PHONE);
|
||||||
|
Console.WriteLine("Maintainer team ID: " + e.MAINTAINER_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("No such database entry was found :/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WhoWorksInMaintainerTeam()
|
||||||
|
{
|
||||||
|
foreach(MaintainerTeam m in RestService.Get<MaintainerTeam>("/api/MaintainerTeam"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Team name: " + m.NAME);
|
||||||
|
Console.WriteLine("ID: " + m.ID + "\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = 1;
|
||||||
|
bool flag = true;
|
||||||
|
while (flag)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Your choice: ");
|
||||||
|
id = Convert.ToInt32(Console.ReadLine());
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IQueryable<Employee> res = RestService.WhoWorksInMaintainerTeam(id);
|
||||||
|
if (res.Count() != 0)
|
||||||
|
{
|
||||||
|
foreach (Employee e in RestService.WhoWorksInMaintainerTeam(id))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Név: " + e.NAME);
|
||||||
|
Console.WriteLine("ID: " + e.ID);
|
||||||
|
Console.WriteLine("Email: " + e.EMAIL);
|
||||||
|
Console.WriteLine("Phone: " + e.PHONE);
|
||||||
|
Console.WriteLine("Manager's ID: " + e.MANAGER_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("No such database entry was found :/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,62 +1,178 @@
|
|||||||
using System;
|
using System;
|
||||||
using WD7UVN_HFT_2023241.Models;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace WD7UVN_HFT_2023241.Client
|
namespace WD7UVN_HFT_2023241.Client
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
static bool FLAG = true;
|
||||||
|
static RestService rest = new RestService();
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
RestService rest = new RestService();
|
ActionMenuHandler();
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("All employees:\n");
|
static void ActionMenuHandler()
|
||||||
List<Employee> employeeList = rest.Get<Employee>("/api/Employee/");
|
{
|
||||||
foreach (Employee e in employeeList)
|
while (FLAG)
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
int choice = ActionMenu();
|
||||||
e.NAME +
|
if (choice == 6)
|
||||||
": " +
|
{
|
||||||
e.ID
|
NonCRUDMenuHandler();
|
||||||
);
|
}
|
||||||
}
|
else if (choice == 0)
|
||||||
|
{
|
||||||
|
FLAG = false;
|
||||||
|
}
|
||||||
|
else if (1 <= choice && choice <= 5)
|
||||||
|
{
|
||||||
|
switch (TypeSelectorMenu())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
if (choice == 1) { Read.Employee(); }
|
||||||
|
else if (choice == 2) { ReadAll.Employee(); }
|
||||||
|
else if (choice == 3) { Create.Employee(); }
|
||||||
|
else if (choice == 4) { Update.Employee(); }
|
||||||
|
else if (choice == 5) { Delete.Employee(); }
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (choice == 1) { Read.Customer(); }
|
||||||
|
else if (choice == 2) { ReadAll.Customer(); }
|
||||||
|
else if (choice == 3) { Create.Customer(); }
|
||||||
|
else if (choice == 4) { Update.Customer(); }
|
||||||
|
else if (choice == 5) { Delete.Customer(); }
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (choice == 1) { Read.Service(); }
|
||||||
|
else if (choice == 2) { ReadAll.Service(); }
|
||||||
|
else if (choice == 3) { Create.Service(); }
|
||||||
|
else if (choice == 4) { Update.Service(); }
|
||||||
|
else if (choice == 5) { Delete.Service(); }
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (choice == 1) { Read.MaintainerTeam(); }
|
||||||
|
else if (choice == 2) { ReadAll.MaintainerTeam(); }
|
||||||
|
else if (choice == 3) { Create.MaintainerTeam(); }
|
||||||
|
else if (choice == 4) { Update.MaintainerTeam(); }
|
||||||
|
else if (choice == 5) { Delete.MaintainerTeam(); }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("\n\nAll customers:\n");
|
static int TypeSelectorMenu()
|
||||||
List<Customer> customerList = rest.Get<Customer>("/api/Customer/");
|
{
|
||||||
foreach (Customer c in customerList)
|
Console.Clear();
|
||||||
{
|
Console.WriteLine("1.) Employee");
|
||||||
Console.WriteLine(
|
Console.WriteLine("2.) Customer");
|
||||||
c.NAME +
|
Console.WriteLine("3.) Service");
|
||||||
": " +
|
Console.WriteLine("4.) MaintainerTeam");
|
||||||
c.ID
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine("\n\nMaintainer teams:\n");
|
while (true)
|
||||||
List<MaintainerTeam> maintainerTeamList = rest.Get<MaintainerTeam>("/api/MaintainerTeam/");
|
{
|
||||||
foreach (MaintainerTeam m in maintainerTeamList)
|
try
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
Console.Write("Your choice: ");
|
||||||
m.NAME +
|
return Convert.ToInt32(Console.ReadLine());
|
||||||
": " +
|
}
|
||||||
m.ID
|
catch (FormatException)
|
||||||
);
|
{
|
||||||
}
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("\n\nMaintained services:\n");
|
}
|
||||||
List<Service> serviceList = rest.Get<Service>("/api/Service/");
|
|
||||||
foreach (Service s in serviceList)
|
static int ReadMenuHandler()
|
||||||
{
|
{
|
||||||
Console.WriteLine(
|
Console.Clear();
|
||||||
s.NAME +
|
Console.WriteLine("1.) ");
|
||||||
": " +
|
|
||||||
s.ID +
|
while (true)
|
||||||
" -> " +
|
{
|
||||||
s.IP
|
try
|
||||||
+ ":" +
|
{
|
||||||
s.PORT
|
Console.Write("Your choice: ");
|
||||||
);
|
return Convert.ToInt32(Console.ReadLine());
|
||||||
}
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void NonCRUDMenuHandler()
|
||||||
|
{
|
||||||
|
switch (NonCRUDMenu())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
NonCRUD.WhoWorksInMaintainerTeam();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
NonCRUD.GetSubordinates();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
NonCRUD.WhoUsesService();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
NonCRUD.WhoIsResponsibleForService();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
NonCRUD.WhoMaintainsService();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int NonCRUDMenu()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console.WriteLine("1.) Who works in specified maintainer team?");
|
||||||
|
Console.WriteLine("2.) Get manager's subordinates");
|
||||||
|
Console.WriteLine("3.) Which client(s) use(s) specified service?");
|
||||||
|
Console.WriteLine("4.) Who (which manager) is responsible for a specified service?");
|
||||||
|
Console.WriteLine("5.) Get all employees who maintain a specified service");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Your choice: ");
|
||||||
|
return Convert.ToInt32(Console.ReadLine());
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ActionMenu()
|
||||||
|
{
|
||||||
|
Console.Clear();
|
||||||
|
Console.WriteLine("1.) Read");
|
||||||
|
Console.WriteLine("2.) ReadAll");
|
||||||
|
Console.WriteLine("3.) Create");
|
||||||
|
Console.WriteLine("4.) Update");
|
||||||
|
Console.WriteLine("5.) Delete");
|
||||||
|
Console.WriteLine("6.) Non-CRUD");
|
||||||
|
Console.WriteLine("0.) Exit");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Console.Write("Your choice: ");
|
||||||
|
return Convert.ToInt32(Console.ReadLine());
|
||||||
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must enter a number");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Security;
|
using System.Net.Security;
|
||||||
|
using WD7UVN_HFT_2023241.Models;
|
||||||
|
|
||||||
namespace WD7UVN_HFT_2023241.Client
|
namespace WD7UVN_HFT_2023241.Client
|
||||||
{
|
{
|
||||||
class RestService
|
class RestService
|
||||||
{
|
{
|
||||||
HttpClient client;
|
private static HttpClient client;
|
||||||
|
|
||||||
public RestService(string baseurl = "https://localhost:5001", string pingableEndpoint = "/swagger")
|
public RestService(string baseurl = "https://localhost:5001", string pingableEndpoint = "/swagger")
|
||||||
{
|
{
|
||||||
@@ -64,7 +66,7 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> Get<T>(string endpoint)
|
public static List<T> Get<T>(string endpoint)
|
||||||
{
|
{
|
||||||
List<T> items = new List<T>();
|
List<T> items = new List<T>();
|
||||||
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
||||||
@@ -80,7 +82,7 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetSingle<T>(string endpoint)
|
public static T GetSingle<T>(string endpoint)
|
||||||
{
|
{
|
||||||
T item = default(T);
|
T item = default(T);
|
||||||
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
HttpResponseMessage response = client.GetAsync(endpoint).GetAwaiter().GetResult();
|
||||||
@@ -96,7 +98,7 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get<T>(int id, string endpoint)
|
public static T Get<T>(int id, string endpoint)
|
||||||
{
|
{
|
||||||
T item = default(T);
|
T item = default(T);
|
||||||
HttpResponseMessage response = client.GetAsync(endpoint + "/" + id.ToString()).GetAwaiter().GetResult();
|
HttpResponseMessage response = client.GetAsync(endpoint + "/" + id.ToString()).GetAwaiter().GetResult();
|
||||||
@@ -112,7 +114,7 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Post<T>(T item, string endpoint)
|
public static void Post<T>(T item, string endpoint)
|
||||||
{
|
{
|
||||||
HttpResponseMessage response =
|
HttpResponseMessage response =
|
||||||
client.PostAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
client.PostAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
||||||
@@ -125,7 +127,7 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Delete(int id, string endpoint)
|
public static void Delete(int id, string endpoint)
|
||||||
{
|
{
|
||||||
HttpResponseMessage response =
|
HttpResponseMessage response =
|
||||||
client.DeleteAsync(endpoint + "/" + id.ToString()).GetAwaiter().GetResult();
|
client.DeleteAsync(endpoint + "/" + id.ToString()).GetAwaiter().GetResult();
|
||||||
@@ -139,7 +141,7 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Put<T>(T item, string endpoint)
|
public static void Put<T>(T item, string endpoint)
|
||||||
{
|
{
|
||||||
HttpResponseMessage response =
|
HttpResponseMessage response =
|
||||||
client.PutAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
client.PutAsJsonAsync(endpoint, item).GetAwaiter().GetResult();
|
||||||
@@ -153,6 +155,85 @@ namespace WD7UVN_HFT_2023241.Client
|
|||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IQueryable<Employee> WhoWorksInMaintainerTeam(int id)
|
||||||
|
{
|
||||||
|
IQueryable<Employee> item = default(IQueryable<Employee>);
|
||||||
|
HttpResponseMessage response = client.GetAsync("/api/WhoWorksInMaintainerTeam/" + id.ToString()).GetAwaiter().GetResult();
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
item = response.Content.ReadAsAsync<IQueryable<Employee>>().GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||||
|
throw new ArgumentException(error.Msg);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IQueryable<Employee> GetSubordinates(int id)
|
||||||
|
{
|
||||||
|
IQueryable<Employee> item = default(IQueryable<Employee>);
|
||||||
|
HttpResponseMessage response = client.GetAsync("/api/GetSubordinates/" + id.ToString()).GetAwaiter().GetResult();
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
item = response.Content.ReadAsAsync<IQueryable<Employee>>().GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||||
|
throw new ArgumentException(error.Msg);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IQueryable<Customer> WhoUsesService(int id)
|
||||||
|
{
|
||||||
|
IQueryable<Customer> item = default(IQueryable<Customer>);
|
||||||
|
HttpResponseMessage response = client.GetAsync("/api/WhoUsesService/" + id.ToString()).GetAwaiter().GetResult();
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
item = response.Content.ReadAsAsync<IQueryable<Customer>>().GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||||
|
throw new ArgumentException(error.Msg);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Employee WhoIsResponsibleForService(int id)
|
||||||
|
{
|
||||||
|
Employee item = default(Employee);
|
||||||
|
HttpResponseMessage response = client.GetAsync("/api/WhoIsResponsibleForService/" + id.ToString()).GetAwaiter().GetResult();
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
item = response.Content.ReadAsAsync<Employee>().GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||||
|
throw new ArgumentException(error.Msg);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IQueryable<Employee> WhoMaintainsService(int id)
|
||||||
|
{
|
||||||
|
IQueryable<Employee> item = default(IQueryable<Employee>);
|
||||||
|
HttpResponseMessage response = client.GetAsync("/api/WhoMaintainsService/" + id.ToString()).GetAwaiter().GetResult();
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
item = response.Content.ReadAsAsync<IQueryable<Employee>>().GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var error = response.Content.ReadAsAsync<RestExceptionInfo>().GetAwaiter().GetResult();
|
||||||
|
throw new ArgumentException(error.Msg);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public class RestExceptionInfo
|
public class RestExceptionInfo
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user