private List <HistoryView> SelectHistoryView(Expression <Func <History, bool> > Expression) { int accountId, releaseCpId; using (ITableRepository db = new TableRepository()) { accountId = db.GetTableIdByTableName("Account"); releaseCpId = db.GetTableIdByTableName("ReleaseCP"); } var Query = DbSet.AsNoTracking() .Include(a => a.ActivityLog) .Include(a => a.Release) .Include(a => a.Release.Account) .Include(a => a.ActivityLog.Employee) .Include(a => a.Release.ReleaseCPs.Select(s => s.CP)) .Include(a => a.Table); // .Include(a=>a.Release.ReleaseMilestones.Select(s=>s.Milestone)) // .Include(a => a.Release.ReleaseProducts.Select(s => s.Product)) // .Include(a => a.Release.ReleaseFamilyProducts.Select(s => s.FamilyProduct)) // .Include(a => a.Release.ReleaseStakeholders.Select(s => s.Stakeholder)) // .Include(a => a.Release.ReleaseAreaOwners.Select(s => s.Area)); if (Expression != null) { Query = Query.Where(Expression); } List <HistoryView> HistoryView = new List <TableViews.HistoryView>(); foreach (var item in Query) { HistoryView historyView = new HistoryView(); historyView.ReleaseId = item.TableID != accountId && item.Release != null ? (int?)item.Release.ReleaseID : null; historyView.ReleaseName = item.TableID != accountId && item.Release != null ? item.Release.Name : null; historyView.AccountId = item.Release != null ? (int?)item.Release.AccountID : null; historyView.AccountName = item.Release != null && item.Release.Account != null ? item.Release.Account.Name : ""; historyView.Id = item.ActivityLogID; historyView.CpId = item.TableID == releaseCpId && item.Release != null && /*TableHistory.Release.ReleaseCPs!=null&&*/ item.Release.ReleaseCPs.FirstOrDefault(a => a.ReleaseCPID == item.ItemID) != null ? (int?)item.Release.ReleaseCPs.FirstOrDefault(a => a.ReleaseCPID == item.ItemID).CPID : null;//only if exists historyView.CpName = item.TableID == releaseCpId && item.Release != null /*&& TableHistory.Release.ReleaseCPs != null */ && item.Release.ReleaseCPs.FirstOrDefault(a => a.ReleaseCPID == item.ItemID) != null && item.Release.ReleaseCPs.FirstOrDefault(a => a.ReleaseCPID == item.ItemID).CP != null?item.Release.ReleaseCPs.FirstOrDefault(a => a.ReleaseCPID == item.ItemID).CP.Name : ""; if (item.FieldName == "AmdocsFocalPoint2ID" || item.FieldName == "AmdocsFocalPoint1ID" || item.FieldName == "EmployeeID1" || item.FieldName == "EmployeeID2") { using (IEmployeeRepository db = new EmployeeRepository()) { try { if (!string.IsNullOrEmpty(item.OldValue)) { string name = db.GetFullNameByEmpId(Convert.ToInt32(item.OldValue)); historyView.OldValue = name != null ? name : ""; } else { historyView.OldValue = ""; } if (!string.IsNullOrEmpty(item.NewValue)) { string name = db.GetFullNameByEmpId(Convert.ToInt32(item.NewValue)); historyView.NewValue = name != null ? name : ""; } else { historyView.NewValue = ""; } } catch { historyView.NewValue = ""; } } } else { historyView.OldValue = item != null ? item.OldValue : ""; historyView.NewValue = item != null ? item.NewValue : ""; } historyView.ModifiedById = item.ActivityLog != null && item.ActivityLog.Employee != null ? (int?)item.ActivityLog.Employee.MDMCode : null; historyView.ModifiedByName = item.ActivityLog != null && item.ActivityLog.Employee != null ? item.ActivityLog.Employee.FirstName + " " + item.ActivityLog.Employee.LastName : ""; historyView.ModifiedDate = item.ActivityLog != null && item.ActivityLog.Date != null?item.ActivityLog.Date.ToString() : ""; historyView.TableName = item.Table != null ? item.Table.Name : ""; if (item.Table.ParameterRelashionID != 0)// { string fieldName = null; string tableName = StaticResources.GetTableName(item.Table.ParameterRelashionID); fieldName = GetParameterTableName(tableName, item.ItemID); historyView.FieldName = fieldName; } else { historyView.FieldName = item != null ? item.FieldName : ""; } HistoryView.Add(historyView); } return(HistoryView.ToList()); }
public List <HistoryView> GetList(int?ReleaseID, DateTime?StartDate, DateTime?EndDate, int TableId, int ModifiedById) { int releaseMilestoneTableId, releaseAreaOwnersTableId, releaseProductTableId, releaseFamilyProductTableId, releaseStakeHolderTableId, accountTableId, releaseTableId, releaseCpTableId; using (ITableRepository db = new TableRepository()) { releaseMilestoneTableId = db.GetTableIdByTableName("ReleaseMilestone"); releaseAreaOwnersTableId = db.GetTableIdByTableName("ReleaseAreaOwner"); releaseProductTableId = db.GetTableIdByTableName("ReleaseProduct"); releaseFamilyProductTableId = db.GetTableIdByTableName("ReleaseFamilyProduct"); releaseStakeHolderTableId = db.GetTableIdByTableName("ReleaseStakeholder"); accountTableId = db.GetTableIdByTableName("Account"); releaseTableId = db.GetTableIdByTableName("Release"); releaseCpTableId = db.GetTableIdByTableName("ReleaseCP"); } Expression <Func <History, bool> > Expression; using (ITableRepository db = new TableRepository()) { EndDate = EndDate.Value.AddDays(1); //TODO check if activitylog exists Expression = c => c.ActivityLog.Date >= StartDate; Expression = Expression.And(c => c.ActivityLog.Date < EndDate); if (ModifiedById != 0) { Expression = Expression.And(c => c.ActivityLog.EmployeeID == ModifiedById); } if (TableId == releaseTableId) { Expression = Expression.And(c => c.TableID == releaseTableId || c.TableID == releaseMilestoneTableId || c.TableID == releaseAreaOwnersTableId || c.TableID == releaseProductTableId || c.TableID == releaseFamilyProductTableId || c.TableID == releaseStakeHolderTableId ); } else if (TableId != 0)//one table { Expression = Expression.And(c => c.TableID == TableId); } else//all tables { Expression = Expression.And(c => c.TableID == accountTableId || c.TableID == releaseTableId || c.TableID == releaseCpTableId || c.TableID == releaseMilestoneTableId || c.TableID == releaseAreaOwnersTableId || c.TableID == releaseProductTableId || c.TableID == releaseFamilyProductTableId || c.TableID == releaseStakeHolderTableId ); } if (ReleaseID != 0)//not all releases { Expression = Expression.And(c => c.ReleaseID == ReleaseID); } } List <HistoryView> historyView = SelectHistoryView(Expression).ToList(); return(historyView); }