[HttpPut] // Actualiza la informacion de un cliente public IHttpActionResult ActualizarCliente([FromBody] Cliente cliente) { using (ReservacionesModel db = new ReservacionesModel()) { if (ModelState.IsValid) { clientes datosCliente = new clientes() { identificacion = cliente.identificacion, nombre = cliente.nombre, apellido = cliente.apellido, telefono = cliente.telefono, correo = cliente.correo, id_ciudad = cliente.id_ciudad, id_departamento = cliente.id_departamento, edad = cliente.edad }; db.Entry(datosCliente).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Ok("datos actualizados exitosamente")); } else { var msg_error = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList(); return(Ok(msg_error)); } } }
public IHttpActionResult Get() { List <Cliente> clientes = new List <Cliente>(); using (ReservacionesModel db = new ReservacionesModel()) { clientes = (from d in db.clientes join c in db.ciudades on d.id_ciudad equals c.id_ciudad select new Cliente { //fecha_evento = d.fecha_evento, identificacion = d.identificacion, nombre = d.nombre, apellido = d.apellido, telefono = d.telefono, correo = d.correo, id_ciudad = d.id_ciudad, edad = d.edad, ciudades = c.ciudad, departamento = c.departamentos.departamento }).ToList(); } return(Ok(clientes)); }
[HttpDelete] //Elimina la sala del cliente public IHttpActionResult EliminarSala([FromBody] Solicitud sala) { using (ReservacionesModel db = new ReservacionesModel()) { var llavePrimarea = db.salas.Where(x => x.identificacion == sala.identificacion).ToList(); if (llavePrimarea.Count() > 0) { if (ModelState.IsValid) { var query = db.Database.SqlQuery <Solicitud>("sp_eliminar_cliente @identificacion", new SqlParameter("@identificacion", sala.identificacion)).ToList(); return(Ok("Cliente eliminado")); } else { var msg_error = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList(); return(Ok(msg_error)); } } else { return(Ok("El cliente no tiene nunguna sala")); } } }
[HttpPost]// Crea una sala y la asiga a un cliente existente public IHttpActionResult CrearSala([FromBody] Solicitud sala) { using (ReservacionesModel db = new ReservacionesModel()) { var llavePrimarea = db.clientes.Where(x => x.identificacion == sala.identificacion).ToList(); if (llavePrimarea.Count() > 0) { if (ModelState.IsValid) { db.salas.Add(new salas { fecha_evento = sala.fecha_evento, capacidad = sala.capacidad, id_motivo = sala.id_motivo, observaciones = sala.observaciones, estado = sala.estado, identificacion = sala.identificacion }); var respuesta = db.SaveChanges(); return(Ok("Registro ingresado con exito")); } else { var msg_error = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList(); return(Ok(msg_error)); } } else { return(Ok("El cliente no existe")); } } }
public IHttpActionResult ObtenerDepartamentos() { List <Departamentos> departamentos = new List <Departamentos>(); using (ReservacionesModel db = new ReservacionesModel()) { departamentos = (from d in db.departamentos select new Departamentos { id_departamento = d.id_departamento, departamento = d.departamento }).ToList(); } return(Ok(departamentos)); }
[HttpPost]// Crea un cliente validando el modelo public IHttpActionResult CrearCliente([FromBody] Cliente cliente) { using (ReservacionesModel db = new ReservacionesModel()) { object_error json = new object_error(); var llavePrimarea = db.clientes.Where(x => x.identificacion == cliente.identificacion).ToList(); if (llavePrimarea.Count() == 0) { if (ModelState.IsValid) { db.clientes.Add(new clientes { identificacion = cliente.identificacion, nombre = cliente.nombre, apellido = cliente.apellido, telefono = cliente.telefono, correo = cliente.correo, id_ciudad = cliente.id_ciudad, id_departamento = cliente.id_departamento, edad = cliente.edad }); var respuesta = db.SaveChanges(); return(Content(HttpStatusCode.Created, "Cliente creado con exito!!!!")); } else { var msg_error = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList(); json.Detalle = JsonConvert.SerializeObject(msg_error); json.Error = "Informacion invalida , verifique los datos"; return(Content(HttpStatusCode.BadRequest, json)); } } else { json.Error = "Ya existe un cliente con la misma identificacion"; return(Content(HttpStatusCode.Forbidden, json)); } } }
[HttpPost]// Crea un cliente validando el modelo public IHttpActionResult CrearCliente([FromBody] Cliente cliente) { using (ReservacionesModel db = new ReservacionesModel()) { var llavePrimarea = db.clientes.Where(x => x.identificacion == cliente.identificacion).ToList(); if (llavePrimarea.Count() == 0) { if (ModelState.IsValid) { db.clientes.Add(new clientes { identificacion = cliente.identificacion, nombre = cliente.nombre, apellido = cliente.apellido, telefono = cliente.telefono, correo = cliente.correo, id_ciudad = cliente.id_ciudad, id_departamento = cliente.id_departamento, edad = cliente.edad }); var respuesta = db.SaveChanges(); return(Ok("Registro ingresado con exito")); } else { var msg_error = ModelState.Select(x => x.Value.Errors).Where(y => y.Count > 0).ToList(); return(Ok(msg_error)); } } else { return(Ok("Ya existe un cliente con la misma identificacion")); } } }
public IHttpActionResult ObtenerCiudad([FromBody] Departamentos departamento) { if (ModelState.IsValid) { List <Ciudades> ciudad = new List <Ciudades>(); using (ReservacionesModel db = new ReservacionesModel()) { ciudad = (from c in db.ciudades where departamento.id_departamento == c.id_departamento select new Ciudades { id_departamento = c.id_departamento, ciudad = c.ciudad, id_ciudad = c.id_ciudad }).ToList(); } var hola = Content(HttpStatusCode.OK, ciudad); return(hola); } else { return(Content(HttpStatusCode.BadRequest, "Informacion invalida")); } }