Пример #1
0
 public void Delete(Tag tag, Account account)
 {
     if (tag.Account.ID != account.ID)
         throw new ApplicationException("The tag does not belong to the account.");
     foreach (Task task in _taskService.AllForTag(tag, account))
         task.Tags.Remove(tag);
     _repository.Delete(tag);
 }
Пример #2
0
 public TagViewModel(Tag tag, IList<Task> tasks)
     : this(tag)
 {
     foreach (Task task in tasks) {
         TaskViewModel t = new TaskViewModel(task);
         this.Tasks.Add(t);
     }
 }
Пример #3
0
 public ActionResult Create(TagViewModel model)
 {
     Account account = _accountService.LoadByEmail(User.Identity.Name);
     Tag tag = new Tag();
     tag.Title = model.Title;
     _tagService.CreateTag(tag, account);
     model = new TagViewModel(tag);
     return Content(JsonUtils.SerializeObject(model));
 }
Пример #4
0
 public void CanDetermineIfTagBelongsToAccount()
 {
     Account account1 = new Account();
     account1.ID = 1;
     Account account2 = new Account();
     account2.ID = 2;
     Tag tag = new Tag();
     tag.Account = account1;
     Assert.IsTrue(tag.BelongsToAccount(account1), "BelongsToAccount is false.");
     Assert.IsFalse(tag.BelongsToAccount(account2), "BelongsToAccount is true.");
 }
Пример #5
0
 public TagViewModel(Tag tag)
 {
     this.ID = tag.ID;
     this.Title = tag.Title;
     this.Tasks = new List<TaskViewModel>();
 }
Пример #6
0
 public IList<Task> AllForTag(Tag tag, Account account)
 {
     if (!tag.BelongsToAccount(account))
         throw new ApplicationException("The tag does not belong to the account.");
     return _repository.AllForTag(tag);
 }
Пример #7
0
 public void TagHasValidDefaultValues()
 {
     Tag tag = new Tag();
     Assert.IsNull(tag.Account, "Account is not null.");
     Assert.AreEqual(null, tag.Title);
 }
Пример #8
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);
                                }

                            }
                        }
                    }
                }
            }
        }
Пример #9
0
 public void CreateTag(Tag tag, Account account)
 {
     tag.Account = account;
     _repository.Save(tag);
 }