【问题标题】:DHTMLX Scheduler recurring eventsDHTMLX 调度程序重复事件
【发布时间】:2015-03-30 22:35:32
【问题描述】:

我在使用 DHTMLX scheduler 时遇到问题,特别是在重复事件方面。

我已尝试按照此处http://blog.scheduler-net.com/post/recurring-events-calendar-view-asp-net.aspx 找到的文档进行操作。但是似乎无法正常工作。

我可以毫无问题地创建基本调度程序。我现在遇到的问题是任何创建的事件都不会保存到数据库中。这是我目前所拥有的。

型号:

[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[DHXJson(Alias = "id")]
public int Id { get; set; }

[DHXJson(Alias = "text")]
public string Description { get; set; }

[DHXJson(Alias = "start_date")]
public DateTime StartDate { get; set; }

[DHXJson(Alias = "end_date")]
public DateTime EndDate { get; set; }

[DHXJson(Alias="event_length")]
public int event_length { get; set; }

[DHXJson(Alias = "rec_type")]
public string rec_type { get; set; }

[DHXJson(Alias = "event_pid")]
public int event_pid { get; set; }

控制器:

public ActionResult Save(int? id, FormCollection actionValues)
{
    var action = new DataAction(actionValues);
    ApplicationDbContext data = new ApplicationDbContext();
    try
    {
        var changedEvent = (Appointment)DHXEventsHelper.Bind(typeof(Appointment), actionValues);
        //operations with recurring events require some additional handling
        bool isFinished = deleteRelated(action, changedEvent, data);
        if (!isFinished)
        {
            switch (action.Type)
            {

                case DataActionTypes.Insert:
                    data.Appointment.Add(changedEvent);
                    if (changedEvent.rec_type == "none")//delete one event from the serie
                        action.Type = DataActionTypes.Delete;
                    break;
                case DataActionTypes.Delete:
                    changedEvent = data.Appointment.SingleOrDefault(ev => ev.Id == action.SourceId);
                    data.Appointment.Remove(changedEvent);
                    break;
                default:// "update"   
                    var eventToUpdate = data.Appointment.SingleOrDefault(ev => ev.Id == action.SourceId);
                    DHXEventsHelper.Update(eventToUpdate, changedEvent, new List<string>() { "id" });
                    break;
            }
        }
        data.SaveChanges();
        action.TargetId = changedEvent.Id;
    }
    catch
    {
        action.Type = DataActionTypes.Error;
    }

    return (new AjaxSaveResponse(action));
}
protected bool deleteRelated(DataAction action, Appointment changedEvent, ApplicationDbContext context)
{
    bool finished = false;
    if ((action.Type == DataActionTypes.Delete || action.Type == DataActionTypes.Update) && !string.IsNullOrEmpty(changedEvent.rec_type))
    {
       // context.Recurrings.DeleteAllOnSubmit(from ev in context.Recurrings where ev.event_pid == changedEvent.id select ev);
    }
    if (action.Type == DataActionTypes.Delete && (changedEvent.event_pid != 0 && changedEvent.event_pid != null))
    {
    //    Recurring changed = (from ev in context.Recurrings where ev.id == action.TargetId select ev).Single();
     //   changed.rec_type = "none";
        finished = true;
    }
    return finished;
}

有什么帮助或想法吗?

【问题讨论】:

    标签: c# asp.net-mvc dhtmlx


    【解决方案1】:

    尝试将更改保存方法的返回值更改为“ContentResult”。还要查看您的 ApplicationDbContext ,看看您是否可以在索引加载时从该表中提取一些硬编码的 db 值。这是我的一份副本。在我使用 linq to classes 创建模型/EF 之前,我遇到了同样的问题,并且我的上下文基于此。我在创建自己的“轻量级”界面时遇到了同样的问题,因为我不想使用 EF。

    public ContentResult Save(int? id, FormCollection actionValues)
        {
            var action = new DataAction(actionValues);
            var context = new SchedulerDataContext();
            Int64 source_id = Int64.Parse(actionValues["id"]);
            try
            {
                var changedDelEvent = (Delivery)DHXEventsHelper.Bind(typeof(Delivery), actionValues);
                var changedRecEvent = (Recurring)DHXEventsHelper.Bind(typeof(Recurring), actionValues);
                //operations with recurring events require some additional handling
                bool isFinished = deleteRelated(action, changedRecEvent, context);
                if (!isFinished)
                {
                    switch (action.Type)
                    {
                        case DataActionTypes.Insert:
                            context.Recurrings.InsertOnSubmit(changedRecEvent);
                            context.SubmitChanges();
                            break;
                        case DataActionTypes.Delete:
                            changedRecEvent = context.Recurrings.SingleOrDefault(d => d.id == source_id);
                            if (changedRecEvent != null)
                            {
                                context.Recurrings.DeleteOnSubmit(changedRecEvent);
                            }
                            context.SubmitChanges();
                            break;
                        default:// "update"                                        
                            var eventToUpdate = context.Deliveries.SingleOrDefault(d => d.DeliveryID == source_id);
                            DHXEventsHelper.Update(eventToUpdate, changedRecEvent, new List<string> { "id" });
                            if (eventToUpdate != null && eventToUpdate.RouteID != changedRecEvent.id)
                            {
                                var routeToUpdate = context.Routes.SingleOrDefault(d => d.RouteID == changedRecEvent.id);
                                eventToUpdate.Route = routeToUpdate;
                            }
                            context.SubmitChanges();
                            break;
                    }
                    action.TargetId = changedRecEvent.id;
                }
            }
            catch
            {
                action.Type = DataActionTypes.Error;
            }
    
            return (new AjaxSaveResponse(action));           
        }
    

    【讨论】:

    • 你会注意到我正在尝试让重复工作,这就是为什么我有两个“改变”,但是没有重复的事件的 crud 工作得很好。
    【解决方案2】:

    循环扩展 (dhtmlxscheduler_recurring.js) 无法识别您在实体类属性上使用的 DHXJson Alias 注释(非常令人沮丧)。因此,您必须按照 dhtmlxscheduler_recurring.js 所期望的方式准确命名实体类列/属性,即使基本调度程序 API 为您提供了使用 DHXJson 别名注释进行自定义命名的选项。

    【讨论】:

      猜你喜欢
      • 2018-05-25
      • 2019-09-30
      • 2012-11-23
      • 2021-10-18
      • 2019-07-27
      • 2018-08-07
      • 1970-01-01
      • 1970-01-01
      • 2017-01-07
      相关资源
      最近更新 更多