//TODO: Refactor `GetDoorDetail()` (was taken from `DoorUtil.GetDoorDetail()`)

        private DoorDetail GetDoorDetail(WorkorderDoor door, PropertyInfo info, List <FieldHeader> fieldHeaders, string userName)
        {
            try
            {
                var value    = info.GetValue(door.Door);
                var detail   = new DoorDetail();
                var property = info.Name;

                detail.FieldName = property;
                if (detail.FieldName == "Comment")
                {
                    var header = fieldHeaders.FirstOrDefault(fh => fh.FieldName.Equals(detail.FieldName) || fh.FieldName.Equals($"{detail.FieldName}.Content"));
                    detail.Header = (header != null) ? header.Header : property;
                }

                if (value != null)
                {
                    detail.Content = value.ToString();
                }
                if (detail.FieldName == "ChangedBy")
                {
                    detail.Header  = "Endret av";
                    detail.Content = userName;
                }
                else if (detail.FieldName == "ChangedDate")
                {
                    detail.Header = "Endret dato";
                }

                else
                {
                    var header = fieldHeaders.FirstOrDefault(fh => fh.FieldName.Equals(detail.FieldName) || fh.FieldName.Equals($"{detail.FieldName}.Content"));
                    detail.Header = (header != null) ? header.Header : property;
                }

                if (info.PropertyType.Equals(typeof(Hardware)))
                {
                    Hardware hardware = (Hardware)value;
                    detail.IsMaintained   = hardware.IsMaintained;
                    detail.Qty            = hardware.Qty;
                    detail.IsMaintainable = hardware.IsMaintainable;
                    detail.ChecklistId    = hardware.ChecklistId;
                }
                else if (info.PropertyType.Equals(typeof(DoorField)))
                {
                    DoorField doorField = (DoorField)value;
                }

                return(string.IsNullOrEmpty(detail.Content) ? null : detail);
            }
            catch (TargetParameterCountException ex)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private DoorDetail GetDoorDetail(Door door, PropertyInfo info, List <FieldHeader> fieldHeaders, List <string> companiesList)
        {
            try
            {
                object     value    = info.GetValue(door);
                DoorDetail detail   = new DoorDetail();
                string     property = info.Name;

                detail.FieldName = property;

                var header = fieldHeaders.FirstOrDefault(fh => fh.FieldName.Equals(detail.FieldName) || fh.FieldName.Equals($"{detail.FieldName}.Content"));
                detail.Header = (header != null) ? header.Header : property;

                if (value != null)
                {
                    detail.Content = value.ToString();
                }

                //detail.CanMount = true; // TODO: based on the rights, this will change
                detail.IsMaintainable = false;

                if (info.PropertyType.Equals(typeof(Hardware)))
                {
                    Hardware hardware = (Hardware)value;
                    detail.IsMaintained = hardware.IsMaintained;
                    ////if (hardware.CompanyId != null)
                    ////    detail.CanMount = companiesList.Contains(hardware.CompanyId) ? true : false;
                }
                else if (info.PropertyType.Equals(typeof(DoorField)))
                {
                    DoorField doorField = (DoorField)value;
                    detail.IsMaintainable = doorField.Mounted;
                }

                return(string.IsNullOrEmpty(detail.Content) ? null : detail);
            }
            catch (TargetParameterCountException ex)
            {
                return(null);
            }
        }