|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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);
- }
-
- }
-
- }
- }
|