public async Task <ResponseMensaje> Insertar(Ent_Empleado ent_Empleado) { string BaseUri = options.Value.Url.ToString(); ResponseMensaje responseMensaje = new ResponseMensaje(); try { using (HttpClient _httpClient = new HttpClient()) { _httpClient.BaseAddress = new Uri(BaseUri); string stringData = Newtonsoft.Json.JsonConvert.SerializeObject(ent_Empleado); HttpContent content = new StringContent(stringData, Encoding.UTF8, "application/json"); HttpResponseMessage response = _httpClient.PostAsync("Inserta", content).GetAwaiter().GetResult(); string strResponse = await response.Content.ReadAsStringAsync(); responseMensaje = JsonConvert.DeserializeObject <ResponseMensaje>(strResponse); } } catch (Exception ex) { responseMensaje = new ResponseMensaje { codigo = "00", mensaje = ex.Message.ToString() }; //throw; } return(responseMensaje); }
public async Task <string> RegistraEmpleado([FromBody] Ent_Empleado ent_Empleado) { try { lo_Empleado = new Lo_Empleado(options); var LstEmpleados = await this.lo_Empleado.RegistraEmpleado(ent_Empleado); return(LstEmpleados); } catch (Exception) { return(null); } }
public async Task <string> ListarEmpleado() { var ResultJson = string.Empty; using (var cn = new SqlConnection(options.Value.BDConnectionSQL.ToString())) { try { SqlCommand objCommand = new SqlCommand(); objCommand.Connection = cn; objCommand.CommandText = "SPS_Empleados"; objCommand.CommandType = CommandType.StoredProcedure; await cn.OpenAsync(); List <Ent_Empleado> lstEnt_Empleado = new List <Ent_Empleado>(); using (DbDataReader objReader = await objCommand.ExecuteReaderAsync()) { while (await objReader.ReadAsync()) { Ent_Empleado ent_Empleado = new Ent_Empleado(); ent_Empleado.id = Int32.Parse(objReader["id"].ToString()); ent_Empleado.dni = objReader["dni"].ToString(); ent_Empleado.nombre = objReader["nombre"].ToString(); ent_Empleado.apellido_p = objReader["apellido_p"].ToString(); ent_Empleado.apellido_m = objReader["apellido_m"].ToString(); ent_Empleado.fecha_nacimiento = DateTime.Parse(objReader["fecha_nacimiento"].ToString()); ent_Empleado.sexo = objReader["sexo"].ToString(); ent_Empleado.estado = bool.Parse(objReader["estado"].ToString()); ent_Empleado.Area = objReader["Area"].ToString(); ent_Empleado.fecha_registro = DateTime.Parse(objReader["fecha_registro"].ToString()); ent_Empleado.usuario_registro = objReader["usuario_registro"].ToString(); lstEnt_Empleado.Add(ent_Empleado); } } ResultJson = JsonConvert.SerializeObject(lstEnt_Empleado == null ? null : lstEnt_Empleado); } catch (Exception ex) { return(null); } } return(ResultJson); }
public async Task <string> RegistraEmpleado(Ent_Empleado ent_Empleado) { ResponseMensaje responseMensaje; var ResultJson = string.Empty; using (var cn = new SqlConnection(options.Value.BDConnectionSQL.ToString())) { try { SqlCommand objCommand = new SqlCommand(); objCommand.Connection = cn; objCommand.CommandText = "SPI_Empleados"; objCommand.CommandType = CommandType.StoredProcedure; await cn.OpenAsync(); objCommand.Parameters.AddWithValue("@dni", ent_Empleado.dni); objCommand.Parameters.AddWithValue("@nombre", ent_Empleado.nombre); objCommand.Parameters.AddWithValue("@apellido_p", ent_Empleado.apellido_p); objCommand.Parameters.AddWithValue("@apellido_m", ent_Empleado.apellido_m); objCommand.Parameters.AddWithValue("@fecha_nacimiento", ent_Empleado.fecha_nacimiento); objCommand.Parameters.AddWithValue("@sexo", ent_Empleado.sexo); objCommand.Parameters.AddWithValue("@estado", ent_Empleado.estado); objCommand.Parameters.AddWithValue("@Area", ent_Empleado.Area); objCommand.Parameters.AddWithValue("@usuario_registro", ent_Empleado.usuario_registro); await objCommand.ExecuteNonQueryAsync(); responseMensaje = new ResponseMensaje { codigo = "01", mensaje = "Transacción Exitosa" }; } catch (Exception ex) { responseMensaje = new ResponseMensaje { codigo = "00", mensaje = ex.Message.ToString() }; } } return(JsonConvert.SerializeObject(responseMensaje)); }
public async Task <string> RegistraEmpleado(Ent_Empleado ent_Empleado) { DAEmpleado = new Da_Empleado(options); return(await DAEmpleado.RegistraEmpleado(ent_Empleado)); }
public ActionResult Registro(Ent_Empleado ent_Empleado) { var strResultado = empleado.Insertar(ent_Empleado); return(Json(new { data = strResultado.Result })); }