Exemple #1
0
 public static void pridejDoDB(Clanky1 cl)
 {
     using (StrankyEntities context = new StrankyEntities())
     {
         context.Clanky1.Add(cl);
         context.SaveChanges();
     }
 }
Exemple #2
0
 public static void odeberZDB(int id)
 {
     using (StrankyEntities context = new StrankyEntities())
     {
         Clanky1 clZdb = new Clanky1();
         clZdb = context.Clanky1.FirstOrDefault(c => c.Id == id);
         context.Clanky1.Remove(clZdb);
         context.SaveChanges();
     }
 }
Exemple #3
0
        public static int pocetVDB()
        {
            int pocet = 0;

            using (StrankyEntities context = new StrankyEntities())
            {
                pocet = context.Clanky1.Count();
            }
            return(pocet);
        }
Exemple #4
0
 public static void update(Clanky1 cl)
 {
     using (StrankyEntities context = new StrankyEntities())
     {
         Clanky1 clZdb = new Clanky1();
         clZdb       = context.Clanky1.FirstOrDefault(c => c.Id == cl.Id);
         clZdb.Nazev = cl.Nazev;
         clZdb.Text  = cl.Text;
         context.SaveChanges();
     }
 }
Exemple #5
0
        public static Clanky1 vyberZDb(int id)
        {
            Clanky1 clZdb = new Clanky1();

            clZdb = null;
            using (StrankyEntities context = new StrankyEntities())
            {
                try
                {
                    clZdb = context.Clanky1.FirstOrDefault(c => c.Id == id);
                }
                catch
                {
                    return(null);
                }
            }
            return(clZdb);
        }
Exemple #6
0
        public static List <Clanky1> VseZDB()
        {
            List <Clanky1> database = new List <Clanky1>();

            using (StrankyEntities context = new StrankyEntities())
            {
                int i = 1, pocetnalzeu = 0;
                int pocetDB = context.Clanky1.Count();

                Clanky1 clZdb = new Clanky1();
                while (pocetnalzeu != pocetDB)
                {
                    clZdb = context.Clanky1.FirstOrDefault(c => c.Id == i);
                    if (clZdb != null)
                    {
                        pocetnalzeu++;
                        Clanky1 newclanek = new Clanky1();
                        database.Add(newclanek = clZdb); //fix
                    }
                    i++;
                }
            }
            return(database);
        }