diff --git a/KebPOS/DbContexts/KebabContext.cs b/KebPOS/DbContexts/KebabContext.cs index 9e9056d..908b83e 100644 --- a/KebPOS/DbContexts/KebabContext.cs +++ b/KebPOS/DbContexts/KebabContext.cs @@ -13,9 +13,9 @@ internal class KebabContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { // Data source to be replaced with config connection string. - string projPath = Path.GetFullPath(@"C:\\Users\\sipah\\Desktop\\serdar\\projeler\\pointofsle\\CONSOLE.PointOfSale\\KebPOS\\"); - // optionsBuilder.UseSqlite($"C:\\Users\\sipah\\Desktop\\serdar\\projeler\\pointofsle\\CONSOLE.PointOfSale\\KebPOS\\Kebab.db"); - optionsBuilder.UseSqlite($"Data Source=Kebab.db;"); + string projPath = Path.GetFullPath(@"C:\\Users\\sipah\\Desktop\\serdar\\projeler\\pointofsle\\CONSOLE.PointOfSale\\KebPOS\\"); + // optionsBuilder.UseSqlite($"C:\\Users\\sipah\\Desktop\\serdar\\projeler\\pointofsle\\CONSOLE.PointOfSale\\KebPOS\\Kebab.db"); + optionsBuilder.UseSqlite($"Data Source=Kebab.db;"); } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/KebPOS/KebabController.cs b/KebPOS/KebabController.cs index f5639ed..31c2afb 100644 --- a/KebPOS/KebabController.cs +++ b/KebPOS/KebabController.cs @@ -8,7 +8,7 @@ public class KebabController { public void UpdateProductName(Product product, string newProductName) { - using var db = new KebabContext(); + using var db = new KebabContext(); product.Name = newProductName; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); diff --git a/KebPOS/Services/ProductService.cs b/KebPOS/Services/ProductService.cs index c95dd12..02627d6 100644 --- a/KebPOS/Services/ProductService.cs +++ b/KebPOS/Services/ProductService.cs @@ -10,7 +10,7 @@ internal static void InsertProduct() { bool exit = false; bool addNewProduct = true; - + while (addNewProduct) { bool isDuplicate = true; @@ -23,7 +23,7 @@ internal static void InsertProduct() var product = new Product(); product = new Product(); - + while (!nameValid || isDuplicate) { Console.Clear(); diff --git a/KebPOS/UserInterface.cs b/KebPOS/UserInterface.cs index 42cc571..fadeee3 100644 --- a/KebPOS/UserInterface.cs +++ b/KebPOS/UserInterface.cs @@ -134,20 +134,20 @@ internal void ManageReportsMenu() private void UpdateProduct() { var products = _kebabController.GetProducts(); - var productsNameList=products.Select(x => x.Name).ToList(); + var productsNameList = products.Select(x => x.Name).ToList(); var selectedProductName = AnsiConsole.Prompt(new SelectionPrompt(). Title("[Purple]Select product[/]"). AddChoices(productsNameList)); - Product productToUpdate=products.Single(x=> x.Name==selectedProductName); + Product productToUpdate = products.Single(x => x.Name == selectedProductName); var propertyToUpdate = AnsiConsole.Prompt(new SelectionPrompt() - .Title("[Purple]Select property to update[/]") + .Title("[Purple]Select property to update[/]") .AddChoices( ProductProperties.Name, ProductProperties.Description, ProductProperties.Price, ProductProperties.MainMenu)); - switch(propertyToUpdate) + switch (propertyToUpdate) { case ProductProperties.Name: UpdateProductName(productToUpdate); @@ -179,8 +179,19 @@ private void UpdateProductDescription(Product productToUpdate) private void UpdateProductPrice(Product productToUpdate) { - AnsiConsole.Markup($"[Blue]Current price:[/] {productToUpdate.Price}"); - decimal newPrice = AnsiConsole.Ask("[Yellow]Enter new price:[/] "); + AnsiConsole.Markup($"[Blue]Current price:[/] {productToUpdate.Price}\n"); + decimal newPrice = AnsiConsole.Prompt( + new TextPrompt("[Yellow]Enter new price:[/] ") + .ValidationErrorMessage("Not valid input") + .Validate(price => + { + return price switch + { + <= 0 => ValidationResult.Error("Price must be greater than zero"), + _ => ValidationResult.Success(), + }; + })); + _kebabController.UpdateProductPrice(productToUpdate, newPrice); } private void DeleteOrder() // Burayż kodluyorsun @@ -413,7 +424,7 @@ public void DisplayProducts(List products) AnsiConsole.Write(productTable); } -// added for testing + // added for testing public void DisplayProducts(List products) { var productTable = new Table().Centered(); @@ -443,7 +454,7 @@ public void DisplayProducts(List products) AnsiConsole.Write(productTable); } -//end add + //end add public void DisplayOrders(List orders) { var orderTable = new Table().Centered();