|
- using BPASmart.Model;
- using BPASmartClient.Helper;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
-
- namespace BPASmart.RecipeManagement.ViewModel
- {
- public class CreateOrderViewModel : ObservableObject
- {
-
- public ObservableCollection<Recipes> recipes { get; set; } = new ObservableCollection<Recipes>();
-
- public ObservableCollection<string> recipesName { get; set; } = new ObservableCollection<string>();
-
-
- public RelayCommand SaveCommand { get; set; }
-
- public RelayCommand<object> DeleteCommand { get; set; }
- public RelayCommand AddRecipeCommand { get; set; }
-
- private void Delete(object o)
- {
- if (o == null) return;
- if (o is string id)
- {
- var res = recipes.FirstOrDefault(x => x.ID == id);
- recipes.Remove(res);
- }
- }
-
- public CreateOrderViewModel()
- {
- SaveCommand = new RelayCommand(() =>
- {
- Globle.GlobleData.orders.Add(new Order
- {
- OrderId = Guid.NewGuid().ToString(),
- OrderdateTime = DateTime.Now.ToString(),
- Recipes = recipes
- });
- ActionManage.GetInstance.Send("CloseCreateOrderView");
- });
-
- DeleteCommand = new RelayCommand<object>(Delete);
-
- AddRecipeCommand = new RelayCommand(() =>
- {
- recipes.Add(new Recipes() { ID = Guid.NewGuid().ToString(), RecipeCount = 1, });
- });
-
- foreach (var item in Json<LocalRecipes>.Data.locaRecipes)
- {
- recipesName.Add(item.Name);
- }
-
- }
-
- }
- }
|