DHTMLX Scheduler重复发生的事件

时间:2015-01-31 15:06:00

标签: c# asp.net-mvc dhtmlx

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;
}

任何帮助或想法?

2 个答案:

答案 0 :(得分:0)

尝试将更改保存方法返回值更改为&#34; ContentResult&#34;。还要查看ApplicationDbContext,看看在索引加载时是否可以从该表中提取一些硬编码的db值。这是我的副本。在我使用linq创建模型/ EF并且我的上下文基于此之前,我遇到了同样的问题。当我创造自己的&#34;轻量级&#34;时,我遇到了同样的问题。界面,因为我不想使用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));           
    }

答案 1 :(得分:0)

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