public static void CreateGenericProducts() { #if NDB var catgories = new[] { "Drink", "General" }; var barcode = 0; foreach (var prodName in catgories) { var cat = new Category { Name = prodName, Tax = 0.23m }; DataManager.AddCategory(cat); const decimal incrementPrice = 0.1m; var basePrice = 0.5m; for (var i = 1; i <= 5; i++) { DataManager.AddProduct(new Product { Barcode = barcode.ToString(), Category = cat, Name = $"{prodName} #{i}", Price = basePrice, UnitPrice = basePrice }); basePrice += incrementPrice; barcode++; } } #endif }
public IActionResult AddCategory(Category category) { var username = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var user = _userManager.GetUser(username); //TODO: Return error if user isn't administrator var newCategory = _dataManager.AddCategory(category); return(Ok(newCategory)); }
private void MetroButton1_Click(object sender, EventArgs e) { if (_toEdit != null) { var oldName = _toEdit.Name; _toEdit.Name = textBox1.Text; _toEdit.Tax = percentageUpDown1.Value; Extensions.RunInAnotherThread(() => { DataManager.AddCategory(_toEdit); DataManager.LogAction(GlobalStorage.CurrentUser, UserAction.Action.EditCategory, oldName); }); } else { if (string.IsNullOrEmpty(textBox1.Text.Trim()) || errorImage.Visible) { return; } var finalCategory = new Category { Name = textBox1.Text, Tax = !percentageUpDown1.Visible ? int.Parse(string.Join("", simpleSelectionControl1.SelectedEnumValue.GetDescription().Where(char.IsDigit))) / 100m : percentageUpDown1.Value }; Extensions.RunInAnotherThread(() => { DataManager.AddCategory(finalCategory); DataManager.LogAction(GlobalStorage.CurrentUser, UserAction.Action.CreateCategory, textBox1.Text); }); } simpleSelectionControl1.SelectedEnumValue = PortugueseTax.TwentyTree; textBox1.Clear(); }
private void CategoryMenuMenuSwitch(int choice, out bool loop) { loop = true; switch (choice) { case 1: { Console.WriteLine("\n## all categoriies list"); var categories = dataManager.GetAllCategories(); Print(categories); Console.WriteLine("## end all categoriies"); } break; case 2: { Console.WriteLine("\n## add category"); var category = CreateCategory(); try { dataManager.AddCategory(category); } catch (ExistCategoryNameException ex) { Console.WriteLine("category with it name is exist. action cannot be complete"); } Console.WriteLine("## end add category"); } break; case 3: { Console.WriteLine("\n## edit category"); var categories = dataManager.GetAllCategories(); var category = SelectItem(categories); var newCategory = EditCategory(category); try { dataManager.UpdateCategory(category); } catch (ExistCategoryNameException ex) { Console.WriteLine("category with this name is already exist. action cannot be copmlete"); } Console.WriteLine("## end edit category"); } break; case 4: { Console.WriteLine("\n## remove category"); var categories = dataManager.GetAllCategories(); Console.WriteLine("select category to remove"); var category = SelectItem(categories); dataManager.RemoveCategory(category); Console.WriteLine("\n## end remove category"); } break; case 0: { Console.WriteLine("\n## back <--"); loop = false; } break; } }