public async Task <ServiceResponce <GetCharecterDTO> > AddCharecterSkill(AddCharecterSkillDTO newCharecterSkill) { ServiceResponce <GetCharecterDTO> responce = new ServiceResponce <GetCharecterDTO>(); try{ Charecter charecter = await _context.Charecters .Include(c => c.Weapon) .Include(c => c.CharecterSkills).ThenInclude(cs => cs.Skill) .FirstOrDefaultAsync(c => c.Id == newCharecterSkill.CharecterId && c.User.Id == int.Parse(_httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier))); if (charecter == null) { responce.Success = false; responce.Message = "Charecter not found."; return(responce); } Skill skill = await _context.Skills.FirstOrDefaultAsync(s => s.Id == newCharecterSkill.SkillId); if (skill == null) { responce.Success = false; responce.Message = "Skill not found."; return(responce); } CharecterSkill characterSkill = new CharecterSkill() { Charecter = charecter, Skill = skill }; await _context.CharecterSkills.AddAsync(characterSkill); await _context.SaveChangesAsync(); responce.Data = _mapper.Map <GetCharecterDTO>(charecter); } catch (Exception ex) { responce.Success = false; responce.Message = ex.Message; } return(responce); }
public async Task <IActionResult> AddCharecterSkill(AddCharecterSkillDTO newCharecterSkill) { return(Ok(await _charecterSkillService.AddCharecterSkill(newCharecterSkill))); }