Forked from hotgazpacho/FindPotentiallyMatchingExamsForCompletionSignOffQuery.cs
Created
April 17, 2012 17:07
-
-
Save darrencauthon/2407519 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class FindPotentiallyMatchingExamsForCompletionSignOffQuery : Query<IEnumerable<ExamResult>> | |
{ | |
public override IEnumerable<ExamResult> Execute() | |
{ | |
ExamResult er = null; | |
Component c = null; | |
VibrationPoint vp = null; | |
ExamMethod m = null; | |
var matchingCodeSectionIds = QueryOver.Of(() => er) | |
.Where(() => er.Surveillance.Id == Surveillance) | |
.Select(Projections.Property(() => er.CodeSectionId)); | |
var matchingMethods = QueryOver.Of(() => er) | |
.Where(() => er.Surveillance.Id == Surveillance) | |
.Inner.JoinAlias(() => er.Method, () => m) | |
.Select(Projections.Property(() => m.Id)); | |
var matchingComponents = QueryOver.Of(() => er) | |
.Where(() => er.Surveillance.Id == Surveillance) | |
.Inner.JoinAlias(() => er.Component, () => c) | |
.Select(Projections.Property(() => c.Id)); | |
var matchingVibrationPoints = QueryOver.Of(() => er) | |
.Where(() => er.Surveillance.Id == Surveillance) | |
.Inner.JoinAlias(() => er.VibrationPoint, () => vp) | |
.Select(Projections.Property(() => vp.Id)); | |
var matchingVibPointOrNoVibPoint = new Disjunction() | |
.Add(() => er.VibrationPoint == null) | |
.Add(Subqueries.WhereProperty(() => vp.Id).In(matchingVibrationPoints)); | |
var matchingExamsQuery = Session.QueryOver(() => er) | |
.Inner.JoinAlias(() => er.Component, () => c) | |
.Left.JoinAlias(() => er.VibrationPoint, () => vp) | |
.Where(x => x.IsCurrent) | |
.And(Subqueries.WhereProperty(() => er.CodeSectionId).In(matchingCodeSectionIds)) | |
.And(Subqueries.WhereProperty(() => er.Method.Id).In(matchingMethods)) | |
.And(Subqueries.WhereProperty(() => c.Id).In(matchingComponents)) | |
.And(matchingVibPointOrNoVibPoint) | |
.AndNot(x => x.IsComplete) | |
.AndNot(x => x.IsReviewed) | |
.AndNot(x => x.IsApproved) | |
.AndNot(x => x.Surveillance.Id == Surveillance) | |
.TransformUsing(Transformers.DistinctRootEntity) | |
; | |
return matchingExamsQuery.Future(); | |
} | |
public int Surveillance { get; set; } | |
} |
This file contains hidden or 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
matchingExamCreator = ioc.Create<IMatchingExamCreator>(); | |
matchingExamCreator.Create(command.SurveillanceId); | |
This file contains hidden or 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
public interface IExamDataGetter { | |
IEnumerable<ExamResult> GetPotentiallyMatchingExams(int surveillanceId); | |
IEnumerable<ExamResult> LoadSurveillanceForSignoffQuery(int surveillanceId); | |
} | |
public interface ISurveillanceGetter { | |
Surveillance Get(surveillanceId); | |
} | |
public class MatchingExamCreator : IMatchingExamCreator { | |
public MatchingExamCreator(ISurveillanceGetter surveillanceGetter, IExamGetter examGetter){ | |
//... | |
} | |
public void Match(int surveillanceId, signoff, remarks){ | |
var surveillance = surveillanceGetter.Get(surveillanceId); | |
surveillance.SignOffComplete(signoff); | |
surveillance.Remarks = remarks; | |
var exams = examDataGetter.GetPotentiallyMatchingExams(surveillanceId); | |
CreditMatchingExams(surveillance, exams); | |
} | |
//... | |
} | |
public class SessionAndTransactionMatchingExamCreator : IMatchingExamCreator | |
{ | |
public SessionAndTransactionMatchingExamCreator(IMatchingExamCreator, ITransactionCreator transactionCreator){ | |
// ... | |
} | |
public void Match(surveillanceId, signoff, remarks){ | |
using (var transaction in transactionCreator.Create()){ | |
try { | |
matchingExamCreator.Create(surveillanceId, signoff, remarks); | |
transaction.Commit(); | |
} catch { | |
transaction.Rollback(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment