public override TableStajModel FindOne(int id) { TableStajModel tableStajModel = new TableStajModel(); DataTable dataTable = new DataTable(); using (NpgsqlConnection connection = new NpgsqlConnection(postgreSqlConnection)) using (NpgsqlCommand command = new NpgsqlCommand()) { connection.Open(); command.CommandText = "Select *From tablestaj " + "Where id=@id"; command.Parameters.AddWithValue("@id", id); command.Connection = connection; NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter(command); dataAdapter.Fill(dataTable); } if (dataTable.Rows.Count >= 1) { tableStajModel.Id = Convert.ToInt32(dataTable.Rows[0][0].ToString()); tableStajModel.name = dataTable.Rows[0][1].ToString(); tableStajModel.lastname = dataTable.Rows[0][2].ToString(); tableStajModel.age = Convert.ToInt32(dataTable.Rows[0][3].ToString()); tableStajModel.user = Convert.ToInt32(dataTable.Rows[0][4].ToString()); } return(tableStajModel); }
public override int Edit(int id, TableStajModel tableStajModel) { int result = -1; if (this.FindOne(id) != null) { using (NpgsqlConnection connection = new NpgsqlConnection(postgreSqlConnection)) using (NpgsqlCommand command = new NpgsqlCommand()) { connection.Open(); command.CommandText = "Update tablestaj " + "Set name=@name,lastname=@lastname,age=@age,\"user\"=@user " + "Where id=@id"; command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@name", tableStajModel.name); command.Parameters.AddWithValue("@lastname", tableStajModel.lastname); command.Parameters.AddWithValue("@age", tableStajModel.age); command.Parameters.AddWithValue("@user", tableStajModel.user); command.Connection = connection; result = command.ExecuteNonQuery(); } } return(result); }
public void Update(TableStajModel tableStaj) { tableStajCollection.UpdateOne(Builders <TableStajModel> .Filter.Eq("_id", ObjectId.Parse(tableStaj.Id.ToString())), Builders <TableStajModel> .Update .Set("name", tableStaj.Name) .Set("lastname", tableStaj.Lastname) .Set("age", tableStaj.Age) .Set("user", tableStaj.User) ); }
public ActionResult Create(TableStajModel tableStajModel) { int result; result = Global.myDB.Create(tableStajModel); if (result > 0) { return(RedirectToAction("FindAll", "TableStaj")); } return(RedirectToAction("Hata", "Home", new { hataMesaji = "Create error" })); }
public ActionResult Edit(int id, TableStajModel tableStajModel) { int result = -1; if (Global.myDB != null) { result = Global.myDB.Edit(id, tableStajModel); } else { return(RedirectToAction("Hata", "Home", new { hataMesaji = "DB has not found" })); } if (result > 0) { return(RedirectToAction("FindAll", "TableStaj")); } return(RedirectToAction("Hata", "Home", new { hataMesaji = "Edit Error" })); }
public override int Create(TableStajModel tableStaj) { int result; using (SqlConnection connection = new SqlConnection(sqlConnectionString)) using (SqlCommand command = new SqlCommand()) { connection.Open(); command.CommandText = "Insert Into tablestaj Values(@name,@lastname,@age,@user)"; command.Parameters.AddWithValue("@name", tableStaj.name); command.Parameters.AddWithValue("@lastname", tableStaj.lastname); command.Parameters.AddWithValue("@age", tableStaj.age); command.Parameters.AddWithValue("@user", tableStaj.user); command.Connection = connection; result = command.ExecuteNonQuery(); } return(result); }
public void Create(TableStajModel tableStaj) { tableStajCollection.InsertOne(tableStaj); }
public abstract int Edit(int id, TableStajModel tableStajModel);
public abstract int Create(TableStajModel tableStaj);