Exemple #1
0
 public void Add(BookedItem entity)
 {
     using (var dbContext = new PoREntities(ConnectionString))
     {
         dbContext.BookedItems.Add(entity);
         dbContext.SaveChanges();
     }
 }
Exemple #2
0
 public void Add(Client entity)
 {
     using (var dbContext = new PoREntities(ConnectionString))
     {
         dbContext.Clients.Add(entity);
         dbContext.SaveChanges();
     }
 }
Exemple #3
0
 public void Update(BookedItem entity)
 {
     using (var dbContext = new PoREntities(ConnectionString))
     {
         // We could turn this into an upsert
         dbContext.BookedItems.Attach(entity);
         dbContext.Entry(entity).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Exemple #4
0
        public BookedItem GetBookedItem(int id)
        {
            using (var dbContext = new PoREntities(ConnectionString))
            {
                var item = from itm in dbContext.BookedItems
                           where itm.BookedItemId == id
                           select itm;

                return(item.First());
            }
        }
Exemple #5
0
        public void DeleteBookedItem(int itemId)
        {
            using (var dbContext = new PoREntities(ConnectionString))
            {
                var item = from itm in dbContext.BookedItems
                           where itm.BookedItemId == itemId
                           select itm;

                dbContext.BookedItems.Remove(item.First());
            }
        }
Exemple #6
0
        public Client GetClient(int id)
        {
            using (var dbContext = new PoREntities(ConnectionString))
            {
                var entity = from client in dbContext.Clients
                             where client.ClientId == id
                             select client;

                return(entity.First());
            }
        }
Exemple #7
0
        public void DeleteClient(int id)
        {
            using (var dbContext = new PoREntities(ConnectionString))
            {
                var entity = from client in dbContext.Clients
                             where client.ClientId == id
                             select client;

                dbContext.Clients.Remove(entity.First());
            }
        }
Exemple #8
0
 public int GetItemCount()
 {
     using (var dbContext = new PoREntities(ConnectionString))
     {
         var result = from itm in dbContext.Items select itm;
         //The IQueryable isn't registered to the last second, so this isn't executed on the list,
         //    but rather at the database level as a select statement so long as we're using mssql or a
         //    driver that supports Entity framework properly.
         return(result.Count());
     }
 }
Exemple #9
0
 public List <Item> GetItems()
 {
     using (var dbContext = new PoREntities(ConnectionString))
     {
         var items = from itm in dbContext.Items select itm;
         // Calling the tolist here forces the DB call.  Potentially you could do something fancy
         //    and add additional parameters if you returned it as an IQueryable.  You do however
         //    Run into issue with how EF populates the navigation properties.
         return(items.ToList());
     }
 }
Exemple #10
0
 public void Update(Item entity)
 {
     using (var dbContext = new PoREntities(ConnectionString))
     {
         // We could turn this into an upsert
         dbContext.Items.Attach(entity);
         dbContext.Entry(entity).State = EntityState.Modified;
         // This Could cause problems.  You could approach this like and upsert and do something like
         //   AddOrUpdate(i=> i.id == entity.Id).  Additionally you may want to set certain properties
         //   of the entity to 'not modified' if they're null so as not to update the DB.
         dbContext.SaveChanges();
     }
 }
Exemple #11
0
        public Item GetItem(int id)
        {
            // In a perfect wold we would not be using the auto-incremented id here but some from of generated
            //    id so that we would not expose the inner workings of the DB to the world.

            using (var dbContext = new PoREntities(ConnectionString))
            {
                var item = from itm in dbContext.Items
                           where itm.ItemId == id
                           select itm;

                return(item.First());
            }
        }