Example #1
0
        public static MessageData ToViewData(this Message node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            if (node == null)
            {
                return(null);
            }
            var model = new MessageData()
            {
                Id                    = node.Id,
                MessageTypeId         = node.MessageTypeId,
                CreateDate            = node.CreateDate,
                EndDate               = node.EndDate,
                MessageSourceTypeId   = node.MessageSourceTypeId,
                SrcId                 = node.SrcId,
                Subject               = node.Subject,
                Body                  = node.Body,
                Url                   = node.Url,
                ActiveDate            = node.ActiveDate,
                IsDeleted             = node.IsDeleted,
                NotActiveDate         = node.NotActiveDate,
                AlertLevelId          = node.AlertLevelId, //告警等级
                MessageTypeName       = node.MessageType == null?DictionaryCache.Get()[node.MessageTypeId].ChineseName                                                                        : node.MessageType.ChineseName,
                MessageSourceTypeName = node.MessageSourceType == null?DictionaryCache.Get()[node.MessageSourceTypeId].ChineseName                                                            : node.MessageSourceType.ChineseName,
                MessageRecords        = ((suffix & CategoryDictionary.MessageRecord) == CategoryDictionary.MessageRecord) ? node.MessageRecords.ToList().Select(x => x.ToViewData()).ToList() : null
            };

            string MessageSourceTypeStr = node.MessageSourceType == null?DictionaryCache.Get()[node.MessageSourceTypeId].Description : node.MessageSourceType.Description;

            if (MessageSourceTypeStr != null)
            {
                ViewMeterFullInfoBLL meterBLL        = new ViewMeterFullInfoBLL();
                BuildingBLL          buildingBLL     = new BuildingBLL();
                OrganizationBLL      organizationBLL = new OrganizationBLL();
                UserBLL  userBLL  = new UserBLL();
                BrandBLL brandBLL = new BrandBLL();
                try
                {
                    int id = -1;
                    if (model.SrcId != null && int.TryParse(model.SrcId, out id))
                    {
                        if (MessageSourceTypeStr.ToLower() == "meter")
                        {
                            var meter = meterBLL.Find(id).ToViewData();
                            model.MessageSource = meter;
                            model.SenderName    = meter.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "building")
                        {
                            var m = buildingBLL.Find(id).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "organization")
                        {
                            var m = organizationBLL.Find(id).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "brand")
                        {
                            var m = brandBLL.Find(id).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.Name;
                        }
                        else if (MessageSourceTypeStr.ToLower() == "user")
                        {
                            var m = userBLL.Find(model.SrcId).ToViewData();
                            model.MessageSource = m;
                            model.SenderName    = m.FullName;
                        }
                    }
                    else
                    {
                        var m = userBLL.Find(model.SrcId).ToViewData();
                        model.MessageSource = m;
                        model.SenderName    = m.FullName;
                    }
                }
                catch { }
            }

            return(model);
        }
Example #2
0
        public static AttachmentData ToViewData(this Attachment node, CategoryDictionary suffix = CategoryDictionary.None)
        {
            if (node == null)
            {
                return(null);
            }
            var model = new AttachmentData()
            {
                Id                 = node.Id,
                TargetId           = node.TargetId,
                AttachmentTypeId   = node.AttachmentTypeId,
                AttachmentFormatId = node.AttachmentFormatId,
                Description        = node.Description,
                Size               = node.Size,
                CreateTime         = node.CreateTime,
                Path               = node.Path,
                OriginalName       = node.OriginalName,
                LogicalName        = node.LogicalName,
                AttachmentType     = node.AttachmentType == null?DictionaryCache.Get()[node.AttachmentTypeId].ToViewData() : node.AttachmentType.ToViewData(),
                                         AttachmentFormat = node.AttachmentFormat == null?DictionaryCache.Get()[node.AttachmentFormatId].ToViewData() : node.AttachmentFormat.ToViewData(),
            };

            string AttachmentTypeStr = node.AttachmentType == null?DictionaryCache.Get()[node.AttachmentTypeId].Description : node.AttachmentType.Description;

            if (AttachmentTypeStr != null)
            {
                ViewMeterFullInfoBLL meterBLL        = new ViewMeterFullInfoBLL();
                BuildingBLL          buildingBLL     = new BuildingBLL();
                OrganizationBLL      organizationBLL = new OrganizationBLL();
                UserBLL    userBLL    = new UserBLL();
                BrandBLL   brandBLL   = new BrandBLL();
                MessageBLL messageBLL = new MessageBLL();
                int        id         = -1;
                if (model.TargetId != null && int.TryParse(model.TargetId, out id))
                {
                    if (AttachmentTypeStr.ToLower() == "meter")
                    {
                        model.Target = meterBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "building")
                    {
                        model.Target = buildingBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "organization")
                    {
                        model.Target = organizationBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "brand")
                    {
                        model.Target = brandBLL.Find(id).ToViewData();
                    }
                    else if (AttachmentTypeStr.ToLower() == "message")
                    {
                        model.Target = messageBLL.Find(id).ToViewData();
                    }
                }
                else
                {
                    model.Target = userBLL.Find(model.TargetId).ToViewData();
                }
            }
            return(model);
        }