Example #1
0
        public async Task DelateWineListWineValues(int?colourId, int?sourceId, int?sweetId, string userId)
        {
            List <ColourTaste> colourTastes = await GetColourTasteesByUserIdAsync(userId);

            List <SourceTaste> sourceTastes = await GetSourceTasteesByUserIdAsync(userId);

            List <SweetnessTaste> sweetnessTastes = await GetSweetnessTasteesByUserIdAsync(userId);

            if (colourId != 0)
            {
                ColourTaste colourTaste = colourTastes.FirstOrDefault(x => x.ColourId == colourId);
                if (colourTaste.Score < 10)
                {
                    colourTaste.Score -= 4;
                    await UpdateColourTasteAsync(colourTaste);
                }
                else if (colourTaste.Score >= 10)
                {
                    double root     = Convert.ToDouble(colourTaste.Score.ToString().Substring(0, 1)) + 1;
                    double addScore = Math.Sqrt(3 / (Math.Pow(root, root)));
                    colourTaste.Score -= addScore;
                }
            }

            if (sourceId != 0)
            {
                SourceTaste sourceTaste = sourceTastes.FirstOrDefault(x => x.SourceId == sourceId);

                if (sourceTaste.Score < 10)
                {
                    sourceTaste.Score -= 4;
                    await UpdateSourceTasteAsync(sourceTaste);
                }
                else if (sourceTaste.Score >= 10)
                {
                    double root     = Convert.ToDouble(sourceTaste.Score.ToString().Substring(0, 1)) + 1;
                    double addScore = Math.Sqrt(3 / (Math.Pow(root, root)));
                    sourceTaste.Score -= addScore;
                    await UpdateSourceTasteAsync(sourceTaste);
                }
            }

            if (sweetId != 0)
            {
                SweetnessTaste sweetnessTaste = sweetnessTastes.FirstOrDefault(x => x.SweetnesId == sweetId);

                if (sweetnessTaste.Score < 10)
                {
                    sweetnessTaste.Score -= 4;
                    await UpdateSweetnessTasteAsync(sweetnessTaste);
                }
                else if (sweetnessTaste.Score >= 10)
                {
                    double root     = Convert.ToDouble(sweetnessTaste.Score.ToString().Substring(0, 1)) + 1;
                    double addScore = Math.Sqrt(4 / (Math.Pow(root, root)));
                    sweetnessTaste.Score -= addScore;
                    await UpdateSweetnessTasteAsync(sweetnessTaste);
                }
            }
        }
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
        //Inserta los valores en las tablas Tastes cuando el usuario rellena la encuesta,
        //en este caso el valor siempre es 5,
        //independientemente de su valoraciĆ³n total.
        public async Task <ActionResult> InsertSurveyValues(int[] colour, int[] source, int[] sweet)
        {
            if (colour.Length > 0)
            {
                foreach (int col in colour)
                {
                    ColourTaste colourTaste = await _tastesServices.GetColourTasteByIdAsync(col);

                    colourTaste.Score += 5;
                    await _tastesServices.UpdateColourTasteAsync(colourTaste);
                }
            }
            if (source.Length > 0)
            {
                foreach (int sor in source)
                {
                    SourceTaste sourceTaste = await _tastesServices.GetSourceTasteByIdAsync(sor);

                    sourceTaste.Score += 5;
                    await _tastesServices.UpdateSourceTasteAsync(sourceTaste);
                }
            }
            if (sweet.Length > 0)
            {
                foreach (int swe in sweet)
                {
                    SweetnessTaste sweetnessTaste = await _tastesServices.GetSweetnessTasteByIdAsync(swe);

                    sweetnessTaste.Score += 5;
                    await _tastesServices.UpdateSweetnessTasteAsync(sweetnessTaste);
                }
            }
            AppUser user = await _userManager.GetUserAsync(User);

            user.Survey = true;
            await _userManager.UpdateAsync(user);

            return(RedirectToActionPreserveMethod("Index", "Home"));
        }
Example #4
0
 public async Task UpdateSweetnessTasteAsync(SweetnessTaste sweetnessTaste)
 {
     _context.Update(sweetnessTaste);
     await _context.SaveChangesAsync();
 }
Example #5
0
 public async Task DeleteSweetnessTasteAsync(SweetnessTaste sweetnessTaste)
 {
     _context.SweetnessTastes.Remove(sweetnessTaste);
     await _context.SaveChangesAsync();
 }
Example #6
0
        //SWEETNESS TASTE
        public async Task CreateSweetnessTasteAsync(SweetnessTaste sweetnessTaste)
        {
            await _context.AddAsync(sweetnessTaste);

            await _context.SaveChangesAsync();
        }