Patterns and practices has released a new version of guidance for building collaborative applications.
One of the new functionality provided by the Microsoft group is very useful and generic, w.r.t creating and saving business entities. Concept is based on List based repositories by following below steps -
- Business entity class E.g. Customer
- Static class that contains the SharePoint field IDs for the list to be used.
- Repository class which creates instance of the ListItemFieldMapper class and adds mappings that associate the field IDs to the corresponding property of the business entity
Please refer - http://msdn.microsoft.com/en-us/library/ee413898.aspx for more details
After business entity and mapping classes are defines, generic functionality could be used to retrieve and save the business entity directly with SharePoint.
Sample Code -
- Creating collection for Customer Business Entity:
public IList<Customer> GetAllCustomers()
{
// ...
using (SPSite site = new SPSite(customerWebUrl))
{
using (SPWeb customerWeb = site.OpenWeb())
{
SPList customerList = customerWeb.Lists[Constants.CustomerListName];
CAMLQueryBuilder camlQueryBuilder = new CAMLQueryBuilder();
camlQueryBuilder.FilterByContentType(CustomerContentTypeName);
SPListItemCollection items = customerList.GetItems(camlQueryBuilder.Build());
IList<Customer> customers = new List<Customer>();
foreach(SPListItem item in items)
{
Customer customer = listItemFieldMapper.CreateEntity(item);
customers.Add(customer);
}
return customers;
}
}
} - Save a Business Entity to a List
public void AddCustomer(Customer customer)
{
using (SPSite site = new SPSite(customerWebUrl))
{
using (SPWeb customerWeb = site.OpenWeb())
{
SPList customerList = customerWeb.Lists[Constants.CustomerListName];
SPListItem customerListItem = customerList.Items.Add();
this.listItemFieldMapper.FillSPListItemFromEntity( customerListItem, customer);
customerList.Update();
}
}
}
My current project requires ability to display choice column value via color or image associated with a choice
ReplyDeleteBut Sharepoint standard packaged misses that control
I am looking for available solutions on market
I came across
http://sharepointfields.com
Does anybody has experiece using it?