public async Task <ServiceResponse <GetCharacterDto> > AddSkill(AddSkillDto newSkill)
        {
            _log.LogInformation("Start Add Skill process.");
            var skill = await _dBContext.Skills.FirstOrDefaultAsync(x => x.Name == newSkill.Name.Trim());

            if (!(skill is null))
            {
                _log.LogError("Duplicated Skill Name.");
                return(ResponseResult.Failure <GetCharacterDto>("Duplicated Skill Name."));
            }

            _log.LogInformation("Add New Skill.");
            var addSkill = new Skill
            {
                Name   = newSkill.Name,
                Damage = newSkill.Damage,
            };

            _dBContext.Skills.Add(addSkill);
            await _dBContext.SaveChangesAsync();

            _log.LogInformation("Success.");

            var dto = _mapper.Map <GetCharacterDto>(addSkill);

            _log.LogInformation("End.");
            return(ResponseResult.Success(dto));
        }
        public int AddSkill(AddSkillDto add)
        {
            _uow.Skill.Insert(new Skill
            {
                Name  = add.Name,
                Score = add.Score
            });

            return(_uow.SaveChanges());
        }
Exemple #3
0
        public async Task <IActionResult> PostSkill(AddSkillDto newSkill)
        {
            ServiceResponse <GetSkillDto> response = await _skillService.AddSkill(newSkill);

            if (!response.Success)
            {
                return(BadRequest(response));
            }
            return(Ok(response));
        }
Exemple #4
0
        public ActionResult AddSkill(AddSkillDto addSkillDto)
        {
            if (addSkillDto == null)
            {
                throw new ArgumentNullException(nameof(addSkillDto));
            }

            skillRepository.Add(addSkillDto.Username, addSkillDto.LevelId, addSkillDto.Summary);
            return(Ok());
        }
Exemple #5
0
        public async Task <ServiceResponse <List <GetSkillDto> > > AddSkill(AddSkillDto newSkillDto)
        {
            ServiceResponse <List <GetSkillDto> > response = new ServiceResponse <List <GetSkillDto> > ();

            try {
                var skill = _mapper.Map <Skill> (newSkillDto);
                await _context.Skills.AddAsync(skill);

                await _context.SaveChangesAsync();

                var skillList = await _context.Skills.ToListAsync();

                response.Data = skillList.Select(s => _mapper.Map <GetSkillDto> (s)).ToList();
            } catch (System.Exception ex) {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Exemple #6
0
        /// <summary>
        /// this method is used to add skill into database
        /// </summary>
        /// <param name="skill">new skill object continas name only</param>
        /// <returns>return newly created skill object</returns>
        public async Task <Skill> AddSkillAsync(AddSkillDto skill)
        {
            var existingSkill = await _skillRepository.GetSkillByNameAsync(skill.Name);

            if (existingSkill != null)
            {
                throw new Exception("This skill Already Exists");
            }
            else
            {
                var aSkill = new Skill
                {
                    Name = skill.Name
                };
                _skillRepository.AddSkill(aSkill);
                await _skillRepository.SaveChangesAsync();

                return(aSkill);
            }
        }
        public async Task <ServiceResponse <GetSkillDto> > AddSkill(AddSkillDto newSkill)
        {
            ServiceResponse <GetSkillDto> response = new ServiceResponse <GetSkillDto>();
            Skill skill = _mapper.Map <Skill>(newSkill);

            try
            {
                await _context.AddAsync(skill);

                await _context.SaveChangesAsync();

                response.Data = _mapper.Map <GetSkillDto>(skill);
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return(response);
        }
Exemple #8
0
        public async Task <ServiceResponse <List <GetSkillDto> > > AddSkill(AddSkillDto newSkill)
        {
            ServiceResponse <List <GetSkillDto> > serviceResponse = new ServiceResponse <List <GetSkillDto> >();

            int  userId = int.Parse(_httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier));
            User user   = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId);

            if (user != null && user.UserRole == UserRole.Admin)
            {
                Skill skill = _mapper.Map <Skill>(newSkill);
                await _context.Skills.AddAsync(skill);

                await _context.SaveChangesAsync();

                serviceResponse.Data = (_context.Skills.Select(s => _mapper.Map <GetSkillDto>(s))).ToList();
            }
            else
            {
                serviceResponse.Success = false;
                serviceResponse.Message = "You do not have adequate rights to add a skill.";
            }
            return(serviceResponse);
        }
 public Task <ServiceResponse <GetCharacterDto> > AddSkill(AddSkillDto newSkill)
 {
     throw new System.NotImplementedException();
 }
 public async Task <IActionResult> AddSkill(AddSkillDto newSkill)
 {
     return(Ok(await _charService.AddSkill(newSkill)));
 }
        public async Task <ActionResult <Skill> > PublishSkillAsync([FromBody] AddSkillDto skill)
        {
            var result = await _skillService.AddSkillAsync(skill);

            return(Created("", result));
        }