public async Task <IActionResult> Post(Teacher model) { // Teacher teacher = _mapper.Map<Teacher>(model); //model.UnitTeachers = null; _context.Add(model); if (await _repo.SaveChangesAsync()) { return(Created($"api/teachers/{model.Id}", model)); } return(NotFound()); }
public async Task <IActionResult> Post(Unit model) { try { if (model == null) { return(NotFound()); } // Unit unit = model; // unit.Address = model.Address; // unit.Contact = model.Contact; _repo.Add(model); if (await _repo.SaveChangesAsync()) { return(Created($"api/units/{model.Id}", model)); } } catch (System.Exception msg) { this.StatusCode(StatusCodes.Status500InternalServerError, $"A base de dados falhou. Erro: {msg.Message}"); } return(Ok(model)); }