public void DeleteAll() { foreach (Dish dish in Dishes) { Dishes.Clear(); } }
public DiscountViewModel() { Dishes.Clear(); Dishes.AddItems(_unitOfWork.Dishes.GetAll()); ApplyAction = new Command(OnApplyActionExecute, OnApplyActionCanExecute); }
public void SaveChanges() { if (string.IsNullOrEmpty(NameOfSelectedDish)) { MessageBox.Show("Name must not be empty", "Save Dish"); return; } double price; bool ok = ParsePrice(out price); if (!ok) { return; } string oldName = _selectedDish.Name, newName = NameOfSelectedDish; /*// TODO This does not find duplicate names! * if (IsDishNameInUse(newName, _selectedDish)) * { * MessageBox.Show($"Dish named {newName} already exists. Please write a different name.", "Save Dish"); * return; * } */ int index = Dishes.IndexOf(SelectedDish); bool isRenamed = oldName != newName; _selectedDish.Name = NameOfSelectedDish; _selectedDish.Description = DescriptionOfSelectedDish; _selectedDish.Price = price; _selectedDish.ContainsLactose = SelectedDishContainsLactose; _selectedDish.ContainsGluten = SelectedDishContainsGluten; _selectedDish.ContainsFish = SelectedDishContainsFish; DataAccess da = new DataAccess(); da.ModifyDish(_selectedDish); if (isRenamed) { // Reload the list to force items update in ComboBox Dishes.Clear(); Dishes.AddRange(TrimNames(new DataAccess().GetAllDishes())); NotifyOfPropertyChange(() => Dishes); NotifyOfPropertyChange(() => SelectedDish); } SelectedDishModified = false; }
private void LoadData() { Dishes.Clear(); var dataService = new DataService(); Category = dataService.GetCategories().First(c => c.Id == _categoryId); var dishes = dataService.GetDishes(_categoryId); foreach (var dish in dishes) { Dishes.Add(dish); } }
public static void LoadDishesFromFile() { Dishes.Clear(); try { Dishes = JsonConvert.DeserializeObject <ObservableCollection <Dish> >(File.ReadAllText(DishesDB, Encoding.Default)) ?? new ObservableCollection <Dish>(); } catch (JsonReaderException) { new Alert("Неверный формат файла", "Файл должен быть в формате JSON").Show(); DishesDB = Path.Combine(Environment.CurrentDirectory, "data\\dishes.txt"); } }
public void Update() { Dishes.Clear(); using (IDishController controller = factory.CreateDishController()) { DataControllerMessage <IEnumerable <DishDisplayDTO> > controllerMessage = controller.GetAll(); if (controllerMessage.IsSuccess) { foreach (DishDisplayDTO dish in controllerMessage.Data) { Dishes.Add(dish); } } } }
/// <summary> /// Обновление списков сущностей. /// </summary> private void UpdateLists() { Dishes.Clear(); Prepacks.Clear(); Products.Clear(); Shared.NHibernate.Environment.Session.Clear(); var dishes = Repository.Get <Dish>(); foreach (var dish in dishes) { dish.Update(); dish.EntitySaved += OnEntityChanged; dish.EntityDeleted += OnEntityChanged; } var prepacks = Repository.Get <Prepack>(); foreach (var prepack in prepacks) { prepack.Update(); prepack.EntitySaved += OnEntityChanged; prepack.EntityDeleted += OnEntityChanged; } var products = Repository.Get <Product>(); foreach (var product in products) { product.Update(); product.EntitySaved += OnEntityChanged; product.EntityDeleted += OnEntityChanged; } Dishes.AddRange(dishes.Select(x => new DishViewModel(x))); Prepacks.AddRange(prepacks.Select(x => new PrepackViewModel(x))); Products.AddRange(products.Select(x => new ProductViewModel(x))); }
private void RefreshDishesCollection() { Dishes.Clear(); Dishes.AddItems(_unitOfWork.Dishes.GetAll()); new ActionsHelper().CalculateDiscountsExisting(Dishes); }