示例#1
0
 public TagViewModel(Tag tag, IList<Task> tasks)
     : this(tag)
 {
     foreach (Task task in tasks) {
         TaskViewModel t = new TaskViewModel(task);
         this.Tasks.Add(t);
     }
 }
 public TaskListViewModel(TaskList taskList, IList<Task> tasks)
     : this(taskList)
 {
     foreach (Task task in tasks) {
         if (task != null) {
             TaskViewModel t = new TaskViewModel(task);
             this.Tasks.Add(t);
         }
     }
 }
示例#3
0
        public ActionResult Create(TaskViewModel model)
        {
            // Get the account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);

            // Get the task list.
            TaskList taskList = model.TaskListID == 0 ?
                account.Inbox :
                _taskListService.Load(model.TaskListID, account);
            
            // Create a new task and set properties.
            Task newTask = new Task();
            newTask.Title = model.Title;
            newTask.Important = model.Important;
            newTask.Note = model.Note;

            // Due date.
            if (model.Due.HasValue) {
                Logger.Debug(model.Due.Value);
                newTask.Due = model.Due.Value.ToUniversalTime();
            }
            else
                newTask.Due = null;

            // Tags.
            if (model.Tags != null) {
                foreach (TagViewModel selectedTag in model.Tags) {
                    Tag tag = _tagService.Load(selectedTag.ID, account);
                    newTask.Tags.Add(tag);
                }
            }
            
            // Add to task list.
            taskList.AddTask(newTask);

            // Create the new task.
            _taskService.CreateTask(newTask, account);

            // Create view model and return.
            model = new TaskViewModel(newTask);
            return Content(JsonUtils.SerializeObject(model));
        }
示例#4
0
        public ActionResult Update(TaskViewModel model)
        {
            // Get account and task.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            Task task = _taskService.Load(model.ID, account);
            
            // Update simple properties.
            task.Important = model.Important;
            task.Done = model.Done;
            task.Title = model.Title;
            task.Note = model.Note;
            
            // Due date.
            if (model.Due.HasValue)
                task.Due = model.Due.Value.ToUniversalTime();
            else
                task.Due = null;

            // Update task list.
            TaskList current = task.TaskList;
            TaskList taskList = model.TaskListID == 0 ?
                account.Inbox :
                _taskListService.Load(model.TaskListID, account);
            if (current.ID != taskList.ID) {
                current.RemoveTask(task);
                taskList.AddTask(task);
            }

            // Update tags.
            task.Tags.Clear();
            if (model.Tags != null) {
                foreach (TagViewModel selectedTag in model.Tags) {
                    Tag tag = _tagService.Load(selectedTag.ID, account);
                    task.Tags.Add(tag);
                }
            }
            
            // Recreate view model and return.
            model = new TaskViewModel(task);
            return Content(JsonUtils.SerializeObject(model));
        }