コード例 #1
0
ファイル: TaskService.cs プロジェクト: kevinswarner/Hover_OLD
 public void Delete(Task task, Account account)
 {
     if (!task.BelongsToAccount(account))
         throw new ApplicationException("The task does not belong to the account.");
     task.TaskList.RemoveTask(task);
     _repository.Delete(task);
 }
コード例 #2
0
        public CreateAccountResult CreateAccount(Account account)
        {
            CreateAccountResult result = new CreateAccountResult();

            if (_repository.ExistsForEmail(account.Email)) {
                result.Status = CreateAccountStatus.DuplicateEmail;
                result.Message = String.Format("An account already exists for '{0}'.", account.Email);
                return result;
            }

            // Assign created date.
            account.Created = DateTime.UtcNow;

            // Assign Central Standard Time if no timezone provided.
            if (String.IsNullOrEmpty(account.TimeZoneID))
                account.TimeZoneID = "Central Standard Time";

            // Save the new account.
            _repository.Save(account);

            // Initialize inbox.
            TaskList inbox = new TaskList { Title = "Inbox", TaskListType = TaskListType.Inbox };
            _taskListService.CreateTaskList(inbox, account);
            account.Inbox = inbox;

            // Create sample task and add to inbox.
            Task task = new Task { Title = "Welcome to Hover Tasks!", Note = "Get started by adding tasks, organizing them with lists and areas, and categorizing them with tags." };
            account.Inbox.AddTask(task);
            _taskService.CreateTask(task, account);
            
            return result;
        }
コード例 #3
0
 public void CanAddTask()
 {
     TaskList taskList = new TaskList();
     Task task = new Task();
     taskList.AddTask(task);
     Assert.AreEqual(1, taskList.Tasks.Count);
     Assert.AreNotEqual(null, task.TaskList);
 }
コード例 #4
0
 public TaskViewModel(Task task)
 {
     this.ID = task.ID;
     this.TaskListID = task.TaskList != null ? task.TaskList.ID : 0;
     this.TaskListTitle = task.TaskList != null ? task.TaskList.Title : String.Empty;
     this.TaskListIsInbox = task.TaskList != null ? task.TaskList.TaskListType == TaskListType.Inbox : false;
     this.Title = task.Title;
     this.Important = task.Important;
     this.Due = task.Due;
     this.Done = task.Done;
     this.Note = task.Note;
     this.SortOrder = task.TaskList != null ? task.TaskList.Tasks.IndexOf(task) : 0;
     this.Tags = new List<TagViewModel>();
     foreach (Tag tag in task.Tags) {
         TagViewModel t = new TagViewModel(tag);
         this.Tags.Add(t);
     }
 }
コード例 #5
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));
        }
コード例 #6
0
ファイル: TaskService.cs プロジェクト: kevinswarner/Hover_OLD
 public void CreateTask(Task task, Account account)
 {
     task.Account = account;
     _repository.Save(task);
 }
コード例 #7
0
ファイル: TaskList.cs プロジェクト: kevinswarner/Hover_OLD
 public virtual void RemoveTask(Task task)
 {
     task.TaskList = null;
     this.Tasks.Remove(task);
 }
コード例 #8
0
ファイル: TaskList.cs プロジェクト: kevinswarner/Hover_OLD
 public virtual void AddTask(Task task)
 {
     task.TaskList = this;
     this.Tasks.Add(task);
 }
コード例 #9
0
        public void InitializeGettingStarted(Account account)
        {
            // Get account.
            Account gettingStarted = GetByEmail("*****@*****.**");
            
            // Only process if found.
            if (gettingStarted != null && account.Email != "*****@*****.**") {

                // Tags.
                Dictionary<string, Tag> tags = new Dictionary<string, Tag>();
                foreach (Tag existingTag in _tagService.AllForAccount(gettingStarted)) {

                    // Create tag.
                    Tag tag = new Tag { Title = existingTag.Title };
                    _tagService.CreateTag(tag, account);

                    // Store in dictionary.
                    tags.Add(tag.Title, tag);

                }

                // Areas.
                foreach (Area existingArea in gettingStarted.Areas) {

                    // Create area.
                    Area area = new Area { Title = existingArea.Title };
                    account.AddArea(area);
                    _areaService.CreateArea(area, account);

                    // Lists.
                    foreach (TaskList existingList in existingArea.TaskLists) {

                        // Create list.
                        TaskList list = new TaskList {
                            DueListType = existingList.DueListType,
                            TaskListType = existingList.TaskListType,
                            Title = existingList.Title
                        };
                        area.AddTaskList(list);
                        _taskListService.CreateTaskList(list, account);

                        // Tasks
                        foreach (Task existingTask in existingList.Tasks) {

                            // Create task.
                            Task task = new Task {
                                Title = existingTask.Title,
                                Due = existingTask.Due,
                                Important = existingTask.Important,
                                Note = existingTask.Note,
                            };
                            list.AddTask(task);
                            _taskService.CreateTask(task, account);

                            // Assign tags.
                            foreach (Tag assignedTag in existingTask.Tags) {

                                // Find tag by title.
                                if (tags.ContainsKey(assignedTag.Title)) {
                                    Tag tag = tags[assignedTag.Title];
                                    task.Tags.Add(tag);
                                }

                            }
                        }
                    }
                }
            }
        }