Ejemplo n.º 1
0
 public IEnumerable <Candidate> GetAllCandidates()
 {
     using (var dbContext = DBContextResolver.CreateNewInstance <ICandidateEntities>())
     {
         return(dbContext.Candidates.ToArray());
     }
 }
Ejemplo n.º 2
0
 public IEnumerable <Skill> GetAllSkills()
 {
     using (var context = DBContextResolver.CreateNewInstance <ICandidateEntities>())
     {
         return(context.Skills.ToList());
     }
 }
Ejemplo n.º 3
0
 public Candidate GetCandidate(long id)
 {
     using (var context = DBContextResolver.CreateNewInstance <ICandidateEntities>())
     {
         var candidate = context.Candidates.FirstOrDefault(x => x.Id == id);
         return(candidate);
     }
 }
Ejemplo n.º 4
0
 public IEnumerable <long> GetCandidateSkills(long candidateId)
 {
     using (var context = DBContextResolver.CreateNewInstance <ICandidateEntities>())
     {
         var candidateSkills = context.CandidateSkills.Where(x => x.CandidateId == candidateId).ToList();
         return(candidateSkills.Select(x => x.SkillId));
     }
 }
Ejemplo n.º 5
0
 public IEnumerable <Candidate> GetCandidateBySkill(long skillId)
 {
     using (var dbContext = DBContextResolver.CreateNewInstance <ICandidateEntities>())
     {
         var selectedCandidateSkills = dbContext.CandidateSkills.Where(x => x.SkillId == skillId);
         var selectedCandidates      = dbContext.Candidates.Where(x => selectedCandidateSkills.Any(y => y.CandidateId == x.Id));
         return(selectedCandidates.ToList());
     }
 }
Ejemplo n.º 6
0
        public void Delete(int id)
        {
            using (var context = DBContextResolver.CreateNewInstance <ICandidateEntities>())
            {
                var candidate       = context.Candidates.First(x => x.Id == id);
                var candidateSkills = context.CandidateSkills.Where(x => x.CandidateId == id);

                RemoveOldSkills(context, candidateSkills, new long[0]);
                context.Candidates.Remove(candidate);
                context.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        public void UpdateCandidate(long id, string firstName, string lastName, IEnumerable <long> skills)
        {
            using (var context = DBContextResolver.CreateNewInstance <ICandidateEntities>())
            {
                var candidate = context.Candidates.First(x => x.Id == id);
                candidate.FirstName = firstName;
                candidate.LastName  = lastName;
                var candidateSkills = context.CandidateSkills.Where(x => x.CandidateId == id);
                RemoveOldSkills(context, candidateSkills, skills);
                AddNewSkills(context, candidateSkills, id, skills);

                context.SaveChanges();
            }
        }
Ejemplo n.º 8
0
        public void Insert(string firstName, string lastName, IEnumerable <long> skills)
        {
            using (var context = DBContextResolver.CreateNewInstance <ICandidateEntities>())
            {
                var candidate = new Candidate()
                {
                    FirstName = firstName,
                    LastName  = lastName
                };
                context.Candidates.Add(candidate);
                context.SaveChanges();

                AddNewSkills(context, new List <CandidateSkill>(), candidate.Id, skills);
                context.SaveChanges();
            }
        }