public IActionResult Get(int id) { var request = new PlaceIdRequest { Id = id }; _logger.Information(LoggingMessages.GettingPlaceById(id)); var response = _placeServices.GetPlace(request); if (!response.Result) { return(BadRequest(response.Errors)); } if (response.Place == null) { return(NotFound("Place Not Found.")); } return(Ok(response.Place)); }
private Result <StorageAdEditInfo> GetValidatedStorageAdEditInfo(AdEditInfo ad) { if (ad == null) { Result <StorageAdEditInfo> .NewFailure($"{nameof(ad)} is NULL."); } var result = new StorageAdEditInfo(); result.AdId = ad.AdId; // UserId; //var resultUserAds = GetUserAds(ad.UserId); //if (!resultUserAds.Success) // return Result<StorageAdEditInfo>.NewFailure($"Failed to receive user ads by user id: '{ad.UserId}'."); //if (resultUserAds.Value.Any()) // return Result<StorageAdEditInfo>.NewFailure("User already has an ad."); result.UserId = ad.UserId; //PlaceId; var maybePlace = _placesService.GetPlace(ad.PlaceId); if (!maybePlace.Success) { return(Result <StorageAdEditInfo> .NewFailure($"Can't find place by id: {ad.PlaceId}.")); } if (!maybePlace.Value.IsEnabled) { return(Result <StorageAdEditInfo> .NewFailure($"Place '{maybePlace.Value.PlaceCode}' is not enabled.")); } if (maybePlace.Value.PlaceType != PlaceType.City) { return(Result <StorageAdEditInfo> .NewFailure($"Place '{maybePlace.Value.PlaceCode}' is not of type '{PlaceType.City}'.")); } result.PlaceId = ad.PlaceId; //Name; result.Name = ad.Name; //DateBorn; if (ad.DateBorn < DateTime.Now.AddYears(-80) || ad.DateBorn > DateTime.Now.AddYears(-18)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.DateBorn)} is invalid. (Too old or too young.")); } result.DateBorn = ad.DateBorn; //GenderId; if (!ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.Gender, objectId: ad.GenderId)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.GenderId)} did not pass validation.")); } result.GenderId = ad.GenderId; //HeightCm; if (ad.HeightCm.HasValue && (ad.HeightCm.Value < 110 || ad.HeightCm > 250)) { return(Result <StorageAdEditInfo> .NewFailure($"Height is invalid.")); } result.HeightCm = ad.HeightCm; //WeightGr; if (ad.WeightGr.HasValue && (ad.WeightGr < 30 * 1000 || ad.WeightGr > 200 * 1000)) { return(Result <StorageAdEditInfo> .NewFailure($"Weight is invalid.")); } result.WeightGr = ad.WeightGr; //EyeColorId; if (ad.EyeColorId.HasValue && !ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.EyeColor, objectId: ad.EyeColorId.Value)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.EyeColorId)} did not pass validation.")); } result.EyeColorId = ad.EyeColorId; //HairColorId; if (ad.HairColorId.HasValue && !ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.HairColor, objectId: ad.HairColorId.Value)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.HairColorId)} did not pass validation.")); } result.HairColorId = ad.HairColorId; //HairLengthId; if (ad.HairLengthId.HasValue && !ObjectIsEnabledOfType(objectTypeCode: ObjectTypeCodes.HairLength, objectId: ad.HairLengthId.Value)) { return(Result <StorageAdEditInfo> .NewFailure($"{nameof(ad.HairLengthId)} did not pass validation.")); } result.HairLengthId = ad.HairLengthId; return(Result <StorageAdEditInfo> .NewSuccess(result)); }
public async Task <ActionResult <Place> > GetPlace([FromRoute] string id) { return(Ok(await _placesService.GetPlace(id))); }