Files
Prog4_Beadando/WD7UVN_HFT_2023241.Client/TUI/NonCRUD.cs

168 lines
5.9 KiB
C#
Raw Normal View History

2023-12-13 22:04:13 +01:00
using System;
2023-12-29 16:02:09 +01:00
using ConsoleTools;
2023-12-13 22:04:13 +01:00
using WD7UVN_HFT_2023241.Models;
namespace WD7UVN_HFT_2023241.Client.TUI
2023-12-13 22:04:13 +01:00
{
public class NonCRUD
{
2023-12-29 16:02:09 +01:00
private static void RESTWhoMaintainsService(int id)
2023-12-13 22:04:13 +01:00
{
var res = RestService.WhoMaintainsService(id);
if (res != null)
2023-12-13 22:04:13 +01:00
{
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
{
2023-12-29 16:02:09 +01:00
Console.WriteLine("ERROR: No such database entry was found :/");
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
2023-12-29 16:02:09 +01:00
}
public static void WhoMaintainsService()
{
var menu = new ConsoleMenu();
2023-12-29 16:02:09 +01:00
foreach (Service s in RestService.Get<Service>("/api/Service"))
{
menu.Add($"{s.NAME}: {s.ID}", () => RESTWhoMaintainsService(s.ID));
2023-12-13 22:04:13 +01:00
}
menu.Add("Back", ConsoleMenu.Close);
menu.Show();
2023-12-13 22:04:13 +01:00
}
private static void RESTWhoUsesService(int id)
2023-12-13 22:04:13 +01:00
{
var res = RestService.WhoUsesService(id);
if (res != null)
2023-12-13 22:04:13 +01:00
{
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 :/");
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
2023-12-13 22:04:13 +01:00
}
public static void WhoUsesService()
2023-12-13 22:04:13 +01:00
{
var menu = new ConsoleMenu();
2023-12-13 22:04:13 +01:00
foreach (Service s in RestService.Get<Service>("/api/Service"))
{
menu.Add($"{s.NAME}: {s.ID}", () => RESTWhoUsesService(s.ID));
2023-12-13 22:04:13 +01:00
}
menu.Add("Back", ConsoleMenu.Close);
menu.Show();
}
2023-12-13 22:04:13 +01:00
private static void RESTWhoIsResponsibleForService(int id)
{
2023-12-13 22:04:13 +01:00
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 :/");
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
2023-12-13 22:04:13 +01:00
}
public static void WhoIsResponsibleForService()
2023-12-13 22:04:13 +01:00
{
var menu = new ConsoleMenu();
foreach (Service s in RestService.Get<Service>("/api/Service"))
2023-12-13 22:04:13 +01:00
{
menu.Add($"{s.NAME}: {s.ID}", () => RESTWhoIsResponsibleForService(s.ID));
2023-12-13 22:04:13 +01:00
}
menu.Add("Back", ConsoleMenu.Close);
menu.Show();
}
2023-12-13 22:04:13 +01:00
private static void RESTGetSubordinates(int id)
{
var res = RestService.GetSubordinates(id);
if (res != null)
2023-12-13 22:04:13 +01:00
{
foreach (Employee e in res)
{
Console.WriteLine("Name: " + e.NAME);
2023-12-13 22:04:13 +01:00
Console.WriteLine("ID: " + e.ID);
Console.WriteLine("Email: " + e.EMAIL);
Console.WriteLine("Phone: " + e.PHONE);
Console.WriteLine("Manager's ID: " + e.MANAGER_ID);
2023-12-13 22:04:13 +01:00
}
}
else
{
Console.WriteLine("No such database entry was found :/");
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
2023-12-13 22:04:13 +01:00
}
public static void GetSubordinates()
2023-12-13 22:04:13 +01:00
{
var menu = new ConsoleMenu();
foreach (Employee e in RestService.Get<Employee>("/api/Employee"))
2023-12-13 22:04:13 +01:00
{
menu.Add($"{e.NAME}: {e.ID}", () => RESTGetSubordinates(e.ID));
2023-12-13 22:04:13 +01:00
}
menu.Add("Back", ConsoleMenu.Close);
menu.Show();
}
2023-12-13 22:04:13 +01:00
private static void RESTWhoWorksInMaintainerTeam(int id)
{
var res = RestService.WhoWorksInMaintainerTeam(id);
if (res != null)
2023-12-13 22:04:13 +01:00
{
foreach (Employee e in res)
2023-12-13 22:04:13 +01:00
{
Console.WriteLine("Name: " + e.NAME);
2023-12-13 22:04:13 +01:00
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 :/");
}
Console.WriteLine("\nPress any key to continue.");
Console.ReadKey();
}
public static void WhoWorksInMaintainerTeam()
{
var menu = new ConsoleMenu();
foreach(MaintainerTeam m in RestService.Get<MaintainerTeam>("/api/MaintainerTeam"))
{
Console.WriteLine("Team name: " + m.NAME);
Console.WriteLine("ID: " + m.ID + "\n\n");
menu.Add($"{m.NAME}: {m.ID}", () => RESTWhoWorksInMaintainerTeam(m.ID));
}
menu.Add("Back", ConsoleMenu.Close);
menu.Show();
2023-12-13 22:04:13 +01:00
}
}
}