public void Setup() { TestingContext = new DocumentDBContext() { DatabaseId = "TestDb-" + Guid.NewGuid().ToString(), CollectionId = "TestItemRepositoryTests-" + Guid.NewGuid().ToString() }; _testUserId = Guid.NewGuid().ToString(); _repository = new TestItemRepository(TestingContext); _repository.CreateDatabaseAsync(TestingContext.DatabaseId).Wait(); _repository.CreateCollectionAsync(TestingContext.DatabaseId, TestingContext.CollectionId).Wait(); }
public override void RegisterGrids() { UrlHelper UrlHelper = new UrlHelper(); //Issue6Grid MVCGridDefinitionTable.Add("InitialDateGrid", new MVCGridBuilder <IReportInvoiceLine>() .WithSorting(false) .WithPaging(false) .WithAllowChangingPageSize(false) .WithFiltering(true) .WithNoResultsMessage("Please enter a year to search for. No results found.") .AddColumns(cols => { cols.Add("Year").WithHeaderText("Year") .WithFiltering(true) .WithValueExpression(a => a.Year.ToString()); cols.Add("InvoiceNo").WithHeaderText("Invoice No.") .WithVisibility(true, true) .WithValueExpression(a => a.InvoiceNumber.ToString()); cols.Add("City").WithHeaderText("City") .WithVisibility(true, true) .WithValueExpression(a => a.City); }) .WithRetrieveDataMethod((context) => { IList <IReportInvoiceLine> list = new List <IReportInvoiceLine>(); int totalRecords = 0; string syear = context.QueryOptions.GetFilterString("Year"); int year; if (Int32.TryParse(syear, out year)) { list = ReportInvoiceLines(year); totalRecords = list.Count; } return(new QueryResult <IReportInvoiceLine>() { Items = list, TotalRecords = totalRecords }); }) ); //Issue6Grid MVCGridDefinitionTable.Add("Issue6Grid", new MVCGridBuilder <Job>() .WithSorting(true) .WithDefaultSortColumn("Id") .WithPaging(true) .WithAllowChangingPageSize(true) .WithMaxItemsPerPage(100) .WithItemsPerPage(10) .WithAdditionalQueryOptionName("globalsearch") .AddColumns(cols => { cols.Add("Id", "Id", row => row.JobId.ToString()).WithSorting(true); cols.Add("Name", "Name", row => row.Name).WithSorting(true); cols.Add("Contact") .WithHeaderText("Contact") .WithSorting(false) .WithHtmlEncoding(false) .WithValueExpression((p, c) => p.Contact != null ? UrlHelper.Action("Edit", "Contact", new { id = p.Contact.Id }) : "") .WithValueTemplate("<a href='{Value}'>{Model.Contact.FullName}</a>").WithPlainTextValueExpression((p, c) => p.Contact != null ? p.Contact.FullName : ""); cols.Add("Delete") .WithHtmlEncoding(false) .WithSorting(false) .WithFiltering(false) .WithHeaderText("<input type='checkbox' id='chkselectall'>") .WithValueExpression((p, c) => UrlHelper.Action("Save", "Country", new { area = "General", id = p.JobId })) .WithValueTemplate("<input type='checkbox' class='select' value='{Model.JobId}'>") .WithPlainTextValueExpression((p, c) => ""); }) .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; string globalsearch = options.GetAdditionalQueryOptionString("globalsearch"); JobRepo repo = new JobRepo(); int totalRecords; var data = repo.GetData(out totalRecords, globalsearch, options.GetLimitOffset(), options.GetLimitRowcount(), options.GetSortColumnData <string>(), options.SortDirection == SortDirection.Dsc); return(new QueryResult <Job>() { Items = data, TotalRecords = totalRecords }); }) ); //Issue21Grid //ńłóźćłąę. MVCGridDefinitionTable.Add("Issue21Grid", new MVCGridBuilder <TestItem>() .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("Col1").WithValueExpression(p => "ńłóźćłąę."); cols.Add("Col2").WithValueExpression(p => p.Col2); }) .WithSorting(true, "Col1") .WithPaging(true, 10) .WithFiltering(true) .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; string col3Filter = context.QueryOptions.GetFilterString("FromDate"); TestItemRepository repo = new TestItemRepository(); int totalRecords; var items = repo.GetData(out totalRecords, col3Filter, options.GetLimitOffset(), options.GetLimitRowcount(), options.GetSortColumnData <string>(), options.SortDirection == SortDirection.Dsc); return(new QueryResult <TestItem>() { Items = items, TotalRecords = totalRecords }); }) ); //Issue17Grid MVCGridDefinitionTable.Add("Issue17Grid", new MVCGridBuilder <TestItem>() .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("Col1").WithValueExpression(p => p.Col1); cols.Add("Col2").WithValueExpression(p => p.Col2); cols.Add("FromDate").WithHeaderText("From Date").WithFiltering(true).WithValueExpression(x => x.Col3); }) .WithSorting(true, "Col1") .WithPaging(true, 10) .WithFiltering(true) .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; string col3Filter = context.QueryOptions.GetFilterString("FromDate"); TestItemRepository repo = new TestItemRepository(); int totalRecords; var items = repo.GetData(out totalRecords, col3Filter, options.GetLimitOffset(), options.GetLimitRowcount(), options.GetSortColumnData <string>(), options.SortDirection == SortDirection.Dsc); return(new QueryResult <TestItem>() { Items = items, TotalRecords = totalRecords }); }) ); //Issue28Grid MVCGridDefinitionTable.Add("Issue28Grid", new MVCGridBuilder <TestItem>() .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("Col1").WithValueExpression(p => p.Col1); cols.Add("Col2").WithValueExpression(p => p.Col2); cols.Add("Active").WithValueExpression(p => p.Col4.ToString()); cols.Add("Actions").WithHtmlEncoding(false).WithValueExpression((p, c) => { // here's how to get an action url string url = UrlHelper.Action("action1", "test"); // build whatever html you want StringBuilder sb = new StringBuilder(); sb.Append("<img src='action1.png' onclick='someFunction()'>"); sb.Append("<img src='action2.png' onclick='someFunction()'>"); // conditional html if (p.Col4) { sb.Append("<img src='action3.png' onclick='someFunction()'>"); } return(sb.ToString()); }); }) .WithSorting(true, "Col1") .WithPaging(true, 10) .WithFiltering(true) .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; TestItemRepository repo = new TestItemRepository(); int totalRecords; var items = repo.GetData(out totalRecords, null, options.GetLimitOffset(), options.GetLimitRowcount(), options.GetSortColumnData <string>(), options.SortDirection == SortDirection.Dsc); return(new QueryResult <TestItem>() { Items = items, TotalRecords = totalRecords }); }) ); }