public HttpResponseMessage Post(AlunoCadastroViewModel model) { try { if (ModelState.IsValid) { Aluno a = new Aluno(); a.Nome = model.Nome; a.IdTurma = model.IdTurma; a.GerarNotas(); AlunoRepositorio rp = new AlunoRepositorio(); rp.Insert(a); return(Request.CreateResponse(HttpStatusCode.OK, "Aluno cadastrado com sucesso.")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, ValidationUtil.GetValidationErrors(ModelState))); } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }
public HttpResponseMessage Post(TurmaCadastroViewModel model) { try { if (ModelState.IsValid) { Turma t = new Turma(); t.Nome = model.Nome; TurmaRepositorio rp = new TurmaRepositorio(); rp.Insert(t); return(Request.CreateResponse(HttpStatusCode.OK, "Turma cadastrada com sucesso.")); } else { return(Request.CreateResponse(HttpStatusCode.BadRequest, ValidationUtil.GetValidationErrors(ModelState))); } } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message)); } }