Пример #1
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;
        }
Пример #2
0
 public void CanAddTaskList()
 {
     Area area = new Area();
     TaskList taskList = new TaskList();
     area.AddTaskList(taskList);
     Assert.AreEqual(1, area.TaskLists.Count);
     Assert.AreNotEqual(null, taskList.Area);
 }
Пример #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 void Delete(TaskList taskList, Account account)
 {
     if (!taskList.BelongsToAccount(account))
         throw new ApplicationException("The task list does not belong to the account.");
     _taskService.DeleteForTaskList(taskList, account);
     taskList.Area.RemoveTaskList(taskList);
     _repository.Delete(taskList);
 }
Пример #5
0
 public void TaskListHasValidDefaultValues()
 {
     TaskList list = new TaskList();
     Assert.IsNull(list.Account, "Account is not null.");
     Assert.IsNull(list.Area, "Area is not null.");
     Assert.IsNull(list.Title, "Title is not null.");
     Assert.AreEqual(TaskListType.Normal, list.TaskListType);
     Assert.AreEqual(0, list.Tasks.Count);
 }
Пример #6
0
 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);
         }
     }
 }
Пример #7
0
 public ActionResult Create(TaskListViewModel model)
 {
     Account account = _accountService.LoadByEmail(User.Identity.Name);
     Area area = _areaService.Load(model.AreaID, account);
     TaskList taskList = new TaskList { Title = model.Title };
     area.AddTaskList(taskList);
     _taskListService.CreateTaskList(taskList, account);
     model = new TaskListViewModel(taskList);
     return Content(JsonUtils.SerializeObject(model));
 }
Пример #8
0
 public void CanDetermineIfTaskListBelongsToAccount()
 {
     Account account1 = new Account();
     account1.ID = 1;
     Account account2 = new Account();
     account2.ID = 2;
     TaskList taskList = new TaskList();
     taskList.Account = account1;
     Assert.IsTrue(taskList.BelongsToAccount(account1), "BelongsToAccount is false.");
     Assert.IsFalse(taskList.BelongsToAccount(account2), "BelongsToAccount is true.");
 }
Пример #9
0
 public void TaskListHasValidDefaultValues()
 {
     TaskList list = new TaskList();
     Assert.IsNull(list.Account, "Account is not null.");
     Assert.IsNull(list.Area, "Area is not null.");
     Assert.IsNull(list.Title, "Title is not null.");
     Assert.AreEqual(TaskListType.Normal, list.TaskListType);
     Assert.AreEqual(false, list.Favorite);
     Assert.IsTrue(list.Expanded, "Expanded is false.");
     Assert.AreEqual(0, list.Tasks.Count);
 }
Пример #10
0
 public TaskListViewModel(TaskList taskList)
 {
     this.ID = taskList.ID;
     this.AreaID = taskList.Area != null ? taskList.Area.ID : 0;
     this.AreaTitle = taskList.Area != null ? taskList.Area.Title : String.Empty;
     this.Title = taskList.Title;
     this.TaskListType = taskList.TaskListType;
     this.DueListType = taskList.DueListType;
     this.Favorite = taskList.Favorite;
     this.Expanded = taskList.Expanded;
     this.Tasks = new List<TaskViewModel>();
 }
Пример #11
0
        public void CanReorderTasksBasedOnNewOrderOfTaskIDs()
        {
            TaskList taskList = new TaskList();
            for (long i = 1; i < 11; i++)
                taskList.Tasks.Add(new Task { ID = i, Title = "Task " + i.ToString() });
            
            Assert.AreEqual(10, taskList.Tasks.Count);
            Assert.AreEqual("Task 1", taskList.Tasks[0].Title);
            Assert.AreEqual("Task 10", taskList.Tasks[9].Title);

            long[] taskIDs = new long[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };

            taskList.ReorderTasks(taskIDs);

            Assert.AreEqual(10, taskList.Tasks.Count);
            Assert.AreEqual("Task 10", taskList.Tasks[0].Title);
            Assert.AreEqual("Task 1", taskList.Tasks[9].Title);
        }
Пример #12
0
        public TaskList GetDueList(DueListType dueListType, bool singleListView, Account account)
        {
            TaskList dueList = new TaskList();
            switch (dueListType) {
                case DueListType.Overdue:
                    dueList.ID = -1;
                    dueList.Title = "Overdue";
                    dueList.DueListType = DueListType.Overdue;
                    dueList.Tasks = _taskService.Overdue(account);
                    break;
                case DueListType.Today:

                    dueList.ID = -2;
                    dueList.Title = "Today";
                    dueList.DueListType = DueListType.Today;
                    dueList.Tasks = _taskService.DueToday(account);
                    break;
                case DueListType.Tomorrow:
                    dueList.ID = -3;
                    dueList.Title = "Tomorrow";
                    dueList.DueListType = DueListType.Tomorrow;
                    dueList.Tasks = _taskService.DueTomorrow(account);
                    break;
                case DueListType.ThisWeek:
                    dueList.ID = -4;
                    dueList.Title = "This week";
                    dueList.DueListType = DueListType.ThisWeek;
                    dueList.Tasks = _taskService.DueThisWeek(account, !singleListView);
                    break;
                case DueListType.NextWeek:
                    dueList.ID = -5;
                    dueList.Title = "Next week";
                    dueList.DueListType = DueListType.NextWeek;
                    dueList.Tasks = _taskService.DueNextWeek(account, !singleListView);
                    break;
                case DueListType.Later:
                    dueList.ID = -6;
                    dueList.Title = "Later";
                    dueList.DueListType = DueListType.Later;
                    dueList.Tasks = _taskService.DueLater(account);
                    break;
            }
            return dueList;
        }
Пример #13
0
        public CreateAccountResult CreateAccount(Account account)
        {
            CreateAccountResult result = new CreateAccountResult();

            // Check for existing account.
            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";

            // Assign default theme.
            account.CurrentTheme = Account.DefaultTheme;

            // 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;

            // Intialize with "getting started" area.
            InitializeGettingStarted(account);
            
            // Create mail message.
            MailMessage message = new MailMessage();
            message.To.Add(account.Email);
            message.Subject = "Welcome to Hover Tasks";
            message.Body = "Your Hover Tasks Beta account has been created. We are looking forward to your feedback. Thanks! --The Hover Team";

            // Send email.
            SmtpClient client = new SmtpClient();
            client.Send(message);
            
            return result;
        }
Пример #14
0
        public void ReorderingListPutsCompletedTasksAtEnd()
        {
            TaskList taskList = new TaskList();
            for (long i = 1; i < 11; i++)
                taskList.Tasks.Add(new Task { ID = i, Title = "Task " + i.ToString() });

            taskList.Tasks.Last().Done = true;

            Assert.AreEqual(10, taskList.Tasks.Count);
            Assert.AreEqual("Task 1", taskList.Tasks[0].Title);
            Assert.AreEqual("Task 10", taskList.Tasks[9].Title);

            long[] taskIDs = new long[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 };

            taskList.ReorderTasks(taskIDs);

            Assert.AreEqual(10, taskList.Tasks.Count);
            Assert.AreEqual("Task 9", taskList.Tasks[0].Title);
            Assert.AreEqual("Task 10", taskList.Tasks[9].Title);
        }
Пример #15
0
 public void CanGetTaskLists()
 {
     Account account = new Account();
     account.Inbox = new TaskList();
     Area area1 = new Area { ID = 2001 };
     TaskList list1 = new TaskList { ID = 1001 };
     TaskList list2 = new TaskList { ID = 1002 };
     TaskList list3 = new TaskList { ID = 1003 };
     area1.AddTaskList(list1);
     area1.AddTaskList(list2);
     area1.AddTaskList(list3);
     account.AddArea(area1);
     IList<TaskList> taskLists = account.GetTaskLists(false);
     Assert.AreEqual(3, taskLists.Count);
 }
Пример #16
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);
                                }

                            }
                        }
                    }
                }
            }
        }
Пример #17
0
        public ActionResult Search(List<Sheet> sheets, string searchFor)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Create a task list model to hold "important" tasks.
            TaskList taskList = new TaskList();
            taskList.Title = String.Format("Search Results for '{0}'", searchFor);

            // Find matching tasks.
            IList<Task> tasks = _taskService.Find(searchFor, account);
            
            // Create a task list view model with tasks.
            TaskListViewModel taskListViewModel = new TaskListViewModel(taskList, tasks);

            // Pass task list view model to view.
            ViewData["TaskList"] = JsonUtils.SerializeObject(taskListViewModel);
            
            // Pass search text to view.
            ViewData["SearchText"] = searchFor;
            
            // Manage sheets.
            // NOTE: We always use the default stack for the search results page.
            // ALSO: The url needs to include the search query paramater.
            var url = Url.Action("search", "home") + "/?searchfor=" + searchFor;
            Queue<Sheet> defaultStack = new Queue<Sheet>();
            defaultStack.Enqueue(new Sheet() { Title = account.DashboardTitle, Url = Url.Action("index", "home") });
            SheetViewModel model = new SheetViewModel(sheets);
            model.Sheets = Sheet.Stack("Search Results", url, defaultStack);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

            // Pass inbox to view.
            ViewData["Inbox"] = JsonUtils.SerializeObject(new TaskListViewModel(account.Inbox));

            // Create collection of area view models for the task list menu.
            IList<AreaViewModel> areas = new List<AreaViewModel>();
            foreach (Area ar in account.Areas)
                areas.Add(new AreaViewModel(ar, ar.TaskLists));
            ViewData["Areas"] = JsonUtils.SerializeObject(areas);

            // Create collection of tag view models for the tags menu.
            IList<TagViewModel> tags = new List<TagViewModel>();
            foreach (Tag tag in _tagService.AllForAccount(account))
                tags.Add(new TagViewModel(tag));
            ViewData["Tags"] = JsonUtils.SerializeObject(tags);

            // Return view.
            return View(model);
        }
Пример #18
0
 public IList<Task> AllForTaskList(TaskList taskList, Account account)
 {
     if (!taskList.BelongsToAccount(account))
         throw new ApplicationException("The task list does not belong to the account.");
     return _repository.AllForTaskList(taskList);
 }
Пример #19
0
        public ActionResult Later(List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Create a task list model to hold tasks due "later".
            TaskList taskList = new TaskList();
            taskList.Title = "Later";
            taskList.DueListType = Model.Domain.DueListType.Later;

            // Get tasks.
            IList<Task> tasks = _taskService.DueLater(account);

            // Create a task list view model with tasks.
            TaskListViewModel taskListViewModel = new TaskListViewModel(taskList, tasks);

            // Pass task list view model to view.
            ViewData["TaskList"] = JsonUtils.SerializeObject(taskListViewModel);

            // Manage sheets.
            Queue<Sheet> defaultStack = new Queue<Sheet>();
            defaultStack.Enqueue(new Sheet() { Title = account.DashboardTitle, Url = Url.Action("index", "home") });
            SheetViewModel model = new SheetViewModel(sheets);
            model.Sheets = Sheet.Stack("Later", Url.Action("later", "task"), defaultStack, model.Sheets);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

            // Pass inbox to view.
            ViewData["Inbox"] = JsonUtils.SerializeObject(new TaskListViewModel(account.Inbox));

            // Create collection of area view models for the task list menu.
            IList<AreaViewModel> areas = new List<AreaViewModel>();
            foreach (Area area in account.Areas)
                areas.Add(new AreaViewModel(area, area.TaskLists));
            ViewData["Areas"] = JsonUtils.SerializeObject(areas);

            // Create collection of tag view models for the tags menu.
            IList<TagViewModel> tags = new List<TagViewModel>();
            foreach (Tag tag in _tagService.AllForAccount(account))
                tags.Add(new TagViewModel(tag));
            ViewData["Tags"] = JsonUtils.SerializeObject(tags);

            // Return view.
            return View(model);
        }
Пример #20
0
 public void CreateTaskList(TaskList taskList, Account account)
 {
     taskList.Account = account;
     _repository.Save(taskList);
 }
Пример #21
0
 public virtual void AddTaskList(TaskList taskList)
 {
     taskList.Area = this;
     this.TaskLists.Add(taskList);
 }
Пример #22
0
 public virtual void RemoveTaskList(TaskList taskList)
 {
     taskList.Area = null;
     this.TaskLists.Remove(taskList);
 }