Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 23, 2025 15:42
Show Gist options
  • Select an option

  • Save Strelok78/6ef9526e4b1c4b93fb2c6f6960bbc8c1 to your computer and use it in GitHub Desktop.

Select an option

Save Strelok78/6ef9526e4b1c4b93fb2c6f6960bbc8c1 to your computer and use it in GitHub Desktop.
HR app
using System.Collections;
using System.Diagnostics;
using System.Text;
namespace iJuniorPractice;
class Program
{
static void Main(string[] args)
{
const int AddWorkerCommand = 1;
const int RemoveWorkerCommand = 2;
const int GetWorkersOnPositionCommand = 3;
const int GetAllRecordsCommand = 4;
const int ExitCommand = 5;
Dictionary<string, List<string>> humanResourceRecords = new Dictionary<string, List<string>>()
{
{"developer", new List<string>()
{
"Ivan Ivania Petrovich"
}
},
{"manager", new List<string>()
{
"Ivan Vaia Petrovich",
"Sergei Serg Sergeevich"
}
}
};
bool isHire = true;
int command;
while (isHire)
{
Console.WriteLine($"To add worker press - {AddWorkerCommand}\n" +
$"To remove worker from list press - {RemoveWorkerCommand}\n" +
$"To get workers list per position press - {GetWorkersOnPositionCommand}\n" +
$"To get full list of positions and workers press - {GetAllRecordsCommand}\n" +
$"To exit press - {ExitCommand}");
command = ReadInt();
switch (command)
{
case AddWorkerCommand:
AddNewWorker(humanResourceRecords);
break;
case GetWorkersOnPositionCommand:
WriteWorkersPerPosition(humanResourceRecords);
break;
case RemoveWorkerCommand:
RemoveWorker(humanResourceRecords);
break;
case GetAllRecordsCommand:
WriteAllHRRecords(humanResourceRecords);
break;
case ExitCommand:
isHire = false;
Console.WriteLine("Goodbye!");
break;
default:
Console.WriteLine("Unknown command.");
break;
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.Clear();
}
}
static void AddNewWorker(Dictionary<string, List<string>> humanResourceRecords)
{
string worker;
string position;
WritePositionInCompany(humanResourceRecords);
Console.Write("Enter worker name surname and patronomic: ");
worker = ReadWorkerFullName();
Console.Write("Enter worker position: ");
position = Console.ReadLine();
position.ToLower();
if (humanResourceRecords.ContainsKey(position) == false)
{
humanResourceRecords.Add(position, new List<string>());
}
humanResourceRecords[position].Add(worker);
}
static void RemoveWorker(Dictionary<string, List<string>> humanResourceRecords)
{
int workerId;
string position;
WritePositionInCompany(humanResourceRecords);
Console.Write("Enter position: ");
position = ReadPosition();
if (humanResourceRecords.ContainsKey(position))
{
Console.WriteLine("Position found");
WriteWorkersPerPosition(humanResourceRecords, position);
Console.Write("Enter worker id to remove:");
workerId = ReadInt();
if (humanResourceRecords[position].Count > workerId)
{
humanResourceRecords[position].RemoveAt(workerId);
if (humanResourceRecords[position].Count <= 0)
{
humanResourceRecords.Remove(position);
}
}
else
{
Console.WriteLine("No such worker");
}
}
else
{
Console.WriteLine("No such position.");
}
}
static void WriteAllHRRecords(Dictionary<string, List<string>> humanResourceRecords)
{
foreach (var position in humanResourceRecords.Keys)
{
Console.WriteLine($"{position}: ");
for (int i = 0; i < humanResourceRecords.Count; i++)
{
Console.WriteLine($"id {i} - {humanResourceRecords[position][i]}");
}
}
}
static void WriteWorkersPerPosition(Dictionary<string, List<string>> humanResourceRecords, string position = null)
{
if (position == null)
{
WritePositionInCompany(humanResourceRecords);
Console.Write("Enter position: ");
position = ReadPosition();
}
Console.WriteLine("Workers list:");
if (humanResourceRecords.ContainsKey(position))
{
for (int i = 0; i < humanResourceRecords.Count; i++)
{
Console.WriteLine($"id {i} - {humanResourceRecords[position][i]}");
}
}
else
{
Console.WriteLine("No such position found.");
}
}
static void WritePositionInCompany(Dictionary<string, List<string>> humanResourceRecords)
{
Console.WriteLine("Positions in company: ");
foreach (var position in humanResourceRecords.Keys)
{
Console.WriteLine(position);
}
}
static int ReadInt()
{
string input = Console.ReadLine();
int digit;
while (int.TryParse(input, out digit) == false)
{
Console.WriteLine("Error enter digit");
input = Console.ReadLine();
}
return digit;
}
static string ReadWorkerFullName()
{
string name, surname, patronomic, fullName;
Console.WriteLine("Enter Name: ");
name = Console.ReadLine();
Console.WriteLine("Enter Surname: ");
surname = Console.ReadLine();
Console.WriteLine("Enter Patronomic");
patronomic = Console.ReadLine();
fullName = String.Join(" ", name, surname, patronomic);
return fullName;
}
static string ReadPosition()
{
return Console.ReadLine().ToLower();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment