Exemplo n.º 1
0
        private void GetTasksAfterResponse(string tasklistId, ResultCode resultCode, RestResponse response)
        {
            string result = response.Content;

            JObject dict = (JObject)result.ToJSONObject();
            string tasklist_editableString = dict["Editable"].Value<string>();

            this._tasklistRepository.UpdateEditable(tasklist_editableString.ToLower().Equals("true") ? 1 : 0, tasklistId);
            this._taskRepository.DeleteAll(tasklistId);
            this._taskIdxRepository.DeleteAll(tasklistId);

            JArray tasksArray = (JArray)dict["List"];
            JArray taskIdxsArray = (JArray)dict["Sorts"];

            List<Task> tasks = new List<Task>();
            for (int i = 0; i < tasksArray.Count; i++)
            {
                JToken taskDict = tasksArray[i];
                string taskId = taskDict["ID"].Value<string>();
                string subject = taskDict["Subject"].Value<string>();
                string body = taskDict["Body"].Value<string>();
                bool isCompleted = taskDict["IsCompleted"].Value<bool>();
                string priority = taskDict["Priority"].Value<string>();
                bool editable = taskDict["Editable"].Value<bool>();
                string dueTimeString = taskDict["DueTime"].Value<string>();

                Task task = new Task();
                task.Subject = subject;
                DateTime currentDate = DateTime.Now;
                task.CreateDate = currentDate;
                task.LastUpdateDate = currentDate;
                task.Body = body;
                task.IsPublic = true;
                task.Status = isCompleted ? 1 : 0;
                task.Priority = priority;
                task.TaskId = taskId;
                DateTime dueTime;
                if (DateTime.TryParse(dueTimeString, out dueTime))
                {
                    task.DueDate = dueTime;
                }

                task.Editable = editable;
                task.TasklistId = tasklistId;
                if (IsolatedStorageSettings.ApplicationSettings.Contains(Constant.USERNAME_KEY))
                {
                    string username = (string)IsolatedStorageSettings.ApplicationSettings[Constant.USERNAME_KEY];
                    task.AccountId = username;
                }
                else
                {
                    task.AccountId = "";
                }
                tasks.Add(task);
            }
            this._taskRepository.AddTasks(tasks);

            List<TaskIdx> taskIdxs = new List<TaskIdx>();
            for (int i = 0; i < taskIdxsArray.Count; i++)
            {
                JToken taskIdxDict = taskIdxsArray[i];
                string by = taskIdxDict["By"].Value<string>();
                string taskIdxKey = taskIdxDict["Key"].Value<string>();
                string name = taskIdxDict["Name"].Value<string>();

                JArray indexsArray = (JArray)taskIdxDict["Indexs"];
                string indexes = indexsArray.ToJSONString();

                TaskIdx taskIdx = new TaskIdx();
                taskIdx.By = by;
                taskIdx.Key = taskIdxKey;
                taskIdx.Name = name;
                taskIdx.Indexes = indexes;
                taskIdx.TasklistId = tasklistId;
                if (IsolatedStorageSettings.ApplicationSettings.Contains(Constant.USERNAME_KEY))
                {
                    string username = (string)IsolatedStorageSettings.ApplicationSettings[Constant.USERNAME_KEY];
                    taskIdx.AccountId = username;
                }
                else
                {
                    taskIdx.AccountId = "";
                }
                taskIdxs.Add(taskIdx);
            }
            this._taskIdxRepository.AddTaskIdxs(taskIdxs);

            resultCode.Status = true;

            this.DispatchCommandResult(resultCode);
        }
Exemplo n.º 2
0
        public void AddTaskIdx(string taskId, string key, string tasklistId)
        {
            List<TaskIdx> taskIdxs = null;
            if (IsolatedStorageSettings.ApplicationSettings.Contains(Constant.USERNAME_KEY))
            {
                string username = IsolatedStorageSettings.ApplicationSettings[Constant.USERNAME_KEY] as string;
                taskIdxs = this._context.TaskIdxs
                    .Where(o => o.Key.Equals(key)
                        && o.TasklistId.Equals(tasklistId)
                        && o.AccountId.Equals(username))
                    .ToList();
            }
            else
            {
                taskIdxs = this._context.TaskIdxs
                    .Where(o => o.Key.Equals(key)
                        && o.TasklistId.Equals(tasklistId)
                        && o.AccountId.Equals(""))
                    .ToList();
            }

            TaskIdx taskIdx = null;
            JArray indexesArray = null;
            if (taskIdxs == null || (taskIdxs != null && taskIdxs.Count == 0))
            {
                taskIdx = new TaskIdx();
                taskIdx.By = "priority";
                taskIdx.Key = key;
                taskIdx.Name = key == "0" ? Constant.PRIORITY_TITLE_1 : (key == "1"
                    ? Constant.PRIORITY_TITLE_2 : Constant.PRIORITY_TITLE_3);
                if (IsolatedStorageSettings.ApplicationSettings.Contains(Constant.USERNAME_KEY))
                {
                    string username = IsolatedStorageSettings.ApplicationSettings[Constant.USERNAME_KEY] as string;
                    taskIdx.AccountId = username;
                }
                else
                {
                    taskIdx.AccountId = "";
                }
                indexesArray = new JArray();
            }
            else
            {
                taskIdx = taskIdxs[0];
                if (string.IsNullOrEmpty(taskIdx.Indexes))
                {
                    indexesArray = new JArray();
                }
                else
                {
                    indexesArray = (JArray)taskIdx.Indexes.ToJSONObject();
                }
            }
            indexesArray.Add(taskId);
            taskIdx.Indexes = indexesArray.ToJSONString();
            taskIdx.TasklistId = tasklistId;

            if (taskIdxs == null || (taskIdxs != null && taskIdxs.Count == 0))
            {
                this._context.TaskIdxs.InsertOnSubmit(taskIdx);
            }
            this._context.SubmitChanges();
        }