/// <summary> /// Counts the messages. /// </summary> /// <param name="messages">The messages.</param> /// <returns></returns> private void CountMessages(IList <MessageCountModel> messages) { ReportData.Clear(); foreach (string entityName in messages.Select(c1 => c1.EntityName).Distinct().OrderBy(c1 => c1)) { int entityId = messages.First(c1 => c1.EntityName == entityName).EntityId; ReportData.Add(new MessageSummaryModel { EntityName = entityName, EntityId = entityId, PendingCount = messages.Where(c1 => c1.EntityId == entityId && c1.StatusId == (int)MessageStatus.TransferPending).Sum(c1 => c1.Count), ProcessingCount = messages.Where(c1 => c1.EntityId == entityId && c1.StatusId == (int)MessageStatus.Processing).Sum(c1 => c1.Count), SuccessCount = messages.Where(c1 => c1.EntityId == entityId && c1.StatusId == (int)MessageStatus.RequestTransferred).Sum(c1 => c1.Count), ErrorCount = messages.Where(c1 => c1.EntityId == entityId && c1.StatusId == (int)MessageStatus.Error).Sum(c1 => c1.Count), CompleteCount = messages.Where(c1 => c1.EntityId == entityId && c1.StatusId == (int)MessageStatus.Complete).Sum(c1 => c1.Count), ResponseReceivedCount = messages.Where(c1 => c1.EntityId == entityId && c1.StatusId == (int)MessageStatus.ResponseReceived).Sum(c1 => c1.Count), IsEnabled = true }); } ReportData.Add(new MessageSummaryModel { EntityName = Utilities.TotalStatusName, EntityId = 0, PendingCount = ReportData.Sum(c1 => c1.PendingCount), ProcessingCount = ReportData.Sum(c1 => c1.ProcessingCount), ErrorCount = ReportData.Sum(c1 => c1.ErrorCount), SuccessCount = ReportData.Sum(c1 => c1.SuccessCount), CompleteCount = ReportData.Sum(c1 => c1.CompleteCount), IsEnabled = false }); }
private void LoadDataToUi() { IList <MessageSummaryModel> data = new List <MessageSummaryModel> { new MessageSummaryModel { EntityId = (int)Entity.Product, EntityName = "Products", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, new MessageSummaryModel { EntityId = (int)Entity.SalesOrder, EntityName = "Sales Orders", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, new MessageSummaryModel { EntityId = (int)Entity.Customer, EntityName = "Customers", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, new MessageSummaryModel { EntityId = 0, EntityName = "Others", CompleteCount = 0, PendingCount = 0, ErrorCount = 0 }, }; var searchData = new MessageSearchModel { CreatedFrom = DateTime.Today.AddDays(-FromDateSelected), CreatedTo = DateTime.Today.AddDays(1) }; IList <MessageCountModel> databaseData = localSql.GetErpMessageSummary(searchData); EntityCount = localSql.GetReverseEntities().Count; if (databaseData.Count > 0) { (from c1 in databaseData join c2 in data on c1.EntityId equals c2.EntityId select c1.StatusId == (int)MessageStatus.Complete ? c2.CompleteCount = c1.Count : c1.StatusId == (int)MessageStatus.Error ? c2.ErrorCount = c1.Count : c2.PendingCount += c1.Count).ToArray(); (from c1 in databaseData from c2 in data where c2.EntityId == 0 & c1.EntityId != (int)Entity.Customer & c1.EntityId != (int)Entity.SalesOrder & c1.EntityId != (int)Entity.Product select c1.StatusId == (int)MessageStatus.Complete ? c2.CompleteCount += c1.Count : c1.StatusId == (int)MessageStatus.Error ? c2.ErrorCount += c1.Count : c2.PendingCount += c1.Count).ToArray(); } ReportData.Clear(); ReportData.AddRange(data); }