Ejemplo n.º 1
0
        // Remove all equipment items and add new ones
        public void Init()
        {
            var db = new EquipDBContext();

            // Delete all rows from the Equipments table
            foreach (Equipment item in db.Equipments)
            {
                db.Equipments.Remove(item);
            }

            // Add some new ones
            Equipment equipItem1 = new Equipment()
            {
                Name = "iPad", CheckedOut = false
            };

            db.Equipments.Add(equipItem1);
            Equipment equipItem2 = new Equipment()
            {
                Name = "Microphone", CheckedOut = false
            };

            db.Equipments.Add(equipItem2);
            Equipment equipItem3 = new Equipment()
            {
                Name = "Tripod", CheckedOut = false
            };

            db.Equipments.Add(equipItem3);

            db.SaveChanges();
        }
Ejemplo n.º 2
0
        public bool SaveItem(Equipment item)
        {
            var db = new EquipDBContext();

            // Check to see if an item with this name is in the database
            if (null == db.Equipments.FirstOrDefault(e => e.Name == item.Name))
            {
                db.Equipments.Add(item);
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        public bool UpdateItem(Equipment item)
        {
            var db = new EquipDBContext();
            // Find the item we are changing
            var dbItem = db.Equipments.FirstOrDefault(e => e.EquipmentId == item.EquipmentId);

            if (null != dbItem)
            {
                // Copy properties- this is how we incorporate the changes
                dbItem.Name       = item.Name;
                dbItem.CheckedOut = item.CheckedOut;

                // save the changes to the database
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }