Exemplo n.º 1
0
        public async Task <IActionResult> PutAsync(int id, [FromBody] SaveExperienceResource resource)
        {
            var experience = _mapper.Map <SaveExperienceResource, Experience>(resource);
            var result     = await _experienceService.UpdateAsync(id, experience);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var experienceResource = _mapper.Map <Experience, ExperienceResource>(result.Resource);

            return(Ok(experienceResource));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PostAsync([FromBody] SaveExperienceResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetMessages()));
            }

            var experience = _mapper.Map <SaveExperienceResource, Experience>(resource);
            var result     = await _experienceService.SaveAsync(experience);

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

            var experienceResource = _mapper.Map <Experience, ExperienceResource>(result.Resource);

            return(Ok(experienceResource));
        }