Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void AddNew(Categorie categorie)
        {
            IDalCategorie DAL = DalFactory.CreateCategorieDal();
            DtoCategorie  DTO = categorie.ToDTO();

            DAL.Insert(DTO);
        }
Esempio n. 5
0
 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));
     }
 }
Esempio n. 6
0
        public Categorie GetByID(int id)
        {
            IDalCategorie DAL       = DalFactory.CreateCategorieDal();
            DtoCategorie  DTO       = DAL.GetById(id);
            Categorie     categorie = new Categorie(DTO);

            return(categorie);
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        public void AjouterCategorie(DtoCategorie dtoCat)
        {
            Categorie dep = new Categorie
            {
                id_cat          = dtoCat.id_cat,
                description_cat = dtoCat.description_cat
            };

            Ajouter(dep);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 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);
     }
 }
Esempio n. 11
0
 public Categorie(DtoCategorie categorieDTO)
 {
     id    = categorieDTO.Id;
     titel = categorieDTO.Titel;
 }