Ejemplo n.º 1
0
        public async Task <int> Handle(CreateSkillCommand request, CancellationToken cancellationToken)
        {
            var skill = new Skill(request.Description);

            await _skillRepository.AddAsync(skill);

            return(skill.Id);
        }
Ejemplo n.º 2
0
        public async Task <EntityListOperationResult <SkillDto> > UpdateListSkillAsync(List <string> names)
        {
            try
            {
                var   skills         = new List <Skill>();
                bool  isCreateSkkill = false;
                Skill skillEntity    = null;
                for (int i = 0; i < names.Count; i++)
                {
                    try
                    {
                        skillEntity = await skillRepository.GetByNameAsync(names[i]);

                        skills.Add(skillEntity);
                    }
                    catch (Exception e)
                    {
                        var skillNew = new Skill
                        {
                            Name = names[i],
                        };
                        skillNew = await skillRepository.AddAsync(skillNew);

                        skills.Add(skillNew);
                        isCreateSkkill = true;
                    }
                }

                if (isCreateSkkill)
                {
                    await skillRepository.SaveAsync();
                }
                var skillDtos = mapper.Map <List <SkillDto> >(skills);
                return(EntityListOperationResult <SkillDto> .Success(skillDtos));
            }
            catch (Exception ex)
            {
                return(EntityListOperationResult <SkillDto> .Failure().AddError(ex.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <SkillResponse> SaveAsync(Skill skill)
        {
            try
            {
                await _skillRepository.AddAsync(skill);

                return(new SkillResponse(skill));
            }
            catch (Exception ex)
            {
                return(new SkillResponse($"An error ocurred while saving the skill : {ex.Message}"));
            }
            throw new NotImplementedException();
        }
        public async Task <SkillResponse> SaveAsync(Skill skill)
        {
            try
            {
                await _skillRepository.AddAsync(skill);

                await _unitOfWork.CompleteAsync();

                return(new SkillResponse(skill));
            }
            catch (Exception ex)
            {
                return(new SkillResponse($"An error ocurred while saving the skill: {ex.Message}"));
            }
        }
        public async Task <int> Handle(CreateSkillCommand request, CancellationToken cancellationToken)
        {
            var skill = new Skill(request.Description);

            //Entity Framework - Padrão CQRS
            //await _dbContext.Skills.AddAsync(skill);
            //await _dbContext.SaveChangesAsync();

            //Dapper
            //using (var sqlConnection = new SqlConnection(_connectionString))
            //{
            //    sqlConnection.Open();

            //    var sql = "INSERT INTO Skills (Description, CreatedAt) VALUES (@description, @createdat)";

            //    sqlConnection.Execute(sql, new { description = skill.Description, createdat = skill.CreatedAt });
            //}

            //Padrão Repository
            await _skillRepository.AddAsync(skill);

            return(skill.Id);
        }
 public async Task AddAsync(Skill Skill)
 {
     await skillRepository.AddAsync(Skill);
 }