public async Task <IActionResult> Index() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home")); } var nameIdentifier = User.FindFirstValue(ClaimTypes.NameIdentifier); var recipes = _recipeService.GetAll().Where(r => r.ApplicationUsersRecipes.Any(aur => aur.ApplicationUserId == nameIdentifier)); var recipesViewModel = new RecipesViewModel { Recipes = await recipes.Select(r => new RecipeViewModel { Description = r.Description, Difficulty = r.Difficulty, Evaluation = r.Evaluation.Value, Ingredients = r.Components.Select(c => c.Ingredient.Name), Name = r.Name, Picture = r.Picture, RecipeId = r.RecipeId, Servings = r.Servings, Time = r.Time }).ToListAsync() }; return(View(recipesViewModel)); }
protected override void OnAppearing() { BindingContext = new RecipesViewModel(_category); base.OnAppearing(); lvItems.ItemTapped -= RecipesViewModel.LvItems_ItemTapped; lvItems.ItemTapped += RecipesViewModel.LvItems_ItemTapped; }
private void BtnRecipes_Click(object sender, RoutedEventArgs e) { RecipesViewModel view = new RecipesViewModel(); PopUpControll pop = new PopUpControll("Receptury", 800, 200, view); pop.PopUpShow(); }
public void ReadmeExample_ListPages() { int page = 1; int pageSize = 10; var parameterDict = new Dictionary <string, string>() { { "page", page.ToString() }, { "page_size", pageSize.ToString() } }; PagesResponse <RecipePage> recipePages = butterClient.ListPages <RecipePage>("recipe", parameterDict); var viewModel = new RecipesViewModel(); viewModel.PreviousPageNumber = recipePages.Meta.PreviousPage; viewModel.NextPageNumber = recipePages.Meta.NextPage; viewModel.PagesCount = recipePages.Meta.Count; viewModel.Recipes = new List <RecipeViewModel>(); foreach (Page <RecipePage> recipe in recipePages.Data) { RecipeViewModel recipeViewModel = new RecipeViewModel(); recipeViewModel.Category = recipe.Fields.category; recipeViewModel.RecipeName = recipe.Fields.recipe_name; recipeViewModel.MainIngredient = recipe.Fields.main_ingredient; recipeViewModel.EstimatedCookingTimeInMinutes = recipe.Fields.estimated_cooking_time_in_minutes; recipeViewModel.IngredientList = recipe.Fields.ingredient_list; recipeViewModel.Instructions = recipe.Fields.instructions; viewModel.Recipes.Add(recipeViewModel); } Assert.IsNotNull(viewModel); }
public ActionResult Recipes() { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage modules"))) { return(new HttpUnauthorizedResult()); } IEnumerable <ModuleEntry> modules = _extensionManager.AvailableExtensions() .Where(extensionDescriptor => ExtensionIsAllowed(extensionDescriptor)) .OrderBy(extensionDescriptor => extensionDescriptor.Name) .Select(extensionDescriptor => new ModuleEntry { Descriptor = extensionDescriptor }); var viewModel = new RecipesViewModel(); if (_recipeHarvester != null) { viewModel.Modules = modules.Select(x => new ModuleRecipesViewModel { Module = x, Recipes = _recipeHarvester.HarvestRecipes(x.Descriptor.Id).Where(recipe => !recipe.IsSetupRecipe).ToList() }) .Where(x => x.Recipes.Any()) .ToList(); } return(View(viewModel)); }
public ContentResult DeletePopup(RecipesViewModel model) { string json = ""; int rez = 0; string message = ""; // message = "Подумай ще!"; if (ModelState.IsValid) { var status = _recipeProvider.DeletePopup(model.Id); if (status == StatusDeleteViewModel.Succes) { rez = 1; } else { message = "Во время удаления возникла ошибка!"; rez = 2; } } json = JsonConvert.SerializeObject(new { rez = rez, message = message }); return(Content(json, "application/json")); }
public ActionResult ProductsWeight(int Id) { RecipesViewModel model = _recipeProvider.EditRecipeProdWeight(Id); ViewBag.ListProducts = _recipeProvider.GetListItemProducts(); ViewBag.ListProductWeights = _recipeProvider.GetListWeightProducts(Id); return(View(model)); }
public IActionResult Index() { RecipesViewModel recipes = RecipesViewModel.GetRecipeViewModel(12); ViewData["Title"] = recipes.Title; return(View(recipes)); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); this.viewModel = new RecipesViewModel(); this.DataContext = viewModel; await viewModel.LoadRecipes(); }
public ActionResult Index() { var model = new RecipesViewModel { Recipes = DatabaseService.GetAll() }; return(View(model)); }
/// <summary> /// Creates new instance of <see cref="SendQRCommand"/> /// </summary> public SendQRCommand(RecipesViewModel recipesViewModel) { var app = ((App)App.Current); this._recipeClient = app.RecipeClient; this._userApiClient = app.UserApiClient; this._vm = recipesViewModel; this._isSendAvailable = true; }
public IActionResult ShowAll(IndexViewModel model) { if (!ModelState.IsValid) { return(PartialView("_NoIngredientsPartial")); } var ingredients = model.IngredientsUris.Select(i => $"exists {{ ?food dbo:ingredient dbr:{i.Split('/').Last()} }}"); var ingredients_exists = $"FILTER ({string.Join(" && ", ingredients)})\r\n"; var categories = model.CategoriesUris?.Select(c => $"exists {{ ?food dct:subject dbc:{c.Split(':').Last()} }}"); var categories_exists = categories != null ? $"FILTER ({string.Join(" && ", categories)})\r\n" : ""; var endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org"); var query = "PREFIX dbo: <http://dbpedia.org/ontology/>\r\n" + "PREFIX dbr: <http://dbpedia.org/resource/>\r\n" + "PREFIX dct: <http://purl.org/dc/terms/>\r\n" + "PREFIX dbc: <http://dbpedia.org/resource/Category:>\r\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\r\n" + "SELECT ?food ?stripped_name ?stripped_abstract ?thumb ?id\r\n" + "WHERE{\r\n" + "?food a dbo:Food.\r\n" + "?food rdfs:label ?name.\r\n" + "?food dbo:abstract ?abstract.\r\n" + "?food dbo:thumbnail ?thumb.\r\n" + "?food dbo:wikiPageID ?id\r\n" + ingredients_exists + categories_exists + "FILTER(LANGMATCHES(LANG(?name), 'en') && LANGMATCHES(LANG(?abstract), 'en'))\r\n" + "BIND(STR(?name) AS ?stripped_name)\r\n" + "BIND(STR(?abstract) AS ?stripped_abstract)\r\n" + "}"; var results = endpoint.QueryWithResultSet(query); var recipesViewModel = new RecipesViewModel { Recipes = results.Select(r => new RecipeViewModel { Description = r["stripped_abstract"].ToString(), Name = r["stripped_name"].ToString(), Picture = r["thumb"].ToString(), RecipeId = r["id"].ToString().Split("^^").First(), Evaluation = GetEvaluation(r["id"].ToString().Split("^^").First()) }).ToList() }; if (model.Rating.HasValue) { recipesViewModel.Recipes = recipesViewModel.Recipes.Where(r => r.Evaluation >= model.Rating.Value).ToList(); } return(PartialView("_RecipesPartial", recipesViewModel)); }
public RecipesView() { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; var viewModel = new RecipesViewModel(); this.DataContext = viewModel; if (viewModel.CloseAction == null) { viewModel.CloseAction = new Action(this.Close); } }
public async Task <IActionResult> Index() { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Index", "Home")); } var nameIdentifier = User.FindFirstValue(ClaimTypes.NameIdentifier); var recipesId = await _favoritedRecipeService.GetAll().Where(fr => fr.ApplicationUserId == nameIdentifier).Select(fr => fr.RecipeId).ToListAsync(); var endpoint = new SparqlRemoteEndpoint(new Uri("http://dbpedia.org/sparql"), "http://dbpedia.org"); var favoritedRecipes = new List <RecipeViewModel>(); foreach (var recipeId in recipesId) { var query = "PREFIX dbo: <http://dbpedia.org/ontology/>\r\n" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\r\n" + "SELECT ?food ?stripped_name ?stripped_abstract ?thumb\r\n" + "WHERE{\r\n" + "?food a dbo:Food.\r\n" + "?food rdfs:label ?name.\r\n" + "?food dbo:abstract ?abstract.\r\n" + "?food dbo:thumbnail ?thumb.\r\n" + $"?food dbo:wikiPageID {recipeId}\r\n" + "FILTER(LANGMATCHES(LANG(?name), 'en') && LANGMATCHES(LANG(?abstract), 'en'))\r\n" + "BIND(STR(?name) AS ?stripped_name)\r\n" + "BIND(STR(?abstract) AS ?stripped_abstract)\r\n" + "}"; var results = endpoint.QueryWithResultSet(query); if (results.Any()) { favoritedRecipes.Add(new RecipeViewModel { Description = results.First()["stripped_abstract"].ToString(), Evaluation = 0, //recipe.Evaluation != null ? recipe.Evaluation.Value : 0, FavoritedRecipe = false, // recipe.ApplicationUsersRecipes.Any(aur => aur.ApplicationUserId == User.FindFirstValue(ClaimTypes.NameIdentifier)), Name = results.First()["stripped_name"].ToString(), Picture = results.First()["thumb"].ToString(), RecipeId = recipeId }); } } var recipesViewModel = new RecipesViewModel { Recipes = favoritedRecipes }; return(View(recipesViewModel)); }
public ActionResult Index() { var model = _recipeProvider.GetRecipes(); var r = new Random(); var rand = r.Next(0, model.Count()); RecipesViewModel randRecipe = model./*Where(m => m.Id == 53).FirstOrDefault()*/ ElementAt(rand); // var c = _recipeProvider.GetRecipeProdInfo(rand).CaloricValue; GetRecipeProdItemInfoViewModel info = _recipeProvider.GetRecipeProdInfo(randRecipe.Id); ViewBag.ProdInfo = info; return(View(randRecipe)); }
public ResultsPage(List <String> myList) { InitializeComponent(); ingredientList = myList; //BindingContext = viewModel = new ItemsViewModel(); BindingContext = viewModel2 = new RecipesViewModel(); for (int i = 0; i < ingredientList.Count; i++) { Label myLabel = new Label { Text = ingredientList.ElementAt(i) }; } }
public ActionResult Index() { var recipes = _context.Recipes.Take(10).ToList(); List <string> imagePaths = new List <string>(); foreach (var item in recipes) { imagePaths.Add((from Image in _context.Images where Image.RecipeId == item.Id && Image.Path != "" select Image.Path).First()); } var model = new RecipesViewModel { Recipes = recipes, ImagesPaths = imagePaths }; return(View(model)); }
public RecipesViewModel EditRecipeProdWeight(RecipesViewModel editRecipe) { RecipesViewModel editView = new RecipesViewModel(); try { var recipe = _recipeRepository.GetRecipeById(editRecipe.Id); if (recipe != null) { using (var transaction = new TransactionScope()) { _recipeProdRecordRepository.RemoveRecipe(editRecipe.Id); _recipeProdRecordRepository.SaveChanges(); _recipeRepository.SaveChanges(); var i = 0; foreach (var item in editRecipe.Weight) { var prod = _productRepository.GetProductById(item.Id); if (prod != null) { _recipeProdRecordRepository.Add(new RecipeProdRecord() { RecipeId = editRecipe.Id, ProductId = item.Id, Weight = item.Weight }); } ++i; } _recipeProdRecordRepository.SaveChanges(); _recipeRepository.SaveChanges(); transaction.Complete(); } } } catch { return(null); } return(editRecipe); }
public RecipesViewModel EditRecipeProdWeight(int id) { var recipe = _recipeRepository.GetRecipeById(id); IEnumerable <SelectItemViewModel> categoriesList = new List <SelectItemViewModel>(); categoriesList = GetSelectCategories(); if (recipe != null) { var MyViewModel = new RecipesViewModel(); MyViewModel.Id = id; MyViewModel.RecipeName = recipe.RecipeName; MyViewModel.RecipeImage = recipe.RecipeImage; MyViewModel.RecipeDescription = recipe.RecipeDescription; MyViewModel.CreatedAt = recipe.CreatedAt; MyViewModel.ModefiedAt = recipe.ModefiedAt; MyViewModel.CookingTime = recipe.CookingTime; MyViewModel.RecipeCategory = recipe.RecipeCategory; MyViewModel.Products = recipe.RecipeProdRecords.Select(pr => new SelectItemViewModel { Id = pr.ProductId, Name = pr.Product.ProductName, }).ToList(); MyViewModel.Menus = recipe.MenuRecipeRecords.Select(mr => new SelectItemViewModel { Id = mr.MenuId, Name = mr.Menu.MenuName, }).ToList(); MyViewModel.Weight = recipe.RecipeProdRecords.Select(pr => new SelectProdWeightViewModel { Id = pr.ProductId, Name = pr.Product.ProductName, Weight = pr.Weight }).ToList(); return(MyViewModel); } return(null); }
public async Task <IActionResult> ShowAll(IndexViewModel model) { if (!ModelState.IsValid) { return(PartialView("_NoIngredientsPartial")); } var recipes = _recipeService.GetAll().Where(r => r.Components.All(c => model.IngredientsIds.Contains(c.IngredientId))); if (model.CategoriesIds != null) { recipes = recipes.Where(r => r.CategoriesRecipes.Any(cr => model.CategoriesIds.Contains(cr.CategoryId))); } if (model.Difficulty.HasValue) { recipes = recipes.Where(r => r.Difficulty >= model.Difficulty.Value); } if (model.Rating.HasValue) { recipes = recipes.Where(r => r.Evaluation != null && r.Evaluation.Value >= model.Rating.Value); } var recipesViewModel = new RecipesViewModel { Recipes = await recipes.Select(r => new RecipeViewModel { Description = r.Description, Difficulty = r.Difficulty, Evaluation = r.Evaluation.Value, Ingredients = r.Components.Select(c => c.Ingredient.Name), Name = r.Name, Picture = r.Picture, RecipeId = r.RecipeId, Servings = r.Servings, Time = r.Time }).ToListAsync() }; return(PartialView("_RecipesPartial", recipesViewModel)); }
public ActionResult Recipes() { if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not allowed to manage modules"))) { return(new HttpUnauthorizedResult()); } IEnumerable <ModuleEntry> modules = _extensionManager.AvailableExtensions() .Where(extensionDescriptor => DefaultExtensionTypes.IsModule(extensionDescriptor.ExtensionType)) .OrderBy(extensionDescriptor => extensionDescriptor.Name) .Select(extensionDescriptor => new ModuleEntry { Descriptor = extensionDescriptor }); var viewModel = new RecipesViewModel(); return(View(viewModel)); }
public ActionResult ProductsWeight(RecipesViewModel editRecipe) { var image = editRecipe.PhotoUpload; var imageSave = WorkWithImage.CreateImage(image, 500, 400); if (ModelState.IsValid) { var result = _recipeProvider.EditRecipeProdWeight(editRecipe); if (result == null) { ModelState.AddModelError("", "Ошибка! Невозможно сохранить! Проверьте все ли поля указаны."); } else if (result != null) { if (editRecipe.RecipeImage != null && editRecipe.PhotoUpload == null) { _recipeProvider.EditRecipeProdWeight(editRecipe); return(RedirectToAction("Index")); /*RedirectToAction("ProductsWeight", new { id = editRecipe.Id })*/; } else if (/*editRecipe.PhotoUpload.ContentLength > 0*/ editRecipe.PhotoUpload != null) { // A file was uploaded var fileName = Path.GetFileName(editRecipe.PhotoUpload.FileName); string uploadPath = "~/Images/Recipe/Big/"; var path = Path.Combine(Server.MapPath(uploadPath), fileName); imageSave.Save(path, ImageFormat.Jpeg); editRecipe.RecipeImage = uploadPath + fileName; } _recipeProvider.EditRecipeProdWeight(editRecipe); return(RedirectToAction/*("ProductsWeight", new { id = editRecipe.Id })*/ ("Index")); } } ViewBag.ListProducts = _recipeProvider.GetListItemProducts(); ViewBag.ListMenus = _recipeProvider.GetListItemMenus(); ViewBag.ListProductWeights = _recipeProvider.GetListWeightProducts(editRecipe.Id); return(View(editRecipe)); }
public ActionResult Recettes(RecipesViewModel submitted) { model = DisplaySearchResult(submitted); var IngInList = db.Ingredient.ToList(); List <SelectListItem> items = new List <SelectListItem>(); foreach (var Ing in IngInList) { var item = new SelectListItem { Value = Ing.id.ToString(), Text = Ing.name }; items.Add(item); } MultiSelectList IngList = new MultiSelectList(items.OrderBy(i => i.Text), "Value", "Text"); model.SelectIng = IngList; EditionLastAndNewRecipes.MeilleuresRecettes(model.NewAndBest.lastRecipes); EditionLastAndNewRecipes.DernieresRecettes(model.NewAndBest.bestRecipes); return(View(model)); }
public MyRecipes() { InitializeComponent(); BindingContext = viewModel2 = new RecipesViewModel(); }
public ActionResult Delete(RecipesViewModel recipeDel) { _recipeProvider.Delete(recipeDel.Id); return(RedirectToAction("Index")); }
public CategoryTabbedViewModel(Category category) { Title = category.CategoryName; RecipesViewModel = new RecipesViewModel(category); }
public RecipesPage() { InitializeComponent(); BindingContext = new RecipesViewModel(Navigation); }
public RecipesPage() { InitializeComponent(); BindingContext = viewModel = new RecipesViewModel(); }
private void setUpMocks() { repoSaved = false; recipesRepositoryMock = new Mock <IRecipesRepository>(); productsRepositoryMock = new Mock <IProductsRepository>(); usersRepositoryMock = new Mock <IUsersRepository>(); eventAggregatorMock = new Mock <IEventAggregator>(); var productAddedEventMock = new Mock <NewProductAddedEvent>(); eventAggregatorMock.Setup(e => e.GetEvent <NewProductAddedEvent>()). Returns(productAddedEventMock.Object); var recipeAddedEventMock = new Mock <NewRecipeAddedEvent>(); eventAggregatorMock.Setup(e => e.GetEvent <NewRecipeAddedEvent>()). Returns(recipeAddedEventMock.Object); var recipeRemovedEventMock = new Mock <RecipeRemovedEvent>(); eventAggregatorMock.Setup(e => e.GetEvent <RecipeRemovedEvent>()). Returns(recipeRemovedEventMock.Object); var recipeUpdatedEventMock = new Mock <RecipeUpdatedEvent>(); eventAggregatorMock.Setup(e => e.GetEvent <RecipeUpdatedEvent>()). Returns(recipeUpdatedEventMock.Object); recipeProductList = new List <RecipeProduct>(); product1 = new Product { Id = Guid.NewGuid(), Name = "Product1" }; product2 = new Product { Id = Guid.NewGuid(), Name = "Product2" }; productList = new List <Product> { product1, product2 }; productsRepositoryMock.Setup(pr => pr.GetAllProducts()). Returns(productList); User user = new User { Id = Guid.NewGuid() }; usersRepositoryMock.Setup(ur => ur.GetFirstUser()) .Returns(user); recipe1 = new Recipe { Id = Guid.NewGuid(), Title = "Recipe1", UserId = user.Id }; recipe2 = new Recipe { Id = Guid.NewGuid(), Title = "Recipe2", UserId = user.Id }; recipeList = new List <Recipe> { recipe1, recipe2 }; recipesRepositoryMock.Setup(rr => rr.GetAllRecipes()) .Returns(recipeList); recipesRepositoryMock.Setup(rr => rr.Save()) .Callback(() => repoSaved = true); RecipeProduct recipeProduct1 = new RecipeProduct { Id = Guid.NewGuid(), ProductId = product1.Id, RecipeId = recipe1.Id }; RecipeProduct recipeProduct2 = new RecipeProduct { Id = Guid.NewGuid(), ProductId = product2.Id, RecipeId = recipe1.Id }; RecipeProduct recipeProduct3 = new RecipeProduct { Id = Guid.NewGuid(), ProductId = product1.Id, RecipeId = recipe2.Id }; rpl1 = new RecipeProductLookup { ProductId = product1.Id, RecipeProductId = recipeProduct1.Id, ProductName = product1.Name }; rpl2 = new RecipeProductLookup { ProductId = product2.Id, RecipeProductId = recipeProduct2.Id, ProductName = product2.Name }; rpl3 = new RecipeProductLookup { ProductId = product1.Id, RecipeProductId = recipeProduct3.Id, ProductName = product1.Name }; recipe1.RecipeProducts = new List <RecipeProduct> { recipeProduct1, recipeProduct2 }; recipe2.RecipeProducts = new List <RecipeProduct> { recipeProduct3 }; recipesRepositoryMock.Setup(rr => rr.AddRecipe( It.IsAny <Recipe>())) .Callback <Recipe>(r => recipeList.Add(r)); recipesRepositoryMock.Setup(rr => rr.RemoveRecipe( It.IsAny <Recipe>())) .Callback <Recipe>(r => recipeList.Remove(r)); recipesRepositoryMock.Setup(rr => rr.GetProductsForRecipe( It.Is <Guid>(g => g.Equals(product1.Id)))) .Returns(new List <Product> { product1, product2 }); recipesRepositoryMock.Setup(rr => rr.GetRecipeProductLookupsForRecipe( It.Is <Guid>(g => g.Equals(recipe1.Id)))) .Returns(new List <RecipeProductLookup> { rpl1, rpl2 }); recipesRepositoryMock.Setup(rr => rr.GetProductsForRecipe( It.Is <Guid>(g => g.Equals(product2.Id)))) .Returns(new List <Product> { product1 }); recipesRepositoryMock.Setup(rr => rr.GetRecipeProductLookupsForRecipe( It.Is <Guid>(g => g.Equals(recipe2.Id)))) .Returns(new List <RecipeProductLookup> { rpl3 }); recipesRepositoryMock.Setup(rr => rr.GetProductsForRecipe( It.Is <Guid>(g => !g.Equals(recipe1.Id) && !g.Equals(recipe2.Id)))) .Returns(new List <Product>()); recipesRepositoryMock.Setup(rr => rr.GetRecipeProductLookupsForRecipe( It.Is <Guid>(g => !g.Equals(recipe1.Id) && !g.Equals(recipe2.Id)))) .Returns(new List <RecipeProductLookup>()); recipesRepositoryMock.Setup(rr => rr.AddRecipeProduct( It.IsAny <RecipeProduct>())) .Callback <RecipeProduct>(rp => recipeProductList.Add(rp)); recipesViewModel = new RecipesViewModel( recipesRepositoryMock.Object, productsRepositoryMock.Object, usersRepositoryMock.Object, eventAggregatorMock.Object); }
public RecipesView(ApplicationContext context) { InitializeComponent(); _viewModel = new RecipesViewModel(context); this.DataContext = _viewModel; }
// GET: Register public ActionResult Index() { var model = new RecipesViewModel(); return View(model); }