public Page <WebHookSession> List(User user, ListFilter filter, IRepositoryModelCache cache = null) { var model = UserModel.FromRepositoryType(user); var sql = $@" SELECT COUNT(*) FROM WebHookSessionModels JOIN ComputerModels ON ComputerModels.Id = WebHookSessionModels.Computer_Id WHERE ComputerModels.Owner_Id = @User_Id SELECT * FROM WebHookSessionModels JOIN ComputerModels ON ComputerModels.Id = WebHookSessionModels.Computer_Id WHERE ComputerModels.Owner_Id = @User_Id ORDER BY CreationTimestamp {SqlUtilities.OrderByDirection(filter.SortDirection)} OFFSET @Start ROWS FETCH NEXT @Count ROWS ONLY "; var parameters = new { Count = filter.Count, Start = filter.Start, User_Id = user.Id, }; int total; WebHookSessionModel[] models; using (var multiQuery = _connection.QueryMultiple(sql, parameters)) { total = multiQuery.ReadSingle <int>(); models = multiQuery.Read <WebHookSessionModel>().ToArray(); } var result = new Page <WebHookSession> { Count = filter.Count, Sort = filter.SortDirection, Items = models .Select(x => x.ToRepositoryType(cache, _computerRepository)) .ToArray(), Start = filter.Start, Total = total, }; return(result); }
public Page <Task> List(User user, ListFilter filter, IRepositoryModelCache cache = null) { var userModel = UserModel.FromRepositoryType(user); var sql = $@" SELECT COUNT(*) FROM TaskModels WHERE Owner_Id = @Owner_Id SELECT * FROM TaskModels WHERE Owner_Id = @Owner_Id ORDER BY Id {SqlUtilities.OrderByDirection(filter.SortDirection)} OFFSET @Start ROWS FETCH NEXT @Count ROWS ONLY "; var parameters = new { Count = filter.Count, Owner_Id = userModel.Id, Start = filter.Start, }; int total; TaskModel[] models; using (var multiQuery = _connection.QueryMultiple(sql, parameters)) { total = multiQuery.ReadSingle <int>(); models = multiQuery.Read <TaskModel>().ToArray(); } var result = new Page <Task> { Count = filter.Count, Sort = filter.SortDirection, Items = models .Select(x => x.ToRepositoryType(cache, _computerRepository, _scriptRepository, _userRepository)) .ToArray(), Start = filter.Start, Total = total, }; return(result); }
public Page <Script> List(ListFilter filter, IRepositoryModelCache cache = null) { var sql = $@" SELECT COUNT(*) FROM ScriptModels SELECT * FROM ScriptModels ORDER BY CreationTimestamp {SqlUtilities.OrderByDirection(filter.SortDirection)} OFFSET @Start ROWS FETCH NEXT @Count ROWS ONLY "; var parameters = new { Count = filter.Count, Start = filter.Start, }; int total; ScriptModel[] models; using (var multiQuery = _connection.QueryMultiple(sql, parameters)) { total = multiQuery.ReadSingle <int>(); models = multiQuery.Read <ScriptModel>().ToArray(); } var result = new Page <Script> { Count = filter.Count, Sort = filter.SortDirection, Items = models .Select(x => x.ToRepositoryType(cache)) .ToArray(), Start = filter.Start, Total = total, }; return(result); }