Example #1
0
        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);
            }
        }
Example #2
0
        public async Task <IActionResult> OnGetAsync(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(RedirectToPage("/Index"));
            }

            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{userId}'."));
            }
            foreach (Colour colour in await _filtersServices.GetColourAsync())
            {
                ColourTaste colourTaste = new ColourTaste();
                colourTaste.ColourId  = colour.Id;
                colourTaste.AppUserId = userId;
                colourTaste.Score     = 0;
                await _tasteServices.CreateColourTasteAsync(colourTaste);
            }
            foreach (Source source in await _filtersServices.GetSourceAsync())
            {
                SourceTaste sourceTaste = new SourceTaste();
                sourceTaste.SourceId  = source.Id;
                sourceTaste.AppUserId = userId;
                sourceTaste.Score     = 0;
                await _tasteServices.CreateSourceTasteAsync(sourceTaste);
            }
            foreach (Sweetnes sweetnes in await _filtersServices.GetSweetnesAsync())
            {
                SweetnessTaste sweetnessTaste = new SweetnessTaste();
                sweetnessTaste.SweetnesId = sweetnes.Id;
                sweetnessTaste.AppUserId  = userId;
                sweetnessTaste.Score      = 0;
                await _tasteServices.CreateSweetnessTasteAsync(sweetnessTaste);
            }

            WineList wineList = new WineList
            {
                AppUserId   = userId,
                ListDate    = DateTime.Now,
                ListName    = "Favoritos",
                Description = "Vinos favoritos"
            };

            await _wineListsServices.CreateWineListAsync(wineList);

            code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
            var result = await _userManager.ConfirmEmailAsync(user, code);

            StatusMessage = result.Succeeded ? "Gracias por registrarte en VinoNet." : "/*No te has podido registrar correctamente.*/";
            return(Page());
        }
Example #3
0
        public async Task <ActionResult> Survey()
        {
            List <SourceTaste> sourcetaste = await _tastesServices.GetSourceTastesAsync();

            List <ColourTaste> colourtaste = await _tastesServices.GetColourTastesAsync();

            List <SweetnessTaste> sweetnesstaste = await _tastesServices.GetSweetnessTastesAsync();

            var user = await _userManager.FindByEmailAsync(User.Identity.Name);

            TastesVM tvm = new TastesVM
            {
                ListColours   = await _filtersServices.GetColourAsync(),
                ListSources   = await _filtersServices.GetSourceAsync(),
                ListSweetness = await _filtersServices.GetSweetnesAsync(),

                SourceTastes   = sourcetaste.Where(x => x.AppUser.Id == user.Id).ToList(),
                ColourTastes   = colourtaste.Where(x => x.AppUser.Id == user.Id).ToList(),
                SweetnesTastes = sweetnesstaste.Where(x => x.AppUser.Id == user.Id).ToList(),
            };

            return(View(tvm));
        }
Example #4
0
        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));
            }
        }