Exemplo n.º 1
0
        public async Task <ResponseLogic> RemoveWithObjectAsync(SkillDTO skill)
        {
            var foundSkill = await _repository.FindAsync(skill.Id);

            if (foundSkill is null)
            {
                return(ResponseLogic.NOT_FOUND);
            }

            var users = await _userRepository.ReadAsync();

            var projects = await _projectRepository.ReadDetailedAsync();

            var occurrences = 0;

            foreach (var user in users)
            {
                if (user.Skills.Contains(skill))
                {
                    occurrences++;
                }
            }

            foreach (var project in projects)
            {
                if (project.Skills.Contains(skill))
                {
                    occurrences++;
                }
            }

            if (occurrences > 1)
            {
                return(ResponseLogic.SUCCESS);
            }

            var success = await _repository.DeleteAsync(skill.Id);

            if (success)
            {
                return(ResponseLogic.SUCCESS);
            }
            else
            {
                return(ResponseLogic.ERROR_DELETING);
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Delete(int id)
        {
            logger.Info($"Action Start | Controller name: {nameof(SkillsController)} | Action name: {nameof(Delete)} | Input params: {nameof(id)}={id}");
            await repository.DeleteAsync(id);

            await repository.SaveAsync();

            return(RedirectToAction("Index"));
        }