public WorkTime?Find(User user, DateTime date) { //todo json_extract(Data, '$.DateCreated') <=> Date - error var sql = $@"SELECT {TableCols} FROM {TableName} WHERE AggregateId = (SELECT AggregateId FROM {TableName} WHERE EventName = @EventName AND json_extract(Data, '$.User.UserId') = @UserId AND json_extract(Data, '$.DateCreated') <= @Date AND json_extract(Data, '$.EndDate') >= @Date ORDER BY Date DESC LIMIT 1);"; using var conn = CreateConnection(true); var events = conn.Query <DbEvent>(sql, new { UserId = user.UserId, Date = date, EventName = EventName.WorkTimeCreated, }) .MapToEvents(_mapper).ToList(); if (events.Count == 0) { return(null); } var workTime = WorkTime.FromEvents(events); return(workTime); }
public List <WorkTime> FindAll(User user, DateTime?startDate, DateTime?endDate) { using var conn = CreateConnection(true); IEnumerable <IGrouping <long, Event> >?events = null; if (startDate == null && endDate == null) { events = AllForUser(user, conn); } else if (startDate != null && endDate != null) { events = AllForUserInRange(user, startDate.Value, endDate.Value, conn); } if (events == null) { throw new ArgumentException(); } var workTimes = new List <WorkTime>(); foreach (var aggEvents in events) { workTimes.Add(WorkTime.FromEvents(aggEvents)); } return(workTimes); }