public async Task <WinesVM> WineSourceIndexList() { WinesVM wvm = await WineIndexList(); if (_signInManager.IsSignedIn(User)) { List <Source> getSources = await _filtersServices.GetSourceAsync(); wvm.ListSources = new List <Source>(); if (_signInManager.IsSignedIn(User)) { foreach (Source source in getSources) { if (wvm.ListUserSourceTaste[0].SourceId == source.Id) { wvm.ListSources.Add(source); } else if (wvm.ListUserSourceTaste[1].SourceId == source.Id) { wvm.ListSources.Add(source); } } } Random rnd = new Random(); int numberRandom = rnd.Next(0, getSources.Count - 1); bool salir = false; do { if (!wvm.ListSources.Contains(getSources[numberRandom])) { wvm.ListSources.Add(getSources[numberRandom]); salir = true; } } while (!salir); return(wvm); } else { List <Source> sources = await _filtersServices.GetSourceAsync(); wvm.ListSources = new List <Source>(); Random rnd = new Random(); int cont = 0; do { int numberRandom = rnd.Next(0, sources.Count - 1); if (!wvm.ListSources.Contains(sources[numberRandom])) { wvm.ListSources.Add(sources[numberRandom]); cont++; } } while (cont < 4); return(wvm); } }
public async Task <WinesVM> WineIndexList() { if (_signInManager.IsSignedIn(User)) { WinesVM wvm = await GetUserPreferences(); List <Wine> wineTasteList = new List <Wine>(); foreach (Wine wine in await _winesServices.GetWinesAsync()) { if (wine.ColourId == wvm.ListUserColourTaste[0].ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[0].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[0].SourceId) { wineTasteList.Add(wine); } else if (wine.ColourId == wvm.ListUserColourTaste[0].ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[0].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[1].SourceId) { wineTasteList.Add(wine); } else if (wine.ColourId == wvm.ListUserColourTaste[1].ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[1].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[2].SourceId) { wineTasteList.Add(wine); } } Random rnd = new Random(); wvm.ListWineTaste = new List <Wine>(); for (int i = 0; i < 3; i++) { if (wineTasteList.Count != 0 && wineTasteList.Count > i) { bool salir = false; do { int numberRandom = rnd.Next(0, wineTasteList.Count - 1); if (!wvm.ListWineTaste.Contains(wineTasteList[numberRandom])) { wvm.ListWineTaste.Add(wineTasteList[numberRandom]); salir = true; } } while (!salir); } else { break; } } return(wvm); } else { WinesVM wvm = new WinesVM(); wvm.ListWineTaste = await _winesServices.GetWinesAsync(); wvm.ListWineTaste = wvm.ListWineTaste.OrderByDescending(x => x.Score).ToList().GetRange(0, 3); return(wvm); } }
public async Task <IActionResult> Index() { var user = await _userManager.FindByEmailAsync(User.Identity.Name); List <WineList> listWineList = await _wineListsServices.GetWineListsByUserIdAsync(user.Id); WinesVM wvm = new WinesVM { ListWinesLists = listWineList, AppUser = user }; return(View(wvm)); }
public async Task <WinesVM> GetUserPreferences() { var user = await _userManager.FindByEmailAsync(User.Identity.Name); List <ColourTaste> listColourTastes = await _tastesServices.GetColourTasteesByUserIdAsync(user.Id); List <SourceTaste> listSourceTastes = await _tastesServices.GetSourceTasteesByUserIdAsync(user.Id); List <SweetnessTaste> listSweetnessTastes = await _tastesServices.GetSweetnessTasteesByUserIdAsync(user.Id); WinesVM wvm = new WinesVM { ListUserColourTaste = listColourTastes.OrderByDescending(x => x.Score).ToList().GetRange(0, 3), ListUserSourceTaste = listSourceTastes.OrderByDescending(x => x.Score).ToList().GetRange(0, 3), ListUserSweetnessTaste = listSweetnessTastes.OrderByDescending(x => x.Score).ToList().GetRange(0, 3), }; return(wvm); }
public async Task <IActionResult> ViewsFavorite(int?id) { AppUser user = await _userManager.FindByEmailAsync(User.Identity.Name); bool exitWineListsWine = _wineListsServices.Exit(id, user.Id); Wine wine = await _winesServices.GetWineByIdAsync(id); WinesVM wvm = new WinesVM { ListWinesLists = await _wineListsServices.GetWineListsByUserIdAsync(user.Id), Wine = wine, WinelistsWineExit = exitWineListsWine }; if (exitWineListsWine == true) { wvm.WineListWine = await _wineListsServices.IfExitWineListWine(id, user.Id); } return(View(wvm)); }
public async Task <IActionResult> Index() { WinesVM wvm = await WineSourceIndexList(); return(View(wvm)); }
public async Task <IActionResult> SourcePreferences(int sourceId) { if (_signInManager.IsSignedIn(User)) { WinesVM wvm = await GetUserPreferences(); wvm.Source = await _filtersServices.GetSourceByIdAsync(sourceId); wvm.ListSources = await _filtersServices.GetSourceAsync(); List <Wine> wines = await _winesServices.GetWinesAsync(); wines = wines.Where(x => x.Source.Id == sourceId).ToList(); AppUser user = await _userManager.FindByEmailAsync(User.Identity.Name); await _tastesServices.InsertClickValues(0, wvm.Source.Id, 0, 1, user.Id); List <Wine> firstPreference = new List <Wine>(); List <Wine> secondPreference = new List <Wine>(); if (_signInManager.IsSignedIn(User)) { foreach (Wine wine in wines) { if (wvm.ListUserColourTaste[0].ColourId == wine.ColourId && wvm.ListUserSweetnessTaste[0].SweetnesId == wine.SweetnesId) { firstPreference.Add(wine); } else if (wvm.ListUserColourTaste[0].ColourId == wine.ColourId && wvm.ListUserSweetnessTaste[1].SweetnesId == wine.SweetnesId) { secondPreference.Add(wine); } else if (wvm.ListUserColourTaste[1].ColourId == wine.ColourId && wvm.ListUserSweetnessTaste[1].SweetnesId == wine.SweetnesId) { secondPreference.Add(wine); } } } else { firstPreference = await _winesServices.GetWinesAsync(); } wvm.ListWinesTastesSources = new List <Wine>(); Random numberRandom = new Random(); if (firstPreference.Count > 0) { for (int i = 0; i < 3; i++) { if (firstPreference.Count != 0 && firstPreference.Count > i) { bool salir = false; do { int num = numberRandom.Next(0, firstPreference.Count - 1); if (!wvm.ListWinesTastesSources.Contains(firstPreference[num])) { wvm.ListWinesTastesSources.Add(firstPreference[num]); salir = true; } } while (!salir); } else { break; } } } if (secondPreference.Count > 0) { for (int i = 0; i < 1; i++) { if (firstPreference.Count != 0 && firstPreference.Count > i) { bool salir = false; do { int num = numberRandom.Next(0, secondPreference.Count - 1); if (!wvm.ListWinesTastesSources.Contains(secondPreference[num])) { wvm.ListWinesTastesSources.Add(secondPreference[num]); salir = true; } } while (!salir); } else { break; } } } if (wvm.ListWinesTastesSources == null) { wvm.ListWinesTastesSources = wines; } return(View(wvm)); } else { WinesVM wvm = new WinesVM(); wvm.Source = await _filtersServices.GetSourceByIdAsync(sourceId); wvm.ListWinesTastesSources = await _winesServices.GetWinesAsync(); wvm.ListWinesTastesSources = wvm.ListWinesTastesSources.Where(x => x.SourceId == sourceId).ToList(); wvm.ListWinesTastesSources = wvm.ListWinesTastesSources.OrderByDescending(x => x.Score).ToList().GetRange(0, 5); wvm.ListSources = await _filtersServices.GetSourceAsync(); wvm.ListSources = wvm.ListSources.GetRange(0, 6); return(View(wvm)); } }
public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } if (_signInManager.IsSignedIn(User)) { WinesVM wvm = await GetUserPreferences(); wvm.Wine = await _winesServices.GetWineByIdAsync(id); AppUser user = await _userManager.FindByEmailAsync(User.Identity.Name); await _tastesServices.InsertClickValues(wvm.Wine.ColourId, wvm.Wine.SourceId, wvm.Wine.SweetnesId, 1, user.Id); List <Wine> listOne = new List <Wine>(); List <Wine> listTwo = new List <Wine>(); List <Wine> listThree = new List <Wine>(); int colourTasteOne = wvm.ListUserColourTaste[0].ColourId; int sweetnessTasteOne = wvm.ListUserSweetnessTaste[0].SweetnesId; int sourceTasteOne = wvm.ListUserSourceTaste[0].SourceId; //Filtro para sacar los vinos segun gustos foreach (Wine wine in await _winesServices.GetWinesAsync()) { if (wine.ColourId == wvm.Wine.ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[0].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[0].SourceId) { listOne.Add(wine); } else if (wine.ColourId == wvm.Wine.ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[1].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[1].SourceId) { listOne.Add(wine); } else if (wine.ColourId == wvm.Wine.ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[2].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[2].SourceId) { listOne.Add(wine); } else if (wine.ColourId == wvm.ListUserColourTaste[0].ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[0].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[0].SourceId) { listTwo.Add(wine); } else if (wine.ColourId == wvm.ListUserColourTaste[1].ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[1].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[1].SourceId) { listTwo.Add(wine); } else if (wine.ColourId == wvm.ListUserColourTaste[2].ColourId && wine.SweetnesId == wvm.ListUserSweetnessTaste[2].SweetnesId && wine.SourceId == wvm.ListUserSourceTaste[2].SourceId) { listTwo.Add(wine); } else if (wine.SourceId == wvm.Wine.SourceId && wine.SweetnesId == wvm.ListUserSweetnessTaste[0].SweetnesId) { listThree.Add(wine); } else if (wine.SourceId == wvm.Wine.SourceId && wine.SweetnesId == wvm.ListUserSweetnessTaste[1].SweetnesId) { listThree.Add(wine); } else if (wine.SourceId == wvm.Wine.SourceId && wine.SweetnesId == wvm.ListUserSweetnessTaste[2].SweetnesId) { listThree.Add(wine); } else if (wine.SweetnesId == wvm.ListUserSweetnessTaste[0].SweetnesId) { listTwo.Add(wine); } else if (wine.SourceId == wvm.ListUserSourceTaste[0].SourceId) { listThree.Add(wine); } } Random rnd = new Random(); wvm.ListWinesTastesDetails = new List <Wine>(); for (int i = 0; i < 5; i++) { if (listOne.Count != 0 && listOne.Count > i) { bool salir = false; do { int numberRandom = rnd.Next(0, listOne.Count - 1); if (!wvm.ListWinesTastesDetails.Contains(listOne[numberRandom])) { wvm.ListWinesTastesDetails.Add(listOne[numberRandom]); salir = true; } } while (!salir); } else { break; } } for (int i = 0; i < 3; i++) { if (listTwo.Count != 0 && listTwo.Count > i) { bool salir = false; do { int numberRandom = rnd.Next(0, listTwo.Count - 1); if (!wvm.ListWinesTastesDetails.Contains(listTwo[numberRandom])) { wvm.ListWinesTastesDetails.Add(listTwo[numberRandom]); salir = true; } } while (!salir); } else { break; } } for (int i = 0; i < 2; i++) { if (listThree.Count != 0 && listThree.Count > i) { bool salir = false; do { int numberRandom = rnd.Next(0, listThree.Count - 1); if (!wvm.ListWinesTastesDetails.Contains(listThree[numberRandom])) { wvm.ListWinesTastesDetails.Add(listThree[numberRandom]); salir = true; } } while (!salir); } else { break; } } if (wvm.ListWinesTastesDetails.Count == 0) { return(NotFound()); } //lista de los vinos mejor valorados de orde de mayor a menor wvm.ListWineUserScore = await _winesServices.GetWinesAsync(); wvm.ListWineUserScore = wvm.ListWineUserScore.OrderByDescending(x => x.Score).ToList().GetRange(0, 10); return(View(wvm)); } else { WinesVM wvm = new WinesVM(); wvm.Wine = await _winesServices.GetWineByIdAsync(id); wvm.ListWineUserScore = await _winesServices.GetWinesAsync(); wvm.ListWineUserScore = wvm.ListWineUserScore.OrderByDescending(x => x.Score).ToList().GetRange(0, 10); return(View(wvm)); } }