public async Task <IActionResult> PutHolidayPreference(HolidayPreferences updatePreference) { var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var preferences = await _repo.GetUserHolidayPreferences(userId); if (preferences == null) { return(NotFound(new ApiResponse(404))); } preferences.MaxPrice = updatePreference.MaxPrice; preferences.Websites = updatePreference.Websites; _repo.SaveChanges(); return(Ok(_mapper.Map <HolidayPreferences, HolidayPreferencesDTO>(preferences))); }
public async Task <IActionResult> PostUserPreferences(HolidayPreferences holidayPreferences) { var userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var user = await _repo.GetUserWithHolidayPreferences(userId); user.HolidayPreferences = holidayPreferences; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(Ok(_mapper.Map <HolidayPreferences, HolidayPreferencesDTO>(holidayPreferences))); } return(BadRequest("Problem with add new preferences")); }
public IEnumerable <HolidayOffers> GetHolidayOffersByUserHolidayPreference(IEnumerable <HolidayOffers> holidayOffers, HolidayPreferences holidayPreference, string sort) { List <string> preferenceWebsitesList = new List <string>(); foreach (var holidayPreferencesWebsite in holidayPreference.Websites) { preferenceWebsitesList.Add(holidayPreferencesWebsite.Website); } var filteredOffers = holidayOffers .Where((o) => preferenceWebsitesList.Contains(o.Website)) .Where((o) => o.Price <= holidayPreference.MaxPrice) .ToList(); switch (sort) { case "priceAsc": return(filteredOffers.OrderBy(s => s.Price)); case "priceDesc": return(filteredOffers.OrderByDescending(o => o.Price)); default: return(filteredOffers); } }