LootBoxGenerator/LootBoxSimulator/Program.cs
2024-12-17 15:43:34 +03:00

67 lines
1.9 KiB
C#

using System.Reflection.Emit;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Channels;
using LootBoxSimulator.Models.DAO;
RemoteDatabaseContext db = new RemoteDatabaseContext();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("1. Print category");
stringBuilder.AppendLine();
stringBuilder.Append("2. Print rate");
stringBuilder.AppendLine();
stringBuilder.Append("3. Print items");
stringBuilder.AppendLine();
stringBuilder.Append("4. Edit category");
Console.WriteLine(stringBuilder.ToString());
if (!int.TryParse(Console.ReadLine(), out int menuPosition))
{
Console.WriteLine("Please enter a valid number");
return;
}
switch (menuPosition)
{
case 1:
foreach (var categoryDao in db.Categories)
{
Console.WriteLine($"Id: {categoryDao.Id} Name: {categoryDao.Name}");
}
break;
case 2: break;
case 3: ChangeCategory(); break;
default:
Console.WriteLine("Unkown Menu Position");
break;
}
void ChangeCategory()
{
if(!int.TryParse(Console.ReadLine(), out int CategoryID)) return;
String CategoryName = Console.ReadLine();
if(String.IsNullOrEmpty(CategoryName)) return;
var categoryDao = db.Categories.Find(CategoryID);
categoryDao.Name = CategoryName;
db.SaveChanges();
}
void RemoveCategory()
{
Console.WriteLine("Please enter a Category ID to remove");
if(!int.TryParse(Console.ReadLine(), out int CategoryID)) return;
var categoryDao = db.Categories.Find(CategoryID);
db.Categories.Remove(categoryDao);
db.SaveChanges();
}
void AddCategory()
{
Console.WriteLine("Please enter a Category Name for new category");
String CategoryName = Console.ReadLine();
if(String.IsNullOrEmpty(CategoryName)) return;
CategoryDao categoryDao = new CategoryDao();
categoryDao.Name = CategoryName;
db.Categories.Add(categoryDao);
db.SaveChanges();
}