Ejemplo n.º 1
0
        public ActionResult Index()
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Manage sheets.
            SheetViewModel model = new SheetViewModel();
            model.Sheets = Sheet.Stack(account.DashboardTitle, Url.Action("index", "home"));
            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 area quick links.
            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 tag quick links.
            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);
        }
Ejemplo n.º 2
0
        public ActionResult Update(AccountViewModel model)
        {
            // Get authenticated account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);

            try {

                // Get account being updated.
                Account acct = _accountService.Load(model.ID, account);

                // Update dashboard title.
                acct.DashboardTitle = model.DashboardTitle;

                // Update timezone.
                acct.TimeZoneID = model.TimeZoneID;

                // Update theme.
                if (model.CurrentTheme != acct.CurrentTheme) {

                    // Change theme.
                    acct.CurrentTheme = model.CurrentTheme;

                    // Save to cookie.
                    HttpCookie cookie = new HttpCookie("hover_tasks_theme", acct.CurrentTheme);
                    cookie.Expires = DateTime.Now.AddYears(1);
                    Response.SetCookie(cookie);

                }
                
                // Change email address if different.
                if (model.Email != acct.Email) {
                    
                    // Change email.
                    _accountService.ChangeEmail(acct, model.Email);
                    
                    // Set auth cookie.
                    FormsAuthentication.SetAuthCookie(model.Email, false);

                    // Write cookie to save email.
                    HttpCookie emailCookie = new HttpCookie(EMAIL_COOKIE_NAME, model.Email);
                    emailCookie.Expires = DateTime.Today.AddMonths(1);
                    Response.Cookies.Add(emailCookie);
                }

                // Check for new password.
                if (!String.IsNullOrEmpty(model.NewPassword)) {
                    acct.Password = model.NewPassword;
                }
                
                // Create view model and return.
                model = new AccountViewModel(acct);
                return Content(JsonUtils.SerializeObject(model));

            }
            catch (Exception ex) {
                Response.StatusCode = 500;
                return Content(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Update(AccountViewModel model)
        {
            // Get authenticated account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);

            // Get account being updated.
            Account acct = _accountService.Load(model.ID, account);

            // Update properties.
            acct.DashboardTitle = model.DashboardTitle;

            // Create view model and return.
            model = new AccountViewModel(acct);
            return Content(JsonUtils.SerializeObject(model));
        }
Ejemplo n.º 4
0
        public ActionResult Inbox(List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // 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("Inbox", Url.Action("inbox", "home"), defaultStack, model.Sheets);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

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

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

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

            // 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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public ActionResult Area(long id, List<Sheet> sheets)
        {
            // Get account.
            Account account = _accountService.LoadByEmail(User.Identity.Name);
            AccountViewModel accountViewModel = new AccountViewModel(account);
            ViewData["Account"] = JsonUtils.SerializeObject(accountViewModel);

            // Get area.
            Area area = _areaService.Load(id, account);

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

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

            // Check for replace sheet option.
            bool replaceSheet = Request.Params["option"] != null && Request.Params["option"] == "replace";
            if (replaceSheet)
                sheets.RemoveAt(sheets.Count - 1);

            // 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("area", "home", new { id = id }), defaultStack, model.Sheets);
            ViewData["Stack"] = JsonUtils.SerializeObject(model.Sheets);

            foreach (Sheet s in model.Sheets) {
                Logger.Debug(s.Title + " : " + s.Url);
            }

            // 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("Area", model);

        }