add action remove and add for category

This commit is contained in:
KP9lKk 2024-12-17 15:43:34 +03:00
parent 96db5c9188
commit ee5080f758

View File

@ -40,8 +40,28 @@ void ChangeCategory()
{ {
if(!int.TryParse(Console.ReadLine(), out int CategoryID)) return; if(!int.TryParse(Console.ReadLine(), out int CategoryID)) return;
String CategoryName = Console.ReadLine(); String CategoryName = Console.ReadLine();
if(!String.IsNullOrEmpty(CategoryName)) return; if(String.IsNullOrEmpty(CategoryName)) return;
var categoryDao = db.Categories.Find(CategoryID); var categoryDao = db.Categories.Find(CategoryID);
categoryDao.Name = CategoryName; categoryDao.Name = CategoryName;
db.SaveChanges(); 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();
}