Пример #1
0
 public AreaViewModel(Area area)
 {
     this.ID = area.ID;
     this.Title = area.Title;
     this.Expanded = area.Expanded;
     this.TaskLists = new List<TaskListViewModel>();
 }
Пример #2
0
 public void AreaHasValidDefaultValues()
 {
     Area area = new Area();
     Assert.IsNull(area.Account, "Account is not null.");
     Assert.IsNull(area.Title, "Title is not null.");
     Assert.AreEqual(0, area.TaskLists.Count);
 }
Пример #3
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);
 }
Пример #4
0
 public void CanAddArea()
 {
     Account account = new Account();
     Area area = new Area();
     account.AddArea(area);
     Assert.AreEqual(1, account.Areas.Count);
     Assert.AreNotEqual(null, area.Account);
 }
Пример #5
0
 public ActionResult Create(AreaViewModel model)
 {
     Account account = _accountService.LoadByEmail(User.Identity.Name);
     Area area = new Area { Title = model.Title };
     account.AddArea(area);
     _areaService.CreateArea(area, account);
     model = new AreaViewModel(area, area.TaskLists);
     return Content(JsonUtils.SerializeObject(model));
 }
Пример #6
0
 public AreaViewModel(Area area, IList<TaskList> taskLists, bool includeTasks)
     : this(area)
 {
     foreach (TaskList taskList in taskLists) {
         if (taskList != null) {
             TaskListViewModel t = new TaskListViewModel(taskList, taskList.Tasks);
             this.TaskLists.Add(t);
         }
     }
 }
Пример #7
0
 public void CanDetermineIfAreaBelongsToAccount()
 {
     Account account1 = new Account();
     account1.ID = 1;
     Account account2 = new Account();
     account2.ID = 2;
     Area area = new Area();
     area.Account = account1;
     Assert.IsTrue(area.BelongsToAccount(account1), "BelongsToAccount is false.");
     Assert.IsFalse(area.BelongsToAccount(account2), "BelongsToAccount is true.");
 }
Пример #8
0
        public void Delete(Area area, Account account)
        {
            if (!area.BelongsToAccount(account))
                throw new ApplicationException("The area does not belong to the account.");

            // Delete all task lists in area.
            int startingIndex = area.TaskLists.Count - 1;
            for (int i = startingIndex; i > -1; i--) {
                TaskList taskList = area.TaskLists[i];
                _taskListService.Delete(taskList, account);
            }
            
            // Remove area from account.
            account.RemoveArea(area);

            // Delete the area.
            _repository.Delete(area);
        }
Пример #9
0
 public virtual void RemoveArea(Area area)
 {
     area.Account = null;
     this.Areas.Remove(area);
 }
Пример #10
0
 public virtual void AddArea(Area area)
 {
     area.Account = this;
     this.Areas.Add(area);
 }
Пример #11
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);
 }
Пример #12
0
        public ActionResult Due(List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Create an area model to hold "due" tasks.
            Area area = new Area();
            area.Title = "Due";

            // Create list of task lists to hold each due list.
            IList<TaskList> dueLists = new List<TaskList>();

            // Overdue.
            TaskList overdueList = _taskListService.GetDueList(DueListType.Overdue, false, account);
            dueLists.Add(overdueList);

            // Today.
            TaskList todayList = _taskListService.GetDueList(DueListType.Today, false, account);
            dueLists.Add(todayList);

            // Tomorrow.
            TaskList tomorrowList = _taskListService.GetDueList(DueListType.Tomorrow, false, account);
            dueLists.Add(tomorrowList);

            // This week.
            TaskList thisWeekList = _taskListService.GetDueList(DueListType.ThisWeek, false, account);
            dueLists.Add(thisWeekList);

            // Next week.
            TaskList nextWeekList = _taskListService.GetDueList(DueListType.NextWeek, false, account);
            dueLists.Add(nextWeekList);

            // Later
            TaskList laterList = _taskListService.GetDueList(DueListType.Later, false, account);
            dueLists.Add(laterList);

            // Create an area view model with task lists and tasks.
            AreaViewModel areaViewModel = new AreaViewModel(area, dueLists, true);

            // Pass area view model to view.
            ViewData["Area"] = JsonUtils.SerializeObject(areaViewModel);

            // 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("Due", Url.Action("due", "home"), 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 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);
        }
Пример #13
0
        public ActionResult All(List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Create an area model to hold "all" task lists.
            Area area = new Area();
            area.Title = "All";

            // Create an area view model with task lists and tasks.
            AreaViewModel areaViewModel = new AreaViewModel(area, account.GetTaskLists(true), true);

            // Pass area view model to view.
            ViewData["Area"] = JsonUtils.SerializeObject(areaViewModel);

            // 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(area.Title, Url.Action("all", "home"), 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 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);
        }
Пример #14
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);
                                }

                            }
                        }
                    }
                }
            }
        }
Пример #15
0
 public void CreateArea(Area area, Account account)
 {
     area.Account = account;
     _repository.Save(area);
 }