public async Task <GetEventModel> GetRandomEvent(RandomEventFilter filter, Guid personUid) { var repositoryFilter = _mapper.Map <RepositoryRandomEventFilter>(filter); var personEntity = await _personRepository.GetPerson(personUid); repositoryFilter.Age = personEntity.Age.Value; repositoryFilter.PersonUid = personUid; repositoryFilter.IgnoringEventList = await _personRepository.GetPersonSwipeHistory(personEntity.PersonId); var entity = await _eventRepository.GetRandomEvent(repositoryFilter); return(_mapper.Map <GetEventModel>(entity)); }
public async Task <ActionResult <GetEventModel> > GetRandomEvent(RandomEventFilter randomEventFilter) { var uid = new Guid(HttpContext.Request.Headers[AuthorizationHeaders.PersonUid].First()); var validationResult = _eventValidation.ValidateGetRandomEvent(randomEventFilter); if (!validationResult.ValidationResult) { return(BadRequest(validationResult.ValidationMessage)); } var randomEvent = await _eventLogic.GetRandomEvent(randomEventFilter, uid); if (randomEvent == null) { return(BadRequest(ErrorDictionary.GetErrorMessage(25, CultureParser.GetCultureFromHttpContext(HttpContext)))); } return(randomEvent); }
public (bool ValidationResult, string ValidationMessage) ValidateGetRandomEvent(RandomEventFilter filter) { if (filter.PersonXCoordinate < 0) { return(false, ErrorDictionary.GetErrorMessage(23, _culture)); } if (filter.PersonYCoordinate < 0) { return(false, ErrorDictionary.GetErrorMessage(23, _culture)); } if (filter.CityId.HasValue) { var cities = _cityLogic.GetCities().Result; if (!cities.Any(x => x.CityId == filter.CityId)) { return(false, ErrorDictionary.GetErrorMessage(30, _culture)); } } if (filter.EventTypes != null && filter.EventTypes.Any()) { foreach (var type in filter.EventTypes) { if (!Enum.IsDefined(typeof(EventType), type)) { return(false, ErrorDictionary.GetErrorMessage(14, _culture)); } } } return(true, string.Empty); }