Select theme:
In this final part of the CRM tutorial we will add a few final features that will make the CRM application more polished.
We will rearrange the navigation, create a hierarchy, and add icons.
The application navigation typically lives in the Main layout. Layouts are special pages that define common UI components that are shared between multiple pages.
Dashboard
and Icon to home
.
perm_contact_calendar
.work
.shopping_cart
.Settings
and Icon: settings
. Set the Visible property to ${security.user.isInRole("Sales Manager")}
.
This makes this item visible only to members of the Sales Manager
role.
Opportunity Statuses
and pick the Opportunity Statuses
page from the Path dropdown.
Task Types
and pick the Task Types
page from the Path dropdown.Task Statuses
page.Now when a member of the Sales Manager
role logs in she would see this navigation.
Members of the
Sales Representative
role will see this (not that the Settings menu item is not present).
By default the Main layout has a ProfileMenu component which allows users to logout or update their profile. Let's customize the ProfileMenu to show the current user name and profile picture.
First we have to retrieve the current user details - FirstName
, LastName
and Picture
from the database. The easiest
and most secure way to do that is via custom method.
server\project.csproj
with Vusual Studio (or the server
directory with Visual Studio Code).server\Controllers\ServerMethodsController.cs
.ServerMethodsController
class with the Authorize
attribute. It is mandatory for getting the currently logged user via the ASP.NET Core Identity framework.[Authorize(AuthenticationSchemes = "Bearer")]
public class ServerMethodsController : Controller
{
/* snip */
}
UserManager
ASP.NET Core Identity class.private readonly UserManager<ApplicationUser> userManager;
public ServerMethodsController(CrmContext context, UserManager<ApplicationUser> userManager)
{
this.context = context;
this.userManager = userManager;
}
public IActionResult UserPersonalData()
{
var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
var user = userManager.FindByIdAsync(userId).GetAwaiter().GetResult();
return Json(new
{
FirstName = user.FirstName,
LastName = user.LastName,
Picture = user.Picture
}, new JsonSerializerSettings()
{
ContractResolver = new DefaultContractResolver()
});
}
Now that we a custom method we can invoke it and store the user details in a page property.
UserPersonalData
custom method.Then
event and create a page property called userData
with the ${result}
.
Time to update the ProfileMenu.
${userData.FirstName} ${userData.LastName}
.${userData.Picture}
. Set Width and Height to 32px
and BorderRadius to 16px
.If you run the application from Radzen you will see the current user picture and name in the top right corner.
When you enable security for a Radzen application one of the scaffolded pages is Profile (also accessible from the ProfileMenu component in the top right corner).
By default it allows the current user to change their password. In the CRM application we have extended the AspNetUsers table with three new columns - FirstName
, LastName
, Picture
and we want the
user to be able to change them.
First we will create a custom method that updates the details of the current user.
server\project.csproj
with Vusual Studio (or the server
directory with Visual Studio Code).server\Controllers\ServerMethodsController.cs
.[HttpPost]
public IActionResult UpdatePersonalData(string firstName, string lastName, string picture)
{
var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;
var user = userManager.FindByIdAsync(userId).GetAwaiter().GetResult();
user.FirstName = firstName;
user.LastName = lastName;
user.Picture = picture;
var result = userManager.UpdateAsync(user).GetAwaiter().GetResult();
if (result == IdentityResult.Success)
{
return Ok();
}
else
{
var message = string.Join(", ", result.Errors.Select(error => error.Description));
return BadRequest(new { error = new { message }});
}
}
Now let's create the UI.
Personal
and Password
.Password
item and move the existing Form there.
Personal
tab and drag and drop a new Form inside.FirstName
, Title: First Name
, Required: Checked.LastName
, Title: Last Name
, Required: CheckedPicture
, Title: Picture
, Type: file
, Required: Checked
UserPersonalData
custom method and create a property called personalData
set to ${result}
.${personalData}
. This will data-bind the form to the personalData
property - the form fields will show the corresponding members
of the personalData
page property. The final step is to use the UpdatePersonalData
method when the user submits the form.
UpdatePersonalData
custom method.${event.FirstName}
${event.LastName}
${event.Picture}
Finally let's create a custom login page by editing both the Login layout and page.
We will add a background image that will cover the whole page. Also we will add the CRM application logo.
Radzen allows you to use images seamlessly. For this demo we will use a background and logo. Download those files and add them as assets in the application.
100%
. Set Position to absolute
. Set Top and Left to 0
. This will make the image cover the whole page.
We now want to center the login form in the page (both horizontally and vertically).
Center
.absolute
, Top, Right, Bottom and Left to 0
. Set Margin to 0
.3
units, LG to 4
, MD to 5
and SM to 8
.None
.0px
.logo.png
.128px
. Set BorderRadius to 64px
. This will make the logo a circle.block
. Set Right and Left Margin to auto
.-72px
.
Let's now customize the Login page by using a TemplateForm instead of the Login component.
Username
and Width to 100%
. Set top Margin to 16px
.Username
and pick Username
from the Component dropdown. Set Display to block
so the TextBox starts on the next line.
Password
and Width to 100%
.Password
.
Login
, ButtonType to submit
, Width to 100%
and top Margin to 16px
.
Now to actually perform the login.
login
data source method. Set the username parameter to ${event.Username}
and password to ${event.Password}
.
That is all!
The complete source of this application (with a few additional changes that are mostly cosmetic) is available in the Radzen github repository.
Radzen is free to use. You can also test the premium features for 15 days.
Download NowSelect theme: