Exemplo n.º 1
0
        public async Task <IActionResult> PutAsync(int locatableId, int userProfileId, int tipId, [FromBody] SaveTipResource resource)
        {
            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);
            var result = await _tipService.UpdateAsync(tipId, tip);

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

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

            return(Ok(tipResource));
        }
Exemplo n.º 2
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));
        }