Esempio n. 1
0
        public async Task <bool> DeleteEquipmentType(long equipmentTypeId)
        {
            var equipmentType = await EquipmentTypeAccessor.GetEquipmentType(equipmentTypeId);

            equipmentType.Deleted = true;

            try
            {
                await EquipmentTypeAccessor.SaveEquipmentType(equipmentType);

                Logger.Log(string.Format("Equipment type deleted - Id: {0}", equipmentTypeId), TraceEventType.Information);

                // update the equipment type for existing equipment with the deleted type
                var equipments = await EquipmentAccessor.GetEquipmentByType(equipmentTypeId);

                foreach (var equipment in equipments)
                {
                    try
                    {
                        equipment.EquipmentTypeId = 1;
                        await EquipmentAccessor.SaveEquipment(equipment);
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(string.Format("Could not reassign equipment Type - EquipmentId: {0}", equipment.EquipmentId), TraceEventType.Error, ex);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log("Could not delete equipment type", TraceEventType.Error, ex);
                return(false);
            }
        }
        public async Task <bool> DeleteEquipment(long equipmentId)
        {
            var equipment = await EquipmentAccessor.GetEquipment(equipmentId);

            equipment.Deleted = true;

            try
            {
                await EquipmentAccessor.SaveEquipment(equipment);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.Log("Could not delete equipment", TraceEventType.Error, ex);
                return(false);
            }
        }
Esempio n. 3
0
        public void EquipmentAccessor_SaveEquipment()
        {
            accessor = GetAccessor();

            var equipment = new Equipment
            {
                Name            = "New Equipment",
                Description     = "New Description",
                DateAquired     = new DateTime(2016, 11, 11),
                EquipmentTypeId = 1
            };

            var res = accessor.SaveEquipment(equipment).Result;

            Assert.IsNotNull(res);
            Assert.AreEqual(5, MockDatabaseContext.Equipment.Count());
            Assert.AreEqual("New Equipment", MockDatabaseContext.Equipment.Last().Name);
        }
Esempio n. 4
0
        public void EquipmentAccessor_SaveEquipment_Update()
        {
            accessor = GetAccessor();

            var equipment = new Equipment
            {
                EquipmentId     = 3,
                Name            = "New Equipment",
                Description     = "New Description",
                DateAquired     = new DateTime(2015, 11, 11),
                EquipmentTypeId = 99,
                Deleted         = true
            };

            var res = accessor.SaveEquipment(equipment).Result;

            Assert.IsNotNull(res);
            Assert.AreEqual(5, MockDatabaseContext.Equipment.Count());
            Assert.AreEqual("New Equipment", MockDatabaseContext.Equipment.First(x => x.EquipmentId == 3).Name);
            Assert.AreEqual("New Description", MockDatabaseContext.Equipment.First(x => x.EquipmentId == 3).Description);
            Assert.AreEqual(new DateTime(2015, 11, 11), MockDatabaseContext.Equipment.First(x => x.EquipmentId == 3).DateAquired);
            Assert.AreEqual(99, MockDatabaseContext.Equipment.First(x => x.EquipmentId == 3).EquipmentTypeId);
        }
 public async Task <Equipment> SaveEquipment(Equipment equipment)
 {
     return(await EquipmentAccessor.SaveEquipment(equipment));
 }