protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); _dishViewModel = new DishViewModel(); _dishWindow = new DishWindow { DataContext = _dishViewModel }; _ingredientsViewModel = new IngredientsViewModel(); _ingredientsWindow = new IngredientsWindow { DataContext = _ingredientsViewModel }; _preparationViewModel = new PreparationViewModel(); _preparationWindow = new PreparationWindow { DataContext = _preparationViewModel }; _mainViewModel = new MainViewModel(_dishWindow, _ingredientsWindow, _preparationWindow); _mainWindow = new MainWindow { DataContext = _mainViewModel }; _mainWindow.Show(); }
public async Task <IViewComponentResult> InvokeAsync( int foodId, int mealId) { IngredientsViewModel ingredientsViewModel = await _ingredientService.GetViewListIngredientsViewModelAsync(foodId, mealId); return(View(ingredientsViewModel)); }
/// <summary> /// Parses the comma separated ids from a Recipe into a list of Ingredients /// </summary> /// <param name="idValues">The CSV containing the ids</param> /// <param name="dataStoreReference">A reference to the current ingredients viewmodel</param> /// <returns>A List with the corresponding ingredients</returns> public static List <Ingredient> IdCSVToIngredientList(string idValues, IngredientsViewModel viewModelReference) { List <Ingredient> ingredientList = new List <Ingredient>(); string[] separatedValues = idValues.Split(','); int parsedId; if (viewModelReference.Ingredients == null) { return(ingredientList); } else if (viewModelReference.Ingredients.Count == 0) { viewModelReference.LoadIngredientsCommand.Execute(null); } foreach (string id in separatedValues) { if (int.TryParse(id, out parsedId) && parsedId - 1 >= 0 && parsedId - 1 < viewModelReference.Ingredients.Count) { viewModelReference.Ingredients.ToList().ForEach(i => { if (i.Id == parsedId) { ingredientList.Add(i); } }); } } return(ingredientList); }
/// <summary> /// Handles the actions to do when this Activity is created /// </summary> /// <param name="savedInstanceState">Saved instance state.</param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); ViewModel = BrowseIngredientFragment.ViewModel; SetContentView(Resource.Layout.activity_add_ingredient); saveButton = FindViewById <FloatingActionButton>(Resource.Id.save_button_addIngredient); nameField = FindViewById <EditText>(Resource.Id.nameField_addIngredient); groupField = FindViewById <EditText>(Resource.Id.groupField_addIngredient); measureField = FindViewById <EditText>(Resource.Id.measureField_addIngredient); priceField = FindViewById <EditText>(Resource.Id.estimatedPriceField_addIngredient); estimatedPerField = FindViewById <EditText>(Resource.Id.estimatedPerField_addIngredient); allergenButton = FindViewById <ToggleButton>(Resource.Id.toggleAllergen_addIngredient); var data = Intent.GetStringExtra("ingredient") ?? null; if (data != null) { editMode = true; editIngredient = Newtonsoft.Json.JsonConvert.DeserializeObject <Ingredient>(data); fillForm(); } saveButton.Click += SaveButton_Click; }
/// <summary> /// Instantiates a new view model /// </summary> /// <param name="recipe">The recipe to show</param> /// <param name="ingredientReference">A reference to the list of ingredients, to be loaded on the recipe</param> public RecipeDetailViewModel(Recipe recipe = null, IngredientsViewModel ingredientReference = null) { if (recipe != null) { Title = recipe.Name; Recipe = recipe; IngredientList = ItemParser.IdCSVToIngredientList(recipe.Ingredients, ingredientReference); QuantityList = ItemParser.QuantityValuesToFloatList(recipe.Quantities); } }
/// <summary> /// Instantiates a new adapter /// </summary> /// <param name="activity">The activity for this adapter</param> /// <param name="viewModel">The view model for this adapter</param> public BrowseIngredientsAdapter(Activity activity, IngredientsViewModel viewModel) { this.viewModel = viewModel; this.activity = activity; this.viewModel.Ingredients.CollectionChanged += (sender, args) => { this.activity.RunOnUiThread(NotifyDataSetChanged); }; }
public IActionResult Index() { IngredientsViewModel vm = new IngredientsViewModel() { Ingredients = _db.Ingredients.Where(x => x.Archived == false), Stores = _db.Stores.Where(x => x.Archived == false) }; return(View(vm)); }
public async Task <IActionResult> IngredientList() { var ingredients = await this.restaurantService.GetAllIngredients(); var parsedIngredients = new IngredientsViewModel() { Ingredients = ingredients }; return(this.View(parsedIngredients)); }
/// <summary> /// Gets the estimated total price of this recipe /// </summary> /// <param name="recipe">The recipe</param> /// <param name="viewModel">The viewmodel</param> /// <returns>The total price</returns> public static double GetEstimatedPrice(Recipe recipe, IngredientsViewModel viewModel) { double price = 0; List <float> qList = QuantityValuesToFloatList(recipe.Quantities); List <Ingredient> ingList = IdCSVToIngredientList(recipe.Ingredients, viewModel); ingList.ForEach(i => { price += (i.EstimatedPrice / i.EstimatedPer) * qList[ingList.IndexOf(i)]; }); return(price); }
public async Task <IActionResult> ManageIngredients(IngredientsViewModel vm) { var viewModel = new IngredientsViewModel(); var ingredients = await _ingredientServices.SearchIngredientsAsync(vm.Input); if (ingredients.Count() == 0) { ModelState.AddModelError(string.Empty, "No ingredients found with this name."); return(View(viewModel)); } viewModel.Ingredients = ingredients.Select(i => i.MapToViewModel()).ToList(); return(View(viewModel)); }
public ActionResult Index(IngredientsViewModel IngVm, string q, int?cid, string slug, int page = 1) { var pageSize = 10; IQueryable <Recipe> recipes = db.Recipes; Category category = null; var ingredients = db.Ingredients.Select(x => new { IngredientId = x.Id, IngredientName = x.IngredientName }); ViewBag.Ingredients = new MultiSelectList(ingredients.ToList(), "IngredientId", "IngredientName"); if (IngVm.IngredientId != null) { TempData["DropBoxBosalt"] = true; var selectedIngredients = new List <Ingredient>(); foreach (var item in IngVm.IngredientId) { selectedIngredients.Add(db.Ingredients.FirstOrDefault(x => x.Id == item)); } foreach (var item in selectedIngredients) { recipes = recipes.Where(x => x.Ingredients.Where(y => y.Id == item.Id).Any()); } } if (q != null) { recipes = recipes.Where(x => x.Category.CategoryName.Contains(q) || x.Title.Contains(q)); } if (cid != null && q == null) { category = db.Categories.Find(cid); if (category == null) { return(HttpNotFound()); } recipes = recipes.Where(x => x.CategoryId == cid); } var vm = new HomeIndexViewModel { Recipes = recipes.OrderByDescending(x => x.CreationTime).ToPagedList(page, pageSize), Category = category, SearchTerm = q, CategoryId = cid }; return(View(vm)); }
public ActionResult IngredientsIndex() { try { var viewModel = new IngredientsViewModel { IngredientDtos = ingredientService.GetAllIngredients().ToList() }; return(View(viewModel)); } catch (Exception e) { return(new HttpStatusCodeResult(500)); } }
public override void ViewDidLoad() { base.ViewDidLoad(); ViewModel = new IngredientsViewModel(); // Setup UITableView. refreshControl = new UIRefreshControl(); refreshControl.ValueChanged += RefreshControl_ValueChanged; TableView.Add(refreshControl); TableView.Source = new ItemsDataSource(ViewModel); Title = ViewModel.Title; ViewModel.PropertyChanged += IsBusy_PropertyChanged; ViewModel.Ingredients.CollectionChanged += Items_CollectionChanged; }
/// <summary> /// Handles the actions when this fragment view is created /// </summary> /// <returns>The created view.</returns> /// <param name="inflater">Inflater.</param> /// <param name="container">Container.</param> /// <param name="savedInstanceState">Saved instance state.</param> public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewModel = new IngredientsViewModel(); View view = inflater.Inflate(Resource.Layout.fragment_browse, container, false); recyclerView = view.FindViewById <RecyclerView>(Resource.Id.recyclerView); recyclerView.HasFixedSize = true; recyclerView.SetAdapter(adapter = new BrowseIngredientsAdapter(Activity, ViewModel)); refresher = view.FindViewById <SwipeRefreshLayout>(Resource.Id.refresher); refresher.SetColorSchemeColors(Resource.Color.accent); progress = view.FindViewById <ProgressBar>(Resource.Id.progressbar_loading); progress.Visibility = ViewStates.Gone; return(view); }
private void DeleteButtonClicked(object sender, RoutedEventArgs e) { IngredientsViewModel cat = (IngredientsViewModel)IngredientsListView.SelectedItem; string sql = "Delete from IngredientsList where name = N\'" + cat.Name + "\';"; connection = new SqlConnection(Settings.connectionString); connection.Open(); command = new SqlCommand(sql, connection); try { reader = command.ExecuteReader(); connection.Close(); RefreshButtonClicked(sender, e); } catch (Exception ex) { MessageBox.Show("Błąd połączenia: " + ex.ToString()); } }
/// <summary> /// Handles the actions to do when this activity is created /// </summary> /// <param name="savedInstanceState">Saved instance state.</param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); toastAlert = true; editRecipe = null; editMode = false; IngViewModel = BrowseIngredientFragment.ViewModel; RecViewModel = BrowseRecipeFragment.ViewModel; ingredientNames = IngViewModel.Ingredients.Select(ingredient => ingredient.Name).ToArray(); addedIngredients = new ObservableCollection <Ingredient>(); SetContentView(Resource.Layout.activity_add_recipe); saveButton = FindViewById <FloatingActionButton>(Resource.Id.save_button_addRecipe); nameField = FindViewById <EditText>(Resource.Id.nameField_addRecipe); instructionsField = FindViewById <EditText>(Resource.Id.instructionsField_addRecipe); addIngredientButton = FindViewById <Button>(Resource.Id.addIngredientToRecipe_addRecipe); ingredientRecyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerviewAddIngredients_addRecipe); ingredientSpinner = FindViewById <Spinner>(Resource.Id.ingredientSpinner_addRecipe); swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout_addRecipe); ingredientRecyclerView.SetAdapter(adapter = new RecipeIngredientsAdapter(this, addedIngredients, quantityStore)); ingredientSpinner.Adapter = new ArrayAdapter(this.ApplicationContext, Android.Resource.Layout.SimpleListItem1, ingredientNames); quantityStore = new List <float>(); var data = Intent.GetStringExtra("recipe") ?? null; if (data != null) { editMode = true; editRecipe = Newtonsoft.Json.JsonConvert.DeserializeObject <Recipe>(data); fillForm(); } addIngredientButton.Click += AddIngredientButton_Click; saveButton.Click += SaveButton_Click; adapter.ItemLongClick += IngredientRecyclerView_ItemLongClick; swipeRefreshLayout.Refresh += SwipeRefreshLayout_Refresh; }
public IngredientsView(LocalDataManager localDataManager) { InitializeComponent(); BindingContext = new IngredientsViewModel(localDataManager); }
public ItemsDataSource(IngredientsViewModel viewModel) { this.viewModel = viewModel; }
public IngredientsPage() { InitializeComponent(); BindingContext = viewModel = new IngredientsViewModel(); }
public IngredientsView() { InitializeComponent(); DataContext = new IngredientsViewModel(); }