private void Submit_Click(object sender, RoutedEventArgs e) { var error = ValidateRecipe(); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(error, "FoodRecipeApp", MessageBoxButton.OK, MessageBoxImage.Error); } else { recipe.Name = NameTextBox.Text; recipe.Description = DescriptionTextBox.Text; recipe.Ingredients = ingredients.ToList(); recipe.Directions = directions.ToList(); recipe.Directions.ForEach(d => d.VideoURL = NormalizedYoutubeURL(d.VideoURL)); if (RecipeDAO.Insert(recipe)) { MessageBox.Show("Đã thêm công thức", "FoodRecipeApp", MessageBoxButton.OK, MessageBoxImage.Information); Reset(); } else { MessageBox.Show("Đã có lỗi xảy ra, vui lòng thử lại", "FoodRecipeApp", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public IActionResult Search(string words) { RecipeDAO dao = new RecipeDAO(); List <Recipe> result; if (words == null || words.Equals("")) { result = dao.LoadRecipes(); } else { List <string> l_words = words.Split(' ').ToList(); result = dao.searchByWords(l_words); } var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); int idUser = int.Parse(claim.Value); Dictionary <int, float> rating = dao.allRatings(); ViewBag.Ratings = rating; List <Recipe> receitas = dao.getFavorites(idUser); List <int> favoritos = new List <int>(); foreach (Recipe recp in receitas) { favoritos.Add(recp.Id_Recipe); } ViewBag.Favorites = favoritos; return(View(result)); }
public IActionResult Create(Recipe recipe, IFormFile file) { RecipeDAO dao = new RecipeDAO(); var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); recipe.Creator = int.Parse(claim.Value); string s = "kapa"; List <string> warnings = new List <string> { s }; recipe.Warnings = warnings; recipe.Duration = 5; int id = dao.Insert(recipe); if (file != null) { using (MemoryStream ms = new MemoryStream()) { file.CopyToAsync(ms); byte[] b = ms.ToArray(); dao.InsertImage(id, b); } } return(RedirectToAction("Index", "User")); }
public IActionResult Delete(int id) { RecipeDAO dao = new RecipeDAO(); dao.Delete(id); return(RedirectToAction("Index", "Recipe")); }
public IActionResult Random() { var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); int idUser = int.Parse(claim.Value); RecipeDAO dao = new RecipeDAO(); List <Recipe> recipe = dao.LoadRecipes(); int RandomNumber(int min, int max) { Random random = new Random(); return(random.Next(min, max)); } int numero = RandomNumber(0, recipe.Count); List <Recipe> receitas = dao.getFavorites(idUser); ViewBag.Boolean = false; foreach (Recipe recp in receitas) { if (recp.Id_Recipe == numero) { ViewBag.Boolean = true; break; } } Recipe r = dao.FindById(recipe.ElementAt(numero).Id_Recipe); ViewBag.image = r.GetImage(); return(View(r)); }
public MainWindow() { InitializeComponent(); PosPageButton = -1; IsSeleceFavoritelst = false; AnimationButton.ins.SetButtonBefore(DashboardButton); MylstRecipes = new ObservableCollection <Recipe>(RecipeDAO.GetAllForLst()); MylstRecipes_Favorite = new ObservableCollection <Recipe>(MylstRecipes.Where(item => item.IsFavorite == true).ToList()); CollectionView View = (CollectionView)CollectionViewSource.GetDefaultView(MylstRecipes); View.Filter = item => { if (String.IsNullOrEmpty(SearchText.Text)) { return(true); } else { return((item as Recipe).Name.IndexOf(SearchText.Text, StringComparison.OrdinalIgnoreCase) >= 0); } }; SearchResult.ItemsSource = MylstRecipes; currentNumberEle = Global.MaxColOfList * Global.MaxRowOfList; maxnumber = (MylstRecipes.Count / currentNumberEle) + (((MylstRecipes.Count % currentNumberEle) == 0) ? 0 : 1); CheckShowPageNumber(); lstRecipe.ItemsSource = MylstRecipes.Take(currentNumberEle); }
public bool Login(String username, String password) { try { User u = UserDAO.getUser(username, password); if (u != null) { currentUser = u; currentUser.AddAllRecipes(RecipeDAO.GetAll(currentUser.id)); currentUser.AddAllShoppingLists(ShoppingListDAO.GetAll(currentUser.id)); return(true); } else { return(false); } } catch (MySqlException mse) { return(false); //@TODO: adding logging! } }
public IActionResult Create() { RecipeDAO dao = new RecipeDAO(); Recipe recipe = new Recipe(); return(View(recipe)); }
public IActionResult Edit(int id) { RecipeDAO dao = new RecipeDAO(); Recipe recipe = dao.FindById(id); return(View(recipe)); }
public IActionResult Index() { RecipeDAO dao = new RecipeDAO(); List <Recipe> Recipes = dao.LoadRecipes(); return(View(Recipes)); }
/** * A list on simple reipe objects are retrived from the database, using the DAO pattern, * where the implementation utelizes the entity framework * */ public ActionResult Index() { // get all recipes with images List <DisplaySimpleRecipe> listOfREcipeWithNoImage = RecipeDAO.GetDisplaySimpleRecipes(); return(View(listOfREcipeWithNoImage)); }
public IActionResult Index() { var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); int idUser = int.Parse(claim.Value); RecipeDAO dao = new RecipeDAO(); UserDAO daou = new UserDAO(); Utilizador u = daou.FindById(idUser); List <Recipe> recipes = dao.LoadRecipeByType(u.Preferencia); Dictionary <int, float> rating = dao.allRatings(); List <KeyValuePair <int, float> > sortingDic = rating.ToList(); sortingDic.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value)); List <Recipe> cardRecipes = new List <Recipe>(); foreach (KeyValuePair <int, float> pairs in sortingDic.Take(2)) { cardRecipes.Add(dao.FindById(pairs.Key)); } List <Recipe> aux = dao.LoadRecipes(); foreach (Recipe t in cardRecipes) { bool flag = aux.Remove(t); Console.WriteLine(flag); } Random rnd = new Random(); for (int i = 0; i < 2; i++) { if (aux.Count > 0) { int rand = rnd.Next(aux.Count); Recipe t = aux[rand]; cardRecipes.Add(t); aux.Remove(t); } } List <Recipe> receitas = dao.getFavorites(idUser); List <int> favoritos = new List <int>(); foreach (Recipe recp in receitas) { favoritos.Add(recp.Id_Recipe); } ViewBag.Favorites = favoritos; ViewBag.Ratings = rating; ViewBag.CardRecipe = cardRecipes; return(View(recipes)); }
/// <summary> /// Delete the selected recipe from User list & Database /// </summary> /// <param name="index">index of recipe</param> public void Delete(int index) { if (index >= 0 && index < recipe.Count) { RecipeDAO.DeleteRecipe(recipe[index]); recipe.RemoveAt(index); recipeManager.GetCurrentUser().RemoveRecipe(index); } }
public IActionResult Shopping(int id) { RecipeDAO dao = new RecipeDAO(); Recipe recipe = dao.FindById(id); ViewBag.Image = recipe.GetImage(); return(View(recipe)); }
public InformationBatender() { this._orderDAO = (OrderDAO) new OrderDAOImpl(); this._orderItemDAO = (OrderItemDAO) new OrderItemDAOImpl(); this._recipeDAO = (RecipeDAO) new RecipeDAOImpl(); this._recipeDetailDAO = (RecipeDetailDAO) new RecipeDetailDAOImpl(); this._foodAndDrinkDAO = (FoodAndDrinkDAO) new FoodAndDrinkDAOImpl(); this._ingredientDAO = (IngredientDAO) new IngredientDAOImpl(); this._ingredientMessageDAO = (IngredientMessageDAO) new IngredientMessageDAOImpl(); this._ingreExchangeDAO = (IngreExchangeDAO) new IngreExchangeDAOImpl(); }
private void AddRecipeButton_Click(object sender, RoutedEventArgs e) { AddRecipe addRecipe = new AddRecipe(); addRecipe.AddRecipeIntoLst += new AddRecipe.MyDelegate(target => { MylstRecipes.Add(RecipeDAO.GetAllInfoByID(target)); }); addRecipe.Closed += new EventHandler((o, f) => { LoadElementsWithPageNumber(); }); addRecipe.Show(); }
public IActionResult Favorites() { var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Name); string username = claim.Value; UserDAO dao = new UserDAO(); Utilizador user = dao.FindByUsername(username); RecipeDAO rdao = new RecipeDAO(); List <Recipe> favoritos = rdao.getFavorites(user.Id_utilizador); ViewBag.User = user; ViewBag.Favoritos = favoritos; return(View()); }
public ActionResult CreateRecipe() { String recipeName = ""; String longDescription = ""; String shortDescription; String jsonIngredientList = null; HttpPostedFileBase image_file = Request.Files["image"]; List <JsonIngredient> jsonIngredients = null; //if data is shit foreach (String key in Request.Form.AllKeys) { if (key == "name") { recipeName = Request.Form[key]; } if (key == "short_desc") { shortDescription = Request.Form[key]; } if (key == "long_desc") { longDescription = Request.Form[key]; } if (key == "ingredients") { jsonIngredientList = Request.Form[key]; jsonIngredients = new JavaScriptSerializer().Deserialize <List <JsonIngredient> >(jsonIngredientList); ViewBag.test1 = jsonIngredientList + ":" + jsonIngredients; } } RecipeDAO.CreateRecipe(new FullRecipe(recipeName, longDescription, jsonIngredients)); if (SaveImage(image_file, recipeName)) { //save the file ViewBag.message = "the recipe have been saved"; SaveImage(image_file, recipeName); } else { ViewBag.message = "the recipe was not saved"; } return(View()); }
public IActionResult Details(int id) { var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); int idUser = int.Parse(claim.Value); UserDAO daou = new UserDAO(); Utilizador u = daou.FindById(idUser); RecipeDAO dao = new RecipeDAO(); Recipe recipe; if (u.Type == 1) { recipe = dao.FindByIdAdmin(id); ViewBag.Admin = true; } else { recipe = dao.FindById(id); ViewBag.Admin = false; } if (recipe == null) { return(RedirectToAction("Index", "User")); } List <Recipe> receitas = dao.getFavorites(idUser); ViewBag.Boolean = false; foreach (Recipe recp in receitas) { if (recp.Id_Recipe == id) { ViewBag.Boolean = true; break; } } ViewBag.image = recipe.GetImage(); int ativo = dao.IsActive(id); ViewBag.Teste = ativo; return(View(recipe)); }
public UserControlHome() { InitializeComponent(); data = RecipeDAO.GetAll(); caclPages(data.Count); //view.Source = recipes; //view.Filter += new FilterEventHandler(view_Filter); //this.recipeList.DataContext = view; //ShowCurrentPageIndex(); this.tbTotalPage.Text = totalPage.ToString(); //recipeList.ItemsSource = data; displayRecipes(); //Debug.WriteLine(currentPageIndex); //Debug.WriteLine(recipesView.Count); }
/** * A full recipe is retirved from the database using the id from the path as the name of the recipe * */ public ActionResult SeeRecipe(String id) { FullRecipe objectToPass; if (id == "" || id == null) { objectToPass = new FullRecipe(); } else { objectToPass = RecipeDAO.GetFullRecipe(id); } // send ther recipe with image object to the view return(View(objectToPass)); }
public IActionResult Edit(Recipe recipe, IFormFile file) { RecipeDAO dao = new RecipeDAO(); if (file != null) { using (MemoryStream ms = new MemoryStream()) { file.CopyToAsync(ms); byte[] b = ms.ToArray(); dao.InsertImage(recipe.Id_Recipe, b); } } dao.Edit(recipe); return(RedirectToAction("Index", "Recipe")); }
public IActionResult Favorite(int id) { string idUser = ""; var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); idUser = claim.Value; int aux = int.Parse(idUser); if (aux > 0) { RecipeDAO dAO = new RecipeDAO(); dAO.AddToFavourite(aux, id); } return(RedirectToAction("Details", "Recipe", new { ID = id })); }
public IActionResult Profile() { var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Name); string username = claim.Value; UserDAO dao = new UserDAO(); Utilizador user = dao.FindByUsername(username); RecipeDAO rdao = new RecipeDAO(); int nReceipts = rdao.NumberReceipts(user.Id_utilizador); int rated = rdao.NumberRated(user.Id_utilizador); int favourites = dao.CalculatePontos(user.Id_utilizador); ViewBag.User = user; ViewBag.NReceipts = nReceipts; ViewBag.Rated = rated; ViewBag.Favourites = favourites; return(View()); }
public IActionResult Approve(int id) { var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); int idUser = int.Parse(claim.Value); UserDAO dao = new UserDAO(); Utilizador u = dao.FindById(idUser); if (u.Type != 1) { return(RedirectToAction("Index", "User")); } RecipeDAO daor = new RecipeDAO(); daor.ApproveRecipe(id); return(RedirectToAction("Colab", "User")); }
private void _initiation() { full_list = RecipeDAO.getDataFromJson(""); favorite_list = RecipeDAO.getFavoriteList(); top_list = new ObservableCollection <Recipe>(); center_list = new ObservableCollection <Recipe>(); bottom_list = new ObservableCollection <Recipe>(); pagination = new VMPagination(); PaginationModel model = new PaginationModel(full_list.Count(), 12); pagination.seed(model); pagination.pagination.PropertyChanged += Pagination_PropertyChanged; processPage(null); }
public IActionResult History() { var id_temp_rec = TempData["Id"]; var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Sid); if (id_temp_rec == null || claim == null) { return(RedirectToAction("Index", "User")); } int id_recipe = int.Parse(id_temp_rec.ToString()); string idUser = claim.Value; int aux = int.Parse(idUser); RecipeDAO dao = new RecipeDAO(); dao.AddHistory(aux, id_recipe); return(RedirectToAction("Index", "User")); }
public IActionResult Index() { var id = TempData["Id"]; if (id == null) { return(RedirectToAction("Index", "User")); } int id_recipe = int.Parse(id.ToString()); RecipeDAO dao = new RecipeDAO(); Recipe r = dao.FindById(id_recipe); if (r == null) { return(RedirectToAction("Index", "User")); } ViewBag.Image = r.GetImage(); return(View(r)); }
/// <summary> /// This will check if the input of the controls are correct. After this it will determine if the user /// edit an existing Recipe or is creating a new one and will add / "update" (delete and add) it to /// the specified database. /// </summary> /// <param name="name">Name / Title of the recipe</param> /// <param name="description">Description of the recipe</param> /// <returns>true = added the recipe to the database; false = input incorrect</returns> public bool AddDB(string name, string description) { if (!String.IsNullOrEmpty(name) && !String.IsNullOrEmpty(description) && ingredients.Count > 0) { tempRecipe.title = name; tempRecipe.description = description; tempRecipe.ingredients = ingredients; if (edit) { RecipeDAO.DeleteRecipe(recipeManager.GetCurrentUser().recipes[index]); tempRecipe.id = recipeManager.GetCurrentUser().recipes[index].id; recipeManager.GetCurrentUser().recipes.RemoveAt(index); recipeManager.GetCurrentUser().recipes.Insert(index, tempRecipe); RecipeDAO.AddRecipeAsync(tempRecipe, tempRecipe.id); } else { int result = RecipeDAO.AddRecipeAsync(tempRecipe); if (result >= 0) { tempRecipe.id = result; } //Add it to running instance recipeManager.GetCurrentUser().AddRecipe(tempRecipe); } return(true); } else { return(false); } }
public IActionResult Colab() { var claim = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.Role); int role = int.Parse(claim.Value); if (role != 1) { return(RedirectToAction("Index", "User")); } RecipeDAO rdao = new RecipeDAO(); UserDAO udao = new UserDAO(); List <Recipe> aproval = rdao.NeedAproval(); List <int> goodBoys = udao.IdUpgradeColab(); List <Utilizador> goodBoyz = new List <Utilizador>(); Dictionary <int, Triplo> myDict = new Dictionary <int, Triplo>(); foreach (int u in goodBoys) { Utilizador goColab = udao.FindById(u); goodBoyz.Add(goColab); int nReceipts = rdao.NumberReceipts(u); int rated = rdao.NumberRated(u); int points = udao.CalculatePontos(u); Triplo infos = new Triplo(nReceipts, rated, points); myDict.Add(u, infos); } ViewBag.Dic = myDict; ViewBag.Need = aproval; ViewBag.GoodBoyz = goodBoyz; return(View()); }