示例#1
0
 public void CanAuthenticate()
 {
     Account account = new Account();
     account.Password = "******";
     Assert.IsTrue(account.Authenticate("APPLES"));
     Assert.IsFalse(account.Authenticate("BAD PASSWORD"));
 }
示例#2
0
 public Area Load(long id, Account account)
 {
     Area area = _repository.Load(id);
     if (!area.BelongsToAccount(account))
         throw new ApplicationException("The area does not belong to the account.");
     return area;
 }
示例#3
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;
        }
示例#4
0
 public Account Load(long id, Account account)
 {
     Account acct = _repository.Load(id);
     if (acct.ID != account.ID)
         throw new ApplicationException("The account being loaded does not match the current authenticated account.");
     return acct;
 }
示例#5
0
 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);
 }
示例#6
0
 public Task Load(long id, Account account)
 {
     Task task = _repository.Load(id);
     if (!task.BelongsToAccount(account))
         throw new ApplicationException("The task does not belong to the account.");
     return task;
 }
示例#7
0
 public Tag Load(long id, Account account)
 {
     Tag tag = _repository.Load(id);
     if (tag.Account.ID != account.ID)
         throw new ApplicationException("The tag does not belong to the account.");
     return tag;
 }
示例#8
0
 public void EntityBaseHasValidDefaultValues()
 {
     Account entity = new Account();
     Assert.AreEqual(0, entity.ID);
     Assert.IsNull(entity.Created, "Created is not null.");
     Assert.IsNull(entity.Updated, "Updated is not null.");
 }
 public AccountViewModel(Account account)
 {
     this.ID = account.ID;
     this.Email = account.Email;
     this.TimeZoneID = account.TimeZoneID;
     this.DashboardTitle = account.DashboardTitle;
 }
示例#10
0
 public void PasswordIsHashedWhenAssignedThroughProperty()
 {
     Account account = new Account();
     Assert.AreEqual(null, account.HashedPassword);
     account.Password = "******";
     Assert.AreNotEqual(null, account.HashedPassword);
     Assert.AreNotEqual("APPLES", account.HashedPassword);
 }
示例#11
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);
 }
示例#12
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);
 }
示例#13
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);
 }
示例#14
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.");
 }
示例#15
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.");
 }
示例#16
0
 public void AccountHasValidDefaultValues()
 {
     Account account = new Account();
     Assert.AreEqual(null, account.Email);
     Assert.AreEqual(null, account.HashedPassword);
     Assert.AreEqual(AccountStatus.Active, account.Status);
     Assert.AreEqual(null, account.CurrentTheme);
     Assert.AreEqual(null, account.TimeZoneID);
     Assert.AreEqual(null, account.Inbox);
     Assert.AreEqual(0, account.Areas.Count);
     Assert.AreEqual("Dashboard", account.DashboardTitle);
 }
示例#17
0
        public IList<Task> DueToday(Account account)
        {
            // Get tasks due today. Sorted by due date by default.
            IList<Task> tasks = _repository.DueToday(account);

            // Reorder by area, then tasklist, then task.
            var reordered = tasks
                .OrderBy(t => t.TaskList.TaskListType == TaskListType.Inbox ? -1 : t.TaskList.Area.Account.Areas.IndexOf(t.TaskList.Area))
                .ThenBy(t => t.TaskList.TaskListType == TaskListType.Inbox ? -1 : t.TaskList.Area.TaskLists.IndexOf(t.TaskList))
                .ThenBy(t => t.TaskList.Tasks.IndexOf(t)).ToList<Task>(); 
            
            // Return.
            return reordered;
        }
示例#18
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);
        }
示例#19
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;
        }
示例#20
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;
        }
示例#21
0
        public IList<Task> DueThisWeek(Account account, bool afterTomorrow)
        {
            // Get today.
            var todayUTC = TimeZoneUtils.GetUtcToday(account.TimeZoneID);

            // Get the first and last days of the current week.
            var first = todayUTC.FirstDateTimeOfWeek(DayOfWeek.Monday);
            var last = todayUTC.GetDateTimeForDayOfWeek(DayOfWeek.Sunday, DayOfWeek.Monday);

            // Adjust for after tomorrow option.
            if (afterTomorrow) {
                var dayAfterTomorrow = todayUTC.AddDays(2);
                first = dayAfterTomorrow;
            }

            // Return tasks during this period.
            return _repository.DueWithin(account, first, last);
        }
示例#22
0
 public IList<Task> DueTomorrow(Account account)
 {
     return _repository.DueTomorrow(account);
 }
示例#23
0
 public IList<Task> DueToday(Account account)
 {
     return _repository.DueToday(account);
 }
示例#24
0
 public IList<Task> Overdue(Account account)
 {
     return _repository.Overdue(account);
 }
示例#25
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);
 }
示例#26
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);
 }
示例#27
0
 public IList<Task> AllForAccount(Account account)
 {
     return _repository.AllForAccount(account);
 }
示例#28
0
 public ActionResult SignUp(SignUpViewModel model)
 {
     if (ModelState.IsValid) {
         Account account = new Account();
         account.Email = model.Email;
         account.Password = model.Password;
         account.CurrentTheme = Account.DefaultTheme;
         CreateAccountResult result = _accountService.CreateAccount(account);
         if (result.Status == CreateAccountStatus.Success) {
             FormsAuthentication.SetAuthCookie(account.Email, false);
             UpdateCurrentTheme(model.Email);
             return JsonRedirect(Url.Action("index", "home"));
         }
         else {
             model.TimeZonesList = TimeZoneUtils.GetTimeZonesSelectList();
             model.Message = result.Message;
         }
     }
     return JsonContent("#sign-in-form-panel", RenderPartialViewToString("_SignUpForm", model));
 }
示例#29
0
 public virtual bool BelongsToAccount(Account account)
 {
     return account.ID == Account.ID;
 }
示例#30
0
 public IList<Task> Important(Account account)
 {
     return _repository.Important(account);
 }