public HistoryBillBLL(EmpContext context = null) : base(context) { dictionaryBLL = new DictionaryBLL(this.db); buildingBLL = new BuildingBLL(this.db); organizationBLL = new OrganizationBLL(this.db); //monitoringConfigBLL = new MonitoringConfigBLL(this.db); meterBLL = new MeterBLL(this.db); userBLL = new UserBLL(this.db); messageBLL = new MessageBLL(this.db); }
public static IList <MessageRecordData> ToViewList(this IQueryable <MessageRecord> nodes, CategoryDictionary suffix = CategoryDictionary.None) { if (nodes == null) { return(null); } Dictionary <int, MessageData> dicMessages = new Dictionary <int, MessageData>(); var nodeList = nodes.ToList(); var results = nodeList.Select(node => new MessageRecordData() { Id = node.Id, MessageId = node.MessageId, UserId = node.UserId, IsReaded = node.IsReaded, IsEnable = node.IsEnable, IsDeleted = node.IsDeleted, ReadedTime = node.ReadedTime, Message = ((suffix & CategoryDictionary.Message) == CategoryDictionary.Message) && node.Message != null ? node.Message.ToShortViewData() : null }).ToList(); MessageBLL messageBLL = new MessageBLL(); for (int i = 0; i < nodeList.Count(); i++) { if (results[i].Message == null) { if (nodeList[i].Message != null) { results[i].Message = nodeList[i].Message.ToViewData(); } else { if (dicMessages.Keys.Contains(nodeList[i].MessageId)) { results[i].Message = dicMessages[nodeList[i].MessageId]; } else { results[i].Message = messageBLL.Find(nodeList[i].MessageId).ToViewData(); dicMessages.Add(nodeList[i].MessageId, results[i].Message); } } } } return(results); }
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); }