Exemplo n.º 1
0
 public clothes GetPieceOfClothing(long id)
 {
     using (SzafaModel dbconn = new SzafaModel())
     {
         if (!CheckDatabaseExistence(dbconn))
         {
             throw new DbUpdateException();
         }
         return(dbconn.clothes.Find(id));
     }
 }
Exemplo n.º 2
0
 public List <types> GetTypes()
 {
     using (SzafaModel dbconn = new SzafaModel())
     {
         if (!CheckDatabaseExistence(dbconn))
         {
             throw new DbUpdateException();
         }
         var searchresults = dbconn.types.Include(t => t.clothes).ToList <types>();
         return(searchresults);
     }
 }
Exemplo n.º 3
0
 public void AddClothes(clothes c)
 {
     using (SzafaModel dbconn = new SzafaModel())
     {
         if (!CheckDatabaseExistence(dbconn))
         {
             throw new DbUpdateException();
         }
         dbconn.clothes.Add(c);
         dbconn.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public void DeletePieceOfClothing(clothes c)
 {
     using (SzafaModel dbconn = new SzafaModel())
     {
         if (!CheckDatabaseExistence(dbconn))
         {
             throw new DbUpdateException();
         }
         clothes cloth = dbconn.clothes.Find(c.id);
         dbconn.clothes.Remove(cloth);
         dbconn.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public void UpdateTypes(types t)
 {
     using (SzafaModel dbconn = new SzafaModel())
     {
         if (!CheckDatabaseExistence(dbconn))
         {
             throw new DbUpdateException();
         }
         types type = dbconn.types.Find(t.id);
         type.name = t.name;
         dbconn.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public IEnumerable <T> GetEntities <T>() where T : class
 {
     using (SzafaModel dbconn = new SzafaModel())
     {
         //parse the property name (remove the namespaces with Split method)
         string typeName = typeof(T).ToString().Split('.').Last();
         //get the elements from the right table
         var searchresults = (DbSet <T>)dbconn.GetType().GetProperty(typeName).GetValue(dbconn);
         //yield-return the IEnumerable of the results
         foreach (T el in searchresults)
         {
             yield return(el);
         }
     }
 }
Exemplo n.º 7
0
 public void UpdateClothes(clothes c)
 {
     using (SzafaModel dbconn = new SzafaModel())
     {
         if (!CheckDatabaseExistence(dbconn))
         {
             throw new DbUpdateException();
         }
         clothes cloth = dbconn.clothes.Find(c.id);
         cloth.description  = c.description;
         cloth.name         = c.name;
         cloth.in_use       = c.in_use;
         cloth.in_use_from  = c.in_use_from;
         cloth.last_time_on = c.last_time_on;
         cloth.picture_path = c.picture_path;
         cloth.times_on     = c.times_on;
         cloth.type_id      = c.type_id;
         dbconn.SaveChanges();
     }
 }
Exemplo n.º 8
0
 private bool CheckDatabaseExistence(SzafaModel conn)
 {
     conn.Database.Connection.ConnectionString = "data source=" + "\"" + AppDomain.CurrentDomain.BaseDirectory + "main.db\"";
     //MessageBox.Show(conn.Database.Connection.ConnectionString);
     return(File.Exists(ExctractDataSource(conn.Database.Connection.ConnectionString)));
 }