예제 #1
0
        public async Task <IActionResult> Create([FromBody] SkillRequest skillRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Skill skill = new Skill {
                Name = skillRequest.Name, Level = skillRequest.Level, ContactID = skillRequest.ContactID
            };

            skill.SkillID = Guid.NewGuid();
            skill.UserID  = HttpContext.GetUserId();

            skill.Contact = await _contactService.GetContactByIdAsync(skill.ContactID);

            if (skill.Contact == null)
            {
                ModelState.AddModelError("ContactID", $"Contact {skill.ContactID} not found.");
                return(BadRequest(ModelState));
            }

            bool created = await _skillService.CreateSkillAsync(skill);

            var locationUri = _uriService.GetSkillUri(skill.SkillID.ToString());

            return(Created(locationUri, new Response <Skill>(skill)));
        }
예제 #2
0
        public async Task <ActionResult <SkillModel> > CreateSkillAsync(int breedId, int heroId, [FromBody] SkillModel skill)
        {
            try
            {
                await _skillService.CreateSkillAsync(heroId, skill);

                return(CreatedAtRoute("GetSkill", new { breedId = breedId, heroId = heroId, skillId = skill.Id }, skill));
            }
            catch (NotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Something happend: {ex.Message}"));
            }
        }