/// <summary> /// Update diagram links /// </summary> /// <param name="action">DiagramRequestModel object</param> /// <param name="wfs">WorkFlowService object</param> private void UpdateLinks(DiagramRequestModel action, WorkFlowService wfs) { LinkWFM link = null; switch (action.Action) { case DiagramAction.Inserted: // add new diagram link if (action.UpdatedLink.GUID == Guid.Empty) { action.UpdatedLink.GUID = Guid.NewGuid(); } link = DataMapperView.DoMapping<LinkViewModel, LinkWFM>(action.UpdatedLink); wfs.SaveLink(link, false); break; case DiagramAction.Deleted: // remove diagram link wfs.RemoveLink((int)action.SourceId, false); break; case DiagramAction.Updated: // update diagram link link = DataMapperView.DoMapping<LinkViewModel, LinkWFM>(action.UpdatedLink); wfs.SaveLink(link, false); break; default: action.Action = DiagramAction.Error; break; } }
/// <summary> /// Update diagram tasks /// </summary> /// <param name="action">DiagramRequestModel object</param> /// <param wfs="diagramData">WorkFlowService object</param> private void UpdateTasks(DiagramRequestModel action, WorkFlowService wfs) { TaskWFM task = null; switch (action.Action) { case DiagramAction.Inserted: // add new diagram task entity if (action.UpdatedTask.GUID == Guid.Empty) { action.UpdatedTask.GUID = Guid.NewGuid(); } task = DataMapperView.DoMapping<TaskViewModel, TaskWFM>(action.UpdatedTask); wfs.SaveTask(task, false); break; case DiagramAction.Deleted: // remove diagram tasks wfs.RemoveTask((int)action.SourceId, false); break; case DiagramAction.Updated: // update diagram task task = DataMapperView.DoMapping<TaskViewModel, TaskWFM>(action.UpdatedTask); wfs.SaveTask(task, false); break; default: action.Action = DiagramAction.Error; break; } }
public void ParseJson(FormCollection form, string diagramMode) { // save current culture and change it to InvariantCulture for data parsing var currentCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var prefixes = form["ids"].Split(','); foreach (var prefix in prefixes) { var diagramRequest = new DiagramRequestModel(); // lambda expression for form data parsing Func<string, string> parse = x => form[String.Format("{0}_{1}", prefix, x)]; diagramRequest.Mode = (DiagramMode)Enum.Parse(typeof(DiagramMode), diagramMode, true); diagramRequest.Action = (DiagramAction)Enum.Parse(typeof(DiagramAction), parse("!nativeeditor_status"), true); diagramRequest.SourceId = Int64.Parse(parse("id")); // parse task if (diagramRequest.Action != DiagramAction.Deleted && diagramRequest.Mode == DiagramMode.Tasks) { diagramRequest.UpdatedTask = new TaskViewModel() { TaskId = (diagramRequest.Action == DiagramAction.Updated) ? (int)diagramRequest.SourceId : 0, Text = parse("text"), StartDate = DateTime.Parse(parse("start_date")), Duration = (String.IsNullOrEmpty(parse("duration"))) ? 0 : Int32.Parse(parse("duration")), Progress = (String.IsNullOrEmpty(parse("progress"))) ? 0 : Decimal.Parse(parse("progress")), ParentId = (parse("parent") != "0") ? Int32.Parse(parse("parent")) : (int?)null, SortOrder = (parse("order") != null) ? Int32.Parse(parse("order")) : 0, Type = parse("type"), Holder = parse("holder") }; } // parse link else if (diagramRequest.Action != DiagramAction.Deleted && diagramRequest.Mode == DiagramMode.Links) { diagramRequest.UpdatedLink = new LinkViewModel() { LinkId = (diagramRequest.Action == DiagramAction.Updated) ? (int)diagramRequest.SourceId : 0, SourceTaskId = Int32.Parse(parse("source")), TargetTaskId = Int32.Parse(parse("target")), Type = parse("type") }; } actions.Add(diagramRequest); } // return current culture back Thread.CurrentThread.CurrentCulture = currentCulture; }