Example #1
0
        public DoorDetailModel GetDetailModelForDoor(Door door, PropertyInfo[] propertyInfo, List <FieldHeader> fieldHeaders, List <string> companiesList)
        {
            DoorDetailModel detailModel = new DoorDetailModel();

            detailModel.ProjectId   = door.ProjectId;
            detailModel.DoorNo      = door.DoorNo;
            detailModel.DoorQty     = door.DoorQty;
            detailModel.RoomType    = door.RoomType.Content;
            detailModel.Floor       = door.Floor;
            detailModel.Id          = door.Id;
            detailModel.DoorDetails = new List <DoorDetail>();

            foreach (PropertyInfo info in propertyInfo)
            {
                if (!propertiesToIgnore.Contains(info.Name))
                {
                    DoorDetail doorDetail = GetDoorDetail(door, info, fieldHeaders, companiesList);

                    if (doorDetail != null)
                    {
                        detailModel.DoorDetails.Add(doorDetail);
                    }
                }
            }

            return(detailModel);
        }
        //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);
            }
        }
        public DoorDetailModel GetDoorDetailsViewWithCompanyPermissions(WorkorderDoor door, List <FieldHeader> fieldHeaders, string userName)
        {
            var detailModel = new DoorDetailModel
            {
                Id          = door.Id,
                WorkOrderId = door.WorkorderId,
                ProjectId   = door.ProjectId,
                DoorNo      = door.Door.DoorNo,
                DoorQty     = door.Door.DoorQty,
                RoomType    = door.Door.RoomType.Content,
                Floor       = door.Door.Floor,
                DoorDetails = new List <DoorDetail>()
            };

            var doorSurfDetails = new List <DoorDetail>();

            foreach (PropertyInfo info in DOOR_PROP_INFO)
            {
                if (!PROPS_TO_IGNORE.Contains(info.Name))
                {
                    DoorDetail doorDetail = GetDoorDetail(door, info, fieldHeaders, userName);
                    if (info.PropertyType.Equals(typeof(Hardware)))
                    {
                        DoorDetail doorSurfDetail = GetDoorSurfDetail(door, info, fieldHeaders);
                        if (doorSurfDetail != null)
                        {
                            doorSurfDetails.Add(doorSurfDetail);
                        }
                    }
                    if (doorDetail != null)
                    {
                        detailModel.DoorDetails.Add(doorDetail);
                    }
                }
            }

            if (doorSurfDetails.Count > 0)
            {
                detailModel.DoorDetails.AddRange(doorSurfDetails);
            }
            detailModel.DoorDetails = detailModel.DoorDetails.OrderBy(x => x.Header).ToList();
            return(detailModel);
        }
Example #4
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);
            }
        }
        private DoorDetail GetDoorSurfDetail(WorkorderDoor door, PropertyInfo info, List <FieldHeader> fieldHeaders)
        {
            try
            {
                var value    = info.GetValue(door.Door);
                var detail   = new DoorDetail();
                var property = info.Name;

                detail.FieldName = property;

                if (value != null)
                {
                    Hardware hardware = (Hardware)value;
                    if (hardware.Surf != null)
                    {
                        detail.Content = hardware.Surf.ToString();
                    }
                    else
                    {
                        return(null);
                    }

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

                detail.IsMaintainable = false;

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