コード例 #1
0
        public async Task <IActionResult> CreateProfessor([FromBody] SaveProfessorResource professorResource)
        {
            var professor = mapper.Map <SaveProfessorResource, Professor>(professorResource);


            context.Professores.Add(professor);
            await context.SaveChangesAsync();

            var result = mapper.Map <Professor, ProfessorResource>(professor);

            return(Ok(result));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateProfessor(int id, [FromBody] SaveProfessorResource professorResource)
        {
            var professor = await context.Professores.FindAsync(id);

            if (professor == null)
            {
                return(NotFound());
            }

            mapper.Map <SaveProfessorResource, Professor>(professorResource, professor);

            await context.SaveChangesAsync();

            professor = await context.Professores.Include(p => p.Aulas).FirstOrDefaultAsync(p => p.Id == professor.Id);

            var result = mapper.Map <Professor, ProfessorResource>(professor);


            return(Ok(result));
        }