예제 #1
0
        public async Task <IActionResult> PostAlumnos([FromBody] AlumnosParameters a)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Alumnos alumnos = new Alumnos(a.padron, a.apellido, a.nombre, a.domicilio, a.carreraId);

            _context.Alumnos.Add(alumnos);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAlumnos", new { id = alumnos.AlumnoId }, alumnos));
        }
예제 #2
0
        public async Task <IActionResult> PutAlumnos([FromRoute] int id, [FromBody] AlumnosParameters a)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != a.alumnoId)
            {
                return(BadRequest());
            }

            Alumnos alumnos = _context.Alumnos.Find(id);

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

            try
            {
                alumnos.Padron    = a.padron;
                alumnos.Apellido  = a.apellido;
                alumnos.Nombre    = a.nombre;
                alumnos.Domicilio = a.domicilio;
                alumnos.CarreraId = a.carreraId;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlumnosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(alumnos));
        }
예제 #3
0
        public async Task IsCrearAlumnoOk()
        {
            // Arrange
            var dbContext  = DbContextMocker.GetAlumnosDbContext("AlumnoApp");
            var controller = new AlumnosController(dbContext);

            // Act
            AlumnosParameters al = new AlumnosParameters();

            al.apellido  = "Gardel";
            al.nombre    = "Carlos";
            al.padron    = "88888";
            al.domicilio = "Av. Siempre Viva 123";
            al.carreraId = 1;

            var response = await controller.PostAlumnos(al);

            var value = (ObjectResult)response;

            dbContext.Dispose();

            // Assert
            Assert.True(value.StatusCode.Value == 201);
        }