public IHttpActionResult PutAgendamento(int id, Agendamento agendamento) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != agendamento.Id) { return(BadRequest()); } db.Entry(agendamento).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AgendamentoExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IActionResult IncluirMedico([FromBody] MedicoViewModel medicoVM) { Medico medico = _mapper.Map <Medico>(medicoVM); var ret = _context.Medicos.Add(medico); _context.SaveChanges(); return(Ok(ret.Entity)); }
public IActionResult IncluirPaciente([FromBody] PacienteViewModel pacienteVM) { Paciente paciente = _mapper.Map <Paciente>(pacienteVM); var ret = _context.Pacientes.Add(paciente); _context.SaveChanges(); return(Ok(ret.Entity)); }
public IActionResult IncluirConsulta([FromBody] ConsultaViewModel consultaVM) { var consultas = _context.Consultas.Where(x => x.MedicoId == consultaVM.MedicoId && x.ConsultaData == consultaVM.ConsultaData); if (consultas == null || !consultas.Any()) { Consulta consulta = _mapper.Map <Consulta>(consultaVM); var ret = _context.Consultas.Add(consulta); _context.SaveChanges(); return(Ok(ret.Entity)); } else { return(BadRequest("Já existe consulta marcada para esse horario")); } }
public void Deleta(int id) { using (var ctx = new AgendamentoContext()) { ctx.Entry(Busca(id)).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } }
public void Atualiza(Sala sala) { using (var ctx = new AgendamentoContext()) { ctx.Entry(sala).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); } }
public void Adiciona(Sala sala) { using (var ctx = new AgendamentoContext()) { ctx.Salas.Add(sala); ctx.SaveChanges(); } }
public void Adiciona(Agendamento agendamento) { using (var ctx = new AgendamentoContext()) { ctx.Agendamentos.Add(agendamento); ctx.SaveChanges(); } }
//Método responsável por popular a base de dados public void Seed() { //se existir algum dado no banco, não faz nada if (_context.Medico.Any() || _context.Consulta.Any()) { return; } Medico med1 = new Medico(1, "Bob Brown", "33360023"); Medico med2 = new Medico(2, "Maria Green", "33360027"); Consulta cons1 = new Consulta(1, "Rayane Nascimento", new DateTime(1998, 4, 21), new DateTime(2019, 7, 3, 9, 30, 0), new DateTime(2019, 7, 3, 10, 30, 0), " ", med1); Consulta cons2 = new Consulta(2, "Rogerio Cardoso", new DateTime(1988, 05, 16), new DateTime(2019, 7, 3, 11, 30, 0), new DateTime(2019, 7, 3, 12, 30, 0), " ", med1); Consulta cons3 = new Consulta(3, "Richier Ojoim", new DateTime(1990, 1, 24), new DateTime(2019, 7, 3, 8, 0, 0), new DateTime(2019, 7, 3, 9, 0, 0), " ", med2); Consulta cons4 = new Consulta(4, "Vinicius Laporti", new DateTime(1990, 11, 30), new DateTime(2019, 7, 4, 8, 0, 0), new DateTime(2019, 7, 4, 9, 0, 0), " ", med2); Consulta cons5 = new Consulta(5, "Henrique Bodart", new DateTime(1992, 1, 9), new DateTime(2019, 7, 4, 9, 30, 0), new DateTime(2019, 7, 4, 10, 30, 0), " ", med2); Consulta cons6 = new Consulta(6, "Julia Martins", new DateTime(1980, 9, 7), new DateTime(2019, 7, 4, 17, 30, 0), new DateTime(2019, 7, 4, 18, 30, 0), " ", med1); Consulta cons7 = new Consulta(7, "Carlos Almeida", new DateTime(1989, 2, 12), new DateTime(2019, 7, 4, 14, 30, 0), new DateTime(2019, 7, 4, 15, 30, 0), " ", med1); //Adicionando os objetos no banco e salvando as alterações _context.Medico.AddRange(med1, med2); _context.Consulta.AddRange(cons1, cons2, cons3, cons4, cons5, cons6, cons7); _context.SaveChanges(); }
public void Add(Agendamento agendamento) { _contexto.Agendamento.Add(agendamento); _contexto.SaveChanges(); }