public bool Delete(Segment segment) { using (IDbConnection db = _factory.OpenDbConnection()) { db.Delete<Segment>(segment); return true; } }
public Segment Add(Segment segment) { using (IDbConnection db = _factory.OpenDbConnection()) { db.Insert<Segment>(segment); segment.Id = db.GetLastInsertId(); return segment; } }
public Segment Update(Segment segment) { using (IDbConnection db = _factory.OpenDbConnection()) { db.Update<Segment>(segment); return segment; } }
private Segment PopulateDerived(Segment segment, IDbConnection db) { segment.NextId = NextSegmentId(segment, db); segment.FirstQuestionId = FirstQuestionId(segment, db); return segment; }
private long NextSegmentId(Segment segment, IDbConnection db) { if (null == segment) return 0; return db.QueryScalar<long>(@"SELECT TOP 1 Id FROM Segment WHERE [Order] > @order AND SurveyId = @surveyId", new { order = segment.Order, surveyId = segment.SurveyId }); }
private long FirstQuestionId(Segment segment, IDbConnection db) { return db.QueryScalar<long>(@"SELECT TOP 1 Id FROM Question WHERE SegmentId = @segmentId ORDER BY [Order],Id", new { segmentId = segment.Id }); }