Esempio n. 1
0
        public async Task <EntityListOperationResult <SkillOfLevelDto> > UpdateListSkillOfLevelAsync(List <SkillOfLevelEditDto> skillOfLevels, List <SkillDto> skills)
        {
            try
            {
                var          skillOfLevelRets = new List <SkillOfLevel>();
                SkillOfLevel skillOfLevel     = null;
                SkillDto     skillDto         = null;
                bool         isCreateSkkill   = false;
                foreach (var skill in skillOfLevels)
                {
                    skillDto = skills.FirstOrDefault(x => x.Name == skill.Name);
                    try
                    {
                        skillOfLevel = await skillOfLevelRepository.GetSkillByLevel(skillDto.Id, skill.StartLevel);

                        skillOfLevelRets.Add(skillOfLevel);
                    }
                    catch (Exception e)
                    {
                        skillOfLevel = new SkillOfLevel
                        {
                            SkillId = skillDto.Id,
                            Level   = skill.StartLevel
                        };
                        isCreateSkkill = true;
                        skillOfLevel   = await skillOfLevelRepository.AddAsync(skillOfLevel);

                        skillOfLevelRets.Add(skillOfLevel);
                    }
                }
                if (isCreateSkkill)
                {
                    await skillOfLevelRepository.SaveAsync();
                }
                var skillDtos = mapper.Map <List <SkillOfLevelDto> >(skillOfLevelRets);
                return(EntityListOperationResult <SkillOfLevelDto> .Success(skillDtos));
            }
            catch (Exception ex)
            {
                return(EntityListOperationResult <SkillOfLevelDto> .Failure().AddError(ex.Message));
            }
        }
Esempio 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));
            }
        }
Esempio n. 3
0
        public async Task <EntityListOperationResult <SkillOfPersonDto> > UpdateListSkillOfPersonAsync(List <SkillOfLevelEditDto> skills, long personId, bool isCreate = true)
        {
            try
            {
                var           skillOfPersons = new List <SkillOfPerson>();
                SkillOfPerson skillOfPerson  = null;
                bool          isCreateSkkill = false;
                foreach (var skill in skills)
                {
                    if (isCreate)
                    {
                        skillOfPerson = new SkillOfPerson
                        {
                            SkillOfLevelId = skill.Id,
                            PersonId       = personId
                        };
                        isCreateSkkill = true;
                        skillOfPerson  = await skillOfPersonRepository.AddAsync(skillOfPerson);

                        skillOfPersons.Add(skillOfPerson);
                    }
                    else
                    {
                        try
                        {
                            skillOfPerson = await skillOfPersonRepository.GetByPersonAndSkill(personId, skill.Id);

                            if (skill.IsDelete)
                            {
                                skillOfPersonRepository.DeleteFromDB(skillOfPerson);
                            }
                            else
                            {
                                skillOfPersons.Add(skillOfPerson);
                            }
                        }
                        catch (Exception e)
                        {
                            skillOfPerson = new SkillOfPerson
                            {
                                SkillOfLevelId = skill.Id,
                                PersonId       = personId
                            };
                            isCreateSkkill = true;
                            skillOfPerson  = await skillOfPersonRepository.AddAsync(skillOfPerson);

                            skillOfPersons.Add(skillOfPerson);
                        }
                    }
                }
                if (isCreateSkkill)
                {
                    await skillOfPersonRepository.SaveAsync();
                }
                var skillDtos = mapper.Map <List <SkillOfPersonDto> >(skillOfPersons);
                return(EntityListOperationResult <SkillOfPersonDto> .Success(skillDtos));
            }
            catch (Exception ex)
            {
                return(EntityListOperationResult <SkillOfPersonDto> .Failure().AddError(ex.Message));
            }
        }