Created
July 17, 2012 13:51
-
-
Save smiler/3129497 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parents = from d in db.milestonemetadata_deliverables | |
join mm in db.eumarketing_milestonemetadatas on new {d.ProjectID, d.MilestoneID} equals new {mm.ProjectID, mm.MilestoneID} | |
where mm.IsActive == 1 && mm.Removed == false && mm.Status != 8 | |
&& ( mm.ActualEndDate >= fromDate && mm.ActualEndDate < toDate | |
|| ( mm.EndPlanEndDate.HasValue | |
&& ( mm.EndPlanEndDate.Value >= fromDate && mm.EndPlanEndDate.Value <= toDate ) | |
|| mm.EndActualEndDate.HasValue | |
&& ( mm.EndActualEndDate.Value >= fromDate && mm.EndActualEndDate.Value <= toDate ) ) ) | |
join m in db.eumarketing_milestones on mm.MilestoneID equals m.Id | |
where m.GroupId != 0 | |
join p in db.eumarketing_projects on d.ProjectID equals p.ProjectID | |
where ( from dr in db.milestonemetadata_deliverables_regions | |
where dr.DeliverablesId == d.Id && regionIds.Contains( dr.RegionId ) | |
select dr ).Any() | |
select new Milestone { | |
Id = mm.Id, | |
LabelID = p.LabelId.HasValue ? p.LabelId.Value : 0, | |
MilestoneID = mm.MilestoneID, | |
FranchiseID = ( int ) p.FranchiseId, | |
ProjectID = p.ProjectID, | |
GroupID = ( int ) m.GroupId, | |
ProjectName = p.ProjectName, | |
MilestoneName = m.MilestoneName, | |
PlanEndDate = mm.PlanEndDate.HasValue ? mm.PlanEndDate.Value : new DateTime( 1900, 1, 1 ), | |
ActualEndDate = | |
mm.ActualEndDate.HasValue | |
? mm.ActualEndDate.Value | |
: ( mm.PlanEndDate.HasValue ? mm.PlanEndDate.Value : new DateTime( 1900, 1, 1 ) ), | |
EndPlanEndDate = mm.EndPlanEndDate, | |
EndActualEndDate = mm.EndActualEndDate, | |
Status = ( Milestone.MilestoneStatus ) mm.Status, | |
Comment = mm.StatusNotes | |
}; | |
// Fetch milestones that have the specified regions | |
var milestones = from mm in db.eumarketing_milestonemetadatas | |
where mm.IsActive == 1 && mm.Removed == false && mm.Status != 8 | |
&& ( mm.ActualEndDate >= fromDate && mm.ActualEndDate < toDate | |
|| ( mm.EndPlanEndDate.HasValue | |
&& ( mm.EndPlanEndDate.Value >= fromDate && mm.EndPlanEndDate.Value <= toDate ) | |
|| mm.EndActualEndDate.HasValue | |
&& ( mm.EndActualEndDate.Value >= fromDate && mm.EndActualEndDate.Value <= toDate ) ) ) | |
join m in db.eumarketing_milestones on mm.MilestoneID equals m.Id | |
where m.GroupId != 0 | |
join p in db.eumarketing_projects on mm.ProjectID equals p.ProjectID | |
where ( from mr in db.milestonemetadata_regions | |
where mr.MilestoneMetadataId == mm.Id && regionIds.Contains( mr.RegionId ) | |
select mr ).Any() | |
select new Milestone { | |
Id = mm.Id, | |
LabelID = p.LabelId.HasValue ? p.LabelId.Value : 0, | |
MilestoneID = mm.MilestoneID, | |
FranchiseID = ( int ) p.FranchiseId, | |
ProjectID = p.ProjectID, | |
GroupID = ( int ) m.GroupId, | |
ProjectName = p.ProjectName, | |
MilestoneName = m.MilestoneName, | |
PlanEndDate = mm.PlanEndDate.HasValue ? mm.PlanEndDate.Value : new DateTime( 1900, 1, 1 ), | |
ActualEndDate = | |
mm.ActualEndDate.HasValue | |
? mm.ActualEndDate.Value | |
: ( mm.PlanEndDate.HasValue ? mm.PlanEndDate.Value : new DateTime( 1900, 1, 1 ) ), | |
EndPlanEndDate = mm.EndPlanEndDate, | |
EndActualEndDate = mm.EndActualEndDate, | |
Status = ( Milestone.MilestoneStatus ) mm.Status, | |
Comment = mm.StatusNotes | |
}; | |
return milestones.Union( parents ).ToList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment