如何从不同的控制器加载资源并在用户单击选项卡导航 Telerik Scheduler UI 时更改它?

How to load resource from different Controller and and change it when user click in tab nav Telerik Scheduler UI?

我正在尝试找到一种方法将 Rooms 加载到 Telerik Scheduler 的资源部分 UI。 Scheduler UI 绑定到 Meeting 模型,用户可以在其中从 Room 预订会议室。我想做的是找到一种方法来绑定来自另一个控制器和模型的资源 "Rooms" 以及当用户 select 不同办公室

时如何更改资源

自视图

 <div class="row">
        <div class="col-md-12">
            <ul class="nav nav-tabs" id="officeTab"><li><a class="office" href="#" data-value="3">London</a></li><li><a class="office" href="#" data-value="5">Hanover</a></li><li><a class="office" href="#" data-value="4">Owen Sound</a></li><li><a class="office" href="#" data-value="1">Seaforth</a></li><li><a class="office" href="#" data-value="6">St. Thomas</a></li><li><a class="office" href="#" data-value="2">Stratford</a></li><li><a class="office" href="#" data-value="8">Woodstock</a></li></ul>
        </div>
    </div>
<div>
    @(Html.Kendo().Scheduler<Meeting>().Name("scheduler").Date(new DateTime(2017, 5, 13))
          .StartTime(new DateTime(2017, 5, 13, 7, 00, 00))
          .Editable(true)
          .Views(views =>
          {
              views.DayView();
              views.AgendaView();
          })
          .Height(600)
          .Timezone("Etc/UTC")
          .Group(group => { group.Resources("Rooms"); group.Date(true); })
          .Resources(resource =>
          {
              resource.Add(m => m.RoomId)
              .Title("Room")
              .Name("Rooms")
              .DataTextField("Text")
              .DataValueField("Value")
              .DataColorField("Color")
              .DataSource(d => d.Read("Get", "Room"));
          }).DataSource(d => d
              .WebApi()
              .Model(m =>
              {
                  m.Id(f => f.RecordId);
                  m.Field(f => f.Title).DefaultValue("No title");
                  m.Field(f => f.Title).DefaultValue("No title");
              })
              .Events(events => events.Error("error_handler"))
              .Read(read => read.Action("Get", "Meeting"))
              .Create(create => create.Action("Post", "Meeting"))
              .Destroy(destroy => destroy.Action("Delete", "Meeting", new { recordId = "{0}" }))
              .Update(update => update.Action("Put", "Meeting", new { recordId = "{0}" }))
          ).Deferred())


    @section scripts {
        @Html.Kendo().DeferredScripts()
    }
    <script>
        function error_handler(e) {
            var errors = $.parseJSON(e.xhr.responseText);

            if (errors) {
                alert("Errors:\n" + errors.join("\n"));
            }
        }
    </script> 
</div>

//会议控制器

using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using Microsoft.AspNetCore.Mvc;
using RoomBooking.Application.Couties.Queries;
using RoomBooking.Application.Rooms.Queries;
using RoomBooking.Domain;

namespace RoomBooking.Presentation.Controllers
{
    [Route("api/v1/[controller]")]
    public class MeetingController : Controller
    {
        [HttpGet]
        public DataSourceResult Get([DataSourceRequest]DataSourceRequest request)
        {
            //return meetingData.GetAll().ToDataSourceResult(request);
            return this.meetingService.GetAll().ToDataSourceResult(request); ;
        }


        public MeetingController(ISchedulerEventService<MeetingModel> meetingService, ISchedulerEventService<ListRoomModel> resourcesService)
        {
            this.meetingService = meetingService;
            this.resourcesService = resourcesService;
        }
        private readonly ISchedulerEventService<MeetingModel> meetingService;
        private readonly ISchedulerEventService<ListRoomModel> resourcesService;
    }
}

//房间控制器

using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using Microsoft.AspNetCore.Mvc;
using RoomBooking.Application.Couties.Queries;
using RoomBooking.Application.Rooms.Queries;
using RoomBooking.Domain;


namespace RoomBooking.Presentation.Controllers
{
    [Route("api/v1/[controller]")]
    public class RoomController : Controller
    {
        [HttpGet]
        public DataSourceResult Get([DataSourceRequest]DataSourceRequest request)
        {
            //return meetingData.GetAll().ToDataSourceResult(request);
            //return this.getRoomsListQuery.Execute().ToDataSourceResult(request);
            var result =  this.resourcesService.GetAll().ToDataSourceResult(request);
            return result;
        }

        public RoomController(ISchedulerEventService<ListRoomModel> resourcesService)
        {
            this.resourcesService = resourcesService;
        }

    private readonly ISchedulerEventService<ListRoomModel> resourcesService;
    }
}

我找到了如何使用来自 asp.net MVC 的示例将项目加载到资源中,您可以在 asp.net 核心 link 中使用相同的方法 https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/scheduler/scheduler-resource-editing

@using Kendo.Mvc.UI
@using Kendo.Mvc.UI.Fluent
@using RoomBooking.Domain
@{
    ViewData["Title"] = "Home Page";
}


<div class="row">
    <div class="col-md-12">
        <ul id="officeTab" class="nav nav-tabs"></ul>
    </div>

</div>

<div>
    @(Html.Kendo().Scheduler<Meeting>().Name("scheduler").Date(new DateTime(2017, 5, 13))
          .StartTime(new DateTime(2017, 5, 13, 7, 00, 00))
          .Editable(true)
          .Views(views =>
          {
              views.DayView();
              views.AgendaView();
          })
          .Height(600)
          .Timezone("Etc/UTC")
          .Group(group => { group.Resources("Rooms"); group.Date(true); })
          .Resources(resource =>
          {
              //resource.Add(m => m.RoomId).Title("Room").Name("Rooms").DataTextField("Text").DataValueField("Value").DataColorField("Color").BindTo(new[]
              //{
              //    new {Text = "Meeting Room 101", Value = 1, Color = "#6eb3fa"},
              //    new {Text = "Meeting Room 201", Value = 2, Color = "#f58a8a"}
              //});
              resource.Add(m => m.RoomId)
                 .Title("Room")
                 .Name("Rooms")
                 .DataTextField("Text")
                 .DataSource(
                     ds => ds.Custom()
                     .Type("aspnetmvc-ajax")
                     .Transport(t => t.Read(r =>
                    r.Action("readRoom", "Room")))
                    .Schema(s => s.Data("Data").Total("Total").Errors("Errors").Model(m =>
                    {
                        m.Id("Value");
                        m.Field("Value", typeof(int));
                        m.Field("Text", typeof(string));
                        m.Field("Color", typeof(string));
                    })
                    ));
          })
          .DataSource(d => d
              .WebApi()
              .Model(m =>
              {
                  m.Id(f => f.RecordId);
                  m.Field(f => f.Title).DefaultValue("No title");
                  m.Field(f => f.Title).DefaultValue("No title");
              })
              .Events(events => events.Error("error_handler"))
              .Read(read => read.Action("Get", "Meeting"))
              .Create(create => create.Action("Post", "Meeting"))
              .Destroy(destroy => destroy.Action("Delete", "Meeting", new { recordId = "{0}" }))
              .Update(update => update.Action("Put", "Meeting", new { recordId = "{0}" }))
          ).Deferred())


    @section scripts {
        @Html.Kendo().DeferredScripts()
    }
    <script>
        function error_handler(e) {
            var errors = $.parseJSON(e.xhr.responseText);

            if (errors) {
                alert("Errors:\n" + errors.join("\n"));
            }
        }
    </script>

</div>