Esempio n. 1
0
        public async Task <IActionResult> UpdateAsync(int id, [FromBody] SaveAchievementResource resource)
        {
            var achievement = _mapper.Map <SaveAchievementResource, Achievement>(resource);
            var result      = await _achievementService.UpdateAsync(id, achievement);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var achievementResource = _mapper.Map <Achievement, AchievementResource>(result.Resource);

            return(Ok(achievementResource));
        }
Esempio n. 2
0
        public async Task <IActionResult> PostAsync([FromBody] SaveAchievementResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var achievement = _mapper.Map <SaveAchievementResource, Achievement>(resource);
            var result      = await _achievementService.SaveAsync(achievement);

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

            var achievementResource = _mapper.Map <Achievement, AchievementResource>(result.Resource);

            return(Ok(achievementResource));
        }