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 void EquipmentTypeAccessor_GetEquipmentType_Null()
        {
            accessor = GetAccessor();

            var res = accessor.GetEquipmentType(99).Result;

            Assert.IsNull(res);
        }
        public void EquipmentTypeAccessor_GetEquipmentType()
        {
            accessor = GetAccessor();

            var res = accessor.GetEquipmentType(2).Result;

            Assert.IsNotNull(res);
            Assert.AreEqual(typeof(EquipmentType), res.GetType());
            Assert.AreEqual("Type 2", res.Name);
        }