public DtoCategorie GetById(int id) { DtoCategorie categorie = new DtoCategorie(); try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = string.Format("select * from Categories where Id={0}", id); using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { DtoCategorie newCategorie = new DtoCategorie { Id = reader.GetInt32(0), Titel = reader.GetString(1) }; categorie = newCategorie; } } } } catch (SqlException se) { Console.Write(se.Message); } return(categorie); }
public void Update(DtoCategorie categorie) { try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "UPDATE Categories SET Titel = @titel Where Id = @id"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); command.Parameters.AddWithValue("@id", categorie.Id); command.Parameters.AddWithValue("@titel", categorie.Titel); command.CommandType = CommandType.Text; command.ExecuteNonQuery(); } } } catch (SqlException se) { Console.Write(se.Message); } }
public List <DtoCategorie> GetAll() { List <DtoCategorie> categories = new List <DtoCategorie>(); try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "select * from Categories"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { DtoCategorie newCategorie = new DtoCategorie { Id = reader.GetInt32(0), Titel = reader.GetString(1), }; categories.Add(newCategorie); } } } } catch (SqlException se) { Console.Write(se.Message); } return(categories); }
public void AddNew(Categorie categorie) { IDalCategorie DAL = DalFactory.CreateCategorieDal(); DtoCategorie DTO = categorie.ToDTO(); DAL.Insert(DTO); }
public ActionResult AjouterOrModifierCat(VMListeCat vmCat) { if (ModelState.IsValid) { DtoCategorie dtoCat = new DtoCategorie(); if (vmCat.id_cat != 0) { dtoCat.id_cat = vmCat.id_cat; dtoCat.description_cat = vmCat.description_cat; BusComp.ModifierCategorie(dtoCat); } else { dtoCat.id_cat = vmCat.id_cat; dtoCat.description_cat = vmCat.description_cat; BusComp.AjouterCategorie(dtoCat); } TempData["SuccessMessageDeprt"] = "Done !"; return(RedirectToAction("ListeCat")); } else { return(RedirectToAjouterOrModifierCat(vmCat.id_cat)); } }
public Categorie GetByID(int id) { IDalCategorie DAL = DalFactory.CreateCategorieDal(); DtoCategorie DTO = DAL.GetById(id); Categorie categorie = new Categorie(DTO); return(categorie); }
public void ModifierCategorie(DtoCategorie cat) { var catUp = context.Categories.Find(cat.id_cat); catUp.description_cat = cat.description_cat; catUp.id_cat = cat.id_cat; context.SaveChanges(); }
public void AjouterCategorie(DtoCategorie dtoCat) { Categorie dep = new Categorie { id_cat = dtoCat.id_cat, description_cat = dtoCat.description_cat }; Ajouter(dep); }
public DtoCategorie GetCategorie(int id) { var x = context.Categories.Find(id); var catDto = new DtoCategorie { id_cat = x.id_cat, description_cat = x.description_cat }; return(catDto); }
public void Insert(DtoCategorie categorie) { try { using (SqlConnection connection = this.connection.CreateConnection()) { string Querry = "insert into Categories ( Titel ) values (@param1)"; using (SqlCommand command = new SqlCommand(Querry, connection)) { connection.Open(); command.Parameters.AddWithValue("@param1", categorie.Titel); command.CommandType = CommandType.Text; int rowsAdded = command.ExecuteNonQuery(); } } } catch (SqlException se) { Console.Write(se.Message); } }
public Categorie(DtoCategorie categorieDTO) { id = categorieDTO.Id; titel = categorieDTO.Titel; }