I recently had the need to develop an example project in Sitecore with the following requirements:
Build a mini CRM in Sitecore using MVC with the following features:
a. A page where a user can add contact details – Name, email, phone and address
b. A listing page with search capabilities (search by email, first name)
c. Ability to edit and delete users
d. A decent user interface
Soooooo, I put this project together in a hurry and demonstrated it to my client. And now that I have no need for it anymore, why not share it on the blog, right? Cut me a little slack on this one - I did the whole thing in about 4 hours, so i can't vouch for coolness or completeness.
I developed this on Sitecore 8.2 Update 2, but it should work on any Sitecore version 7.5 or later. The requirements called for search capability, so I chose to go with Solr. You could just as easily use Lucene or Azure Search or even something more sophisticated like Coveo for Sitecore if you were so inclined. I am storing the user records as bucketed items in Sitecore. The requirement for "a decent user interface" is accomplished with Bootstrap and MVC Razor views.
- You will need to install Sitecore
- You will need to install Solr
- You will need Visual Studio 2017 or later
- Download the full Mini CRM solution here: MiniCrm.zip (362.64 kb).
- Unzip the solution somewhere, and open it in Visual Studio.
- Restore all the Nuget packages.
- Add references to your Sitecore assemblies:
- Take a look at this config file: /app_config/include/MiniCrmIndex.config. As you can see, you need to create a new Solr core named "mini_crm_index_master". Here are some tips on how to do it.
- Create a publish profile in Visual Studio that points to your Sitecore instance.
- Publish the solution. This will publish the following assets to your website (Most of these files are the ones that come with a standard Visual Studio web application):
- Now it's time for some Sitecore work. Log in to your Sitecore as an Admin, and install this package
MiniCrm Sitecore Items-1.0.zip (41.30 kb). This will install the following items:
- /sitecore/templates/User (this is the User template)
- /sitecore/layout/Renderings/User List Rendering (this is a Controller Rendering for the user list method)
- /sitecore/layout/Renderings/User Edit Rendering (this is a Controller Rendering for the user edit method)
- /sitecore/layout/Renderings/User List Rendering (this is a Controller Rendering for the user delete method)
- /sitecore/content/Users (this is the bucket folder to store User items)
- Next, we'll set up the presentation items. Add three new items to your content tree: "UserList", "UserEdit" and "UserDelete".
- Configure the presentation details for each item (here's an example for the UserList item):
- At this point you're ready to run your new application! Here are some screen shots:
So there you have it! I hope this example is helpful to someone out there in Sitecore land. If I had more time to work on this I certainly would have included things like unit tests, better error handling for edge cases, more functionality on the form, like sorting, etc. But this gives you the basic idea of how to do MVC in Sitecore.