public ContentResult Save(FormCollection form)
        {
            var dataActions = DhtmlxRequest.Parse(form, Request.QueryString["gantt_mode"]);

            try
            {
                foreach (var ganttData in dataActions)
                {
                    switch (ganttData.Mode)
                    {
                    case GanttMode.Tasks:
                        UpdateTasks(ganttData);
                        break;

                    case GanttMode.Links:
                        UpdateLinks(ganttData);
                        break;
                    }
                }
            }
            catch
            {
                // return error to client if something went wrong
                dataActions.ForEach(g => { g.Action = DhtmlxAction.Error; });
            }
            return(GanttRespose(dataActions));
        }
        /// <summary>
        /// Update gantt links
        /// </summary>
        /// <param name="ganttData">GanttData object</param>
        private void UpdateLinks(DhtmlxRequest ganttData)
        {
            switch (ganttData.Action)
            {
            case DhtmlxAction.Inserted:
                // add new gantt link entity
                ganttData.UpdatedLink.ProjectId = _ganttService.GetTask(ganttData.UpdatedLink.SourceTaskId).ProjectId;
                _ganttService.InsertLink(ganttData.UpdatedLink);
                break;

            case DhtmlxAction.Deleted:
                // remove gantt link
                _ganttService.DeleteLink(_ganttService.GetLink(ganttData.SourceId));
                break;

            case DhtmlxAction.Updated:
                // update gantt link
                _ganttService.UpdateLink(ganttData.UpdatedLink);
                //db.Entry(db.Tasks.Find(ganttData.UpdatedTask.Id)).CurrentValues.SetValues(ganttData.UpdatedTask);
                break;

            default:
                ganttData.Action = DhtmlxAction.Error;
                break;
            }
        }
        /// <summary>
        /// Update gantt tasks
        /// </summary>
        /// <param name="ganttData">GanttData object</param>
        private void UpdateTasks(DhtmlxRequest ganttData)
        {
            switch (ganttData.Action)
            {
            case DhtmlxAction.Inserted:
                // add new gantt task entity
                long?parent    = ganttData.UpdatedTask.ParentId;
                int  projectID = -1;
                while (parent != null)
                {
                    projectID = (int)parent;
                    parent    = _ganttService.GetTask((long)parent).ParentId;
                }
                ganttData.UpdatedTask.ProjectId = projectID;
                _ganttService.InsertTask(ganttData.UpdatedTask);
                break;

            case DhtmlxAction.Deleted:
                // remove gantt task
                _ganttService.DeleteTaskLinks(ganttData.SourceId);
                _ganttService.DeleteTask(_ganttService.GetTask(ganttData.SourceId));
                break;

            case DhtmlxAction.Updated:
                // update gantt task
                _ganttService.UpdateTask(ganttData.UpdatedTask);
                //db.Entry(db.Tasks.Find(ganttData.UpdatedTask.Id)).CurrentValues.SetValues(ganttData.UpdatedTask);
                break;

            default:
                ganttData.Action = DhtmlxAction.Error;
                break;
            }
        }
Exemple #4
0
        private ContentResult EventRespose(DhtmlxRequest eventData)
        {
            var actions = new List <XElement>();
            var action  = new XElement("action");

            action.SetAttributeValue("type", eventData.Action.ToString().ToLower());
            action.SetAttributeValue("sid", eventData.SourceId);
            action.SetAttributeValue("tid", (eventData.Action != DhtmlxAction.Inserted) ? eventData.SourceId : eventData.UpdatedEvent.Id);
            actions.Add(action);

            var data = new XDocument(new XElement("data", actions));

            data.Declaration = new XDeclaration("1.0", "utf-8", "true");
            return(Content(data.ToString(), "text/xml"));
        }
Exemple #5
0
        public ContentResult Save(FormCollection form)
        {
            var dataAction = DhtmlxRequest.ParseEventRequest(form);

            try
            {
                switch (dataAction.Action)
                {
                case DhtmlxAction.Inserted:
                    // add new gantt task entity
                    _eventService.InsertEvent(dataAction.UpdatedEvent);
                    break;

                case DhtmlxAction.Deleted:
                    // remove gantt tasks
                    _eventService.DeleteEvent(_eventService.GetEvent(dataAction.SourceId));
                    break;

                case DhtmlxAction.Updated:
                    // update gantt task
                    _eventService.UpdateEvent(dataAction.UpdatedEvent);
                    //db.Entry(db.Tasks.Find(ganttData.UpdatedTask.Id)).CurrentValues.SetValues(ganttData.UpdatedTask);
                    break;

                default:
                    dataAction.Action = DhtmlxAction.Error;
                    break;
                }
            }
            catch
            {
                // return error to client if something went wrong
                dataAction.Action = DhtmlxAction.Error;;
            }

            return(EventRespose(dataAction));
        }