This is a migrated thread and some comments may be shown as answers.

Calender resources

1 Answer 130 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Micael
Top achievements
Rank 1
Micael asked on 08 Jan 2020, 08:59 AM

I’ve a Razor Page project with Telerik ASP.NET Core Calender and a database in the back-end. In the Calender I can create new schedules that saves to the database and also read them to populate. For every schedule I would like to add what shift I should be related to so I’ve added a resource and if I create it as a new list it works fine but I can’t figure out how to populate from a table in the database. It feels that I’ve tried million ways now without success.
In this way it works:
                     .Resources(resource =>
                        {
                            resource.Add(m => m.ShiftID)
                            .Name("ShiftList")
                            .Title("Skift") 
                            .DataTextField("Text")
                            .DataValueField("Value")
                            .DataColorField("Color")

                            .BindTo(new[] {
                                new { Text = "fm-skift", Value = 1, Color = "#f8a398" } ,
                                new { Text = "em-skift", Value = 2, Color = "#51a0ed" } ,
                                new { Text = "Natt-skift", Value = 3, Color = "#56ca85" },
                                new { Text = "FM-skift", Value = 4, Color = "#c39bd3" },
                                new { Text = "EN-skift", Value = 5, Color = "#f1c40f" }
                            })
                            ;
                        })

But how can I populate from the database? All the Examples I can find are using MVC and not “true” Razor Pages.

on the model page I've created a list from the database that contains, Value, Textand Color, but I can't use it with Telerik Resources.

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 13 Jan 2020, 08:52 AM

Hello Micael,

Similarly to the Scheduler itself, the Resource field used could have its own DataSource configured:

.Resources(resource => {
	resource.Add(m => m.ShiftID)
		.Name("ShiftList")
		.Title("Skift")
		.DataTextField("Text")
		.DataValueField("Value")
		.DataColorField("Color")
		.DataSource(d => d
			.Read(r => r
				.Url("/Index?handler=ReadResources")
				.Data("getAdditionalData")
				.Type(HttpVerbs.Post)
			)
		);
})

That would allow you to call a Page method, which could be used to access and return the Resource table from your database:

public IActionResult OnPostReadResources()
{
	// Get data here from database
	List<ResourceViewModel> result = new List<ResourceViewModel>()
	{
		new ResourceViewModel() { Value = 1, Text = "R One", Color = "#381643"},
		new ResourceViewModel() { Value = 2, Text = "R Two", Color = "#908723"},
	};

	return new JsonResult(result);
}

Attached you will find a small sample implementing the above.

Regards,
Veselin Tsvetanov
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Scheduler
Asked by
Micael
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or