Flat Forms: DataServiceBase - ProCodersPtyLtd/MasterDetailsDataEntry GitHub Wiki
DataServiceBase
Class Namespace:
using Platz.SqlForms;
Declaration:
public abstract class DataServiceBase : IDataForm
Base class for DataServiceBase<T>
generic class
Define - protected virtual method
protected virtual void Define(DataServiceFormBuilder builder)
{
}
This method should be implemented in a Dynamic List Form class that is inherited from DataServiceBase<T>
. The method accepts only one parameter DataServiceFormBuilder builder
. The following example shows how to use it:
protected override void Define(DataServiceFormBuilder builder)
{
builder.Entity<CustomerAddress>(e =>
{
e.ExcludeAll();
e.Property(p => p.AddressId).IsPrimaryKey();
e.Property(p => p.CustomerId).IsFilter().IsReadOnly();
e.Property(p => p.Title);
e.Property(p => p.FirstName);
e.Property(p => p.LastName);
e.Property(p => p.AddressLine1);
e.Property(p => p.AddressLine2);
e.Property(p => p.City);
e.Property(p => p.CountryRegion);
e.Property(p => p.PostalCode);
// Parameter {0} is always PrimaryKey, parameters {1} and above - Filter Keys
// {0} = AddressId {1} = CustomerId
e.ContextButton("Edit", "CustomerAddrEdit/{0}/{1}").ContextButton("Delete", "CustomerAddrDelete/{0}/{1}");
e.DialogButton("CustomerAddrEdit/0/{1}", ButtonActionTypes.Add);
});
builder.SetListMethod(GetCustomerAddressList);
}
DataServiceBase<T>
Class Namespace:
using Platz.SqlForms;
Declaration:
public abstract class DataServiceBase<T> : DataServiceBase where T : DbContext
Base class to create a Dynamic List Form definition.
Parameters:
DataServiceBase accepts T
template parameter, it should be a class that based on Entity Framework DbContext
DataServiceFormBuilder
Class Declaration:
public class DataServiceFormBuilder : FormBuilder
Inherits all FormBuilder
behaviour and extends it functionality to be used with DataServiceBase
class
SetListMethod - method
public virtual void SetListMethod(Func<object[], object> method)
Allows to provide delegate that is executed when List Form UI components needs to read data from the database
protected override void Define(DataServiceFormBuilder builder)
{
builder.Entity<StudentDetails>(e =>
{
...
});
builder.SetListMethod(GetStudentList);
}
public List<StudentDetails> GetStudentList(params object[] parameters)
{
using (var db = GetDbContext())
{
var query =
from s in db.Student
select new StudentDetails
{
ID = s.ID,
FirstMidName = s.FirstMidName,
LastName = s.LastName,
EnrollmentDate = s.EnrollmentDate,
EnrollmentCount = (db.Enrollment.Where(e => e.StudentID == s.ID).Count())
};
var result = query.ToList();
return result;
}
}