Ejemplo n.º 1
0
        public void TestRelatedEntities()
        {
            using (var scope = new TransactionScope())
            {
                using (var context = new SchoolContext())
                {
                    var leerling = context.Leerlingen.Add(new Leerling
                    {
                        Naam = "Test"
                    });

                    var studie = new Studie
                    {
                        Naam = "PretPakket"
                    };

                    leerling.Studie = studie;

                    context.SaveChanges();
                }

                using (var context = new SchoolContext())
                {
                    context.Database.Log += Console.WriteLine;

                    var leerling = context
                                   .Leerlingen
                                   .Include(l => l.Studie)
                                   .First(p => p.Naam == "Test");
                    Assert.IsNotNull(leerling.Studie);
                }

                //scope.Complete();
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutStudie(int id, Studie studie)
        {
            if (id != studie.StudieId)
            {
                return(BadRequest());
            }

            _context.Entry(studie).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudieExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <Studie> > PostStudie(Studie studie)
        {
            _context.Studie.Add(studie);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetStudie", new { id = studie.StudieId }, studie));
        }
Ejemplo n.º 4
0
        public IActionResult PromoteStudent([FromBody] Studie studie)
        {
            if (studie.Studies == null || studie.Semester == null)
            {
                return(BadRequest());
            }

            ObjectResult ob = new ObjectResult(new SqlServerDbService().PromoteStudents(studie.Semester, studie.Studies));

            ob.StatusCode = 201;
            return(ob);
        }