示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CountryId,UserId,HighlightOfTrip,RatingOfTrip,StartOfTrip,EndOfTrip,hasVisited,hasntVisited")] CountryVisited countryVisited)
        {
            if (id != countryVisited.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(countryVisited);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CountryVisitedExists(countryVisited.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(countryVisited));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("NativeLanguage,Id,Comments,CountryName,CountryId,UserId,HighlightOfTrip,RatingOfTrip,StartOfTrip,EndOfTrip,hasVisited,PhotoOfTrip")] CountryVisited countryVisited)
        {
            if (ModelState.IsValid)
            {
                var         userCurrentUser = User.Identity.Name;
                UserProfile selectedUser;
                selectedUser = _context.UserProfile.Where(p => p.Email == User.Identity.Name).Single();
                var countryFound = await _context.Countries
                                   .FirstOrDefaultAsync(m => m.Name == countryVisited.CountryName);

                countryVisited.CountryId   = countryFound.Id;
                countryVisited.UserId      = selectedUser.Id;
                countryVisited.StarsOfTrip = ratingToStars(countryVisited.RatingOfTrip);
                _context.Add(countryVisited);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(countryVisited));
        }
示例#3
0
        public async Task <IActionResult> Scoreboard()
        {
            List <double> ratedTrips     = new List <double>();
            var           user           = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var           userName       = _context.Users.Where(p => p.Id == user).Single();
            var           userFound      = _context.UserProfile.Where(p => p.Email == userName.UserName).Single();
            var           countriesFound = _context.CountriesVisited.Where(p => p.UserId == userFound.Id).ToList();

            foreach (CountryVisited item in countriesFound)
            {
                ratedTrips.Add(item.RatingOfTrip);
            }
            //List<int> lst = ints.OfType<int>().ToList();tuff
            double[] ratedTripsArray = ratedTrips.ToArray();
            double[] result          = new double[3];
            for (int i = 0; i < ratedTrips.Count; i++)
            {
                if (ratedTrips[i] <= result[0])
                {
                    continue;
                }
                else
                {
                    if (ratedTrips[i] > result[2])
                    {
                        for (int l = 0; l < 2; l++)
                        {
                            result[l] = result[l + 1];
                        }
                        result[2] = ratedTripsArray[i];
                    }
                    else
                    {
                        int indexLeft  = 0;
                        int indexRight = 2;
                        int currIndex  = 0;
                        while (indexRight - indexLeft > 1)
                        {
                            currIndex = (indexRight + indexLeft) / 2;
                            if (ratedTripsArray[i] >= result[currIndex])
                            {
                                indexLeft = currIndex;
                            }
                            else
                            {
                                indexRight = currIndex;
                            }
                        }

                        for (int l = 0; l < currIndex; l++)
                        {
                            result[l] = result[l + 1];
                        }
                        result[currIndex] = ratedTripsArray[i];
                    }
                }
            }
            CountryVisited        topVisitedCountry   = new CountryVisited();
            List <CountryVisited> topVisitedCountries = new List <CountryVisited>();

            for (int i = 0; i < result.Length; i++)
            {
                topVisitedCountry = countriesFound.Where(c => c.RatingOfTrip == result[i]).Select(c => c).Single();
                topVisitedCountries.Add(topVisitedCountry);
            }
            return(View(topVisitedCountries));
        }