public void LoadData() { var dc = new TaskDataContext(this.UserCD); var l = dc.Task_CompleteTimeIsNull_Get(this.UserCD, null, DateTimeInfo.GetToday().Date); if (l.Count > 0) { this.Data.HasData = true; for (int i = 0; i < l.Count; i++) { var r = l[i].Map(new TaskRecord()); if (i == 0) { this.Data.Task = r; } else { this.Data.TaskList.Add(r); } } } else { this.Data.HasData = false; } this.UpdateCommandData(State.AskComplete); }
public override HandleMessageResult HandleMessage(UserActionMessage message) { var cm = message.Command; switch (this.Data.State) { case State.AskStart: if (message.ActionType != UserActionType.Postback || cm == null) { return(new HandleMessageResult(false)); } if (cm.MethodName == nameof(State.AskStart)) { if (cm.Value.ToBoolean() == true) { this.LoadData(); if (this.Data.Task == null) { this.Complete(); } else { this.ResponseAskComplete(); } } else { this.Complete(); } return(new HandleMessageResult(true)); } break; case State.AskComplete: if (message.ActionType != UserActionType.Postback || cm == null) { return(new HandleMessageResult(false)); } if (cm.MethodName == "TaskSuspend") { this.UpdateCommandData(State.AskSuspend); this.ResponseAskSuspend(); return(new HandleMessageResult(true)); } if (cm.MethodName == "TaskComplete") { var rState = WebApp.Current.DatabaseCache.TaskState.GetDefaultState(this.Data.Task.ProjectCD, "Done"); var dc = new TaskDataContext(this.UserCD); dc.Task_CompleteState_Edit(this.Data.Task.TaskCD, rState.StateCD); } else if (cm.MethodName == "TaskInCompleted") { //Do nothing... } if (this.Data.TaskList.Count > 0) { this.TaskEdit(); } else { this.Complete(); } return(new HandleMessageResult(true)); case State.AskSuspend: if (message.ActionType == UserActionType.Postback) { if (cm.MethodName == "SuspendDay") { var dc = new TaskDataContext(this.UserCD); var days = cm.Value.ToInt32(); DateTime?dueDate = null; if (days.HasValue) { dueDate = DateTimeInfo.GetToday().Date.AddDays(days.Value); } dc.Task_DueDate_Edit(this.Data.Task.TaskCD, dueDate); this.TaskEdit(); } } else if (message.ActionType == UserActionType.Message) { var days = message.Text.ToInt32(); if (days > 0) { var dueDate = DateTimeInfo.GetToday().Date.AddDays(days.Value); var dc = new TaskDataContext(this.UserCD); dc.Task_DueDate_Edit(this.Data.Task.TaskCD, dueDate); } this.TaskEdit(); } return(new HandleMessageResult(true)); default: throw new InvalidOperationException(); } return(new HandleMessageResult(false)); }