public bool Update(Models.Paises pais) { try { string sql = "UPDATE tbpaises SET nomepais = '" + this.FormatString(pais.nomePais) + "'," + " ddi = '" + this.FormatString(pais.DDI) + "'," + " sigla = '" + this.FormatString(pais.sigla) + "'," + " dtultalteracao = '" + DateTime.Now.ToString("yyyy-MM-dd") + "' WHERE codpais = " + pais.codigo; OpenConnection(); SqlQuery = new SqlCommand(sql, con); int i = SqlQuery.ExecuteNonQuery(); if (i > 1) { return(true); } else { return(false); } } catch (Exception error) { throw new Exception(error.Message); } finally { CloseConnection(); } }
public bool Insert(Models.Paises pais) { try { var sql = string.Format("INSERT INTO tbpaises ( nomepais, ddi, sigla, dtcadastro, dtultalteracao) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')", this.FormatString(pais.nomePais), this.FormatString(pais.DDI), this.FormatString(pais.sigla), DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd") ); OpenConnection(); SqlQuery = new SqlCommand(sql, con); int i = SqlQuery.ExecuteNonQuery(); if (i > 1) { return(true); } else { return(false); } } catch (Exception error) { throw new Exception(error.Message); } finally { CloseConnection(); } }
public static List <Models.Paises> IniModalEdit(string Id) { List <Models.Paises> lista = new List <Models.Paises>(); try { if (Id != "0") { Int64 IdPais = Convert.ToInt64(Id); ApiServices objApi = new ApiServices(); string Request = "{}"; HttpResponseMessage response = objApi.CallService("Paises/" + IdPais, Request, ApiServices.TypeMethods.GET).Result; if (response.IsSuccessStatusCode) { //resp = await response.Content.ReadAsAsync(); string Respuesta = response.Content.ReadAsStringAsync().Result; Models.Paises obj = Newtonsoft.Json.JsonConvert.DeserializeObject <Models.Paises>(Respuesta); if (obj != null) { lista.Add(new Models.Paises { Id = obj.Id, Nombre = obj.Nombre }); } } } } catch { int sss = 0; } return(lista); }
public Paises GetPais(int?codPais) { try { var model = new Models.Paises(); if (codPais != null) { OpenConnection(); var sql = this.Search(codPais, null); SqlQuery = new SqlCommand(sql, con); reader = SqlQuery.ExecuteReader(); while (reader.Read()) { model.codigo = Convert.ToInt32(reader["Pais_ID"]); model.nomePais = Convert.ToString(reader["Pais_Nome"]); model.DDI = Convert.ToString(reader["Pais_DDI"]); model.sigla = Convert.ToString(reader["Pais_Sigla"]); model.dtCadastro = Convert.ToDateTime(reader["Pais_DataCadastro"]); model.dtUltAlteracao = Convert.ToDateTime(reader["Pais_DataUltAlteracao"]); } } return(model); } catch (Exception error) { throw new Exception(error.Message); } finally { CloseConnection(); } }
public static int Grabar(Models.Paises Pais, int EsNuevo) { try { if (Pais != null) { ApiServices objApi = new ApiServices(); HttpResponseMessage response = null; string Request = Newtonsoft.Json.JsonConvert.SerializeObject(Pais); if (EsNuevo == 0) { response = objApi.CallService("Paises/" + Pais.Id, Request, ApiServices.TypeMethods.PUT).Result; } else { response = objApi.CallService("Paises", Request, ApiServices.TypeMethods.POST).Result; } if (response.IsSuccessStatusCode) { return(1); } else { return(0); } } else { return(0); } } catch (Exception ex) { //Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(0); } }