public async Task <IActionResult> PostAsync(int locatableId, [FromBody] SaveReviewResource resource, int userProfileId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var existingLocatable = await _locatableService.GetByIdAsync(locatableId);

            var existingUserProfile = await _userProfileService.FindById(userProfileId);

            if (!existingLocatable.Success)
            {
                return(BadRequest(existingLocatable.Message));
            }
            if (!existingUserProfile.Success)
            {
                return(BadRequest(existingUserProfile.Message));
            }

            var review = _mapper.Map <SaveReviewResource, Review>(resource);

            review.Locatable   = existingLocatable.Resource;
            review.UserProfile = existingUserProfile.Resource;

            var result = await _reviewService.SaveAsync(review);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var reviewResource = _mapper.Map <Review, ReviewResource>(result.Resource);

            return(Ok(reviewResource));
        }
        public async Task <IActionResult> GetByIdAsync(int id)
        {
            var result = await _locatableService.GetByIdAsync(id);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var locatableResource = _mapper.Map <Locatable, LocatableResource>(result.Resource);

            return(Ok(locatableResource));
        }
        public async Task <IActionResult> GetReviewsByLocatableIdAsync(int locatableId)
        {
            var existingLocatable = await _locatableService.GetByIdAsync(locatableId);

            if (!existingLocatable.Success)
            {
                return(BadRequest(existingLocatable.Message));
            }

            var reviews = await _reviewService.ListByLocatableIdAsync(locatableId);

            var resources = _mapper.Map <IEnumerable <Review>, IEnumerable <ReviewResource> >(reviews);

            return(Ok(resources));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PostAsync(int locatableId, int userProfileId, [FromBody] SaveTipResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var existingLocatable = await _locatableService.GetByIdAsync(locatableId);

            var existingUserProfile = await _userProfileService.FindById(userProfileId);

            if (!existingLocatable.Success)
            {
                return(BadRequest(existingLocatable.Message));
            }
            if (!existingUserProfile.Success)
            {
                return(BadRequest(existingUserProfile.Message));
            }

            var tip = _mapper.Map <SaveTipResource, Tip>(resource);

            tip.Locatable = existingLocatable.Resource;
            //tip.User = existingUser.Resource;
            tip.UserProfile = existingUserProfile.Resource;

            var result = await _tipService.SaveAsync(tip);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var tipResource = _mapper.Map <Tip, TipResource>(result.Resource);

            return(Ok(tipResource));
        }