Created
April 17, 2012 17:02
-
-
Save hotgazpacho/2407501 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
using (var session = _sessionFactory.OpenSession()) | |
using (var transaction = session.BeginTransaction()) | |
{ | |
try | |
{ | |
var potentiallyMatchingExamsQuery = new FindPotentiallyMatchingExamsForCompletionSignOffQuery { Session = session, Surveillance = command.SurveillanceId }; | |
var exams = potentiallyMatchingExamsQuery.Execute(); | |
var surveillanceQuery = new LoadSurveillanceForSignoffQuery { SurveillanceId = command.SurveillanceId, Session = session }; | |
var surveillance = surveillanceQuery.Execute().Value; | |
surveillance.SignOffComplete(command.Signoff); | |
surveillance.Remarks = command.Remarks; | |
CreditMatchingExams(surveillance, exams); | |
transaction.Commit(); | |
} | |
catch (Exception) | |
{ | |
transaction.Rollback(); | |
throw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment