Example #1
0
 public void CanAccessDatabase()
 {
     using (var ctx = new CandidatesDBContext())
     {
         Skill skill = new Skill("test");
         ctx.Skills.Add(skill);
         ctx.SaveChanges();
         ctx.Skills.Remove(skill);
         ctx.SaveChanges();
     }
 }
        public IActionResult Add(Candidate candidate)
        {
            if (ModelState.IsValid)
            {
                var nextID = _context.Candidates.Count() > 0 ? _context.Candidates.Select(x => x.ID).Max() + 1 : 0;
                candidate.ID = nextID;

                if (candidate.Qualifications != null && candidate.Qualifications.Count > 0)
                {
                    foreach (var qualification in candidate.Qualifications)
                    {
                        qualification.ID = candidate.ID;
                    }
                    // Created a separate DbSet for Qualifications because
                    // the in-memory DB was not retrieving the qualifications from each individual candidate
                    _context.Qualifications.AddRange(candidate.Qualifications);
                }

                _context.Candidates.Add(candidate);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
 public override void SaveChanges()
 {
     intranetCtx.SaveChanges();
     candidateDBContext.SaveChanges();
 }