Beispiel #1
0
        public ActionResult Create(TodoViewModel task)
        {
            if (ModelState.IsValid)
            {
                if (task != null)
                {
                    using (var db = new TodoContext())
                    {
                        try
                        {
                            db.TodoItems.Add(new TodoItem() { Description = task.Description, Title = task.Title, Done = false });
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            return RedirectToAction("Index", "Todo");
                        }
                    }

                    return RedirectToAction("Index", "Todo");
                }
            }

            return View(task);
        }
    private void AddTodo(object sender, EventArgs e)
    {
      var description = newTodoView.Text.Trim();
      if (String.IsNullOrEmpty(description) || todos == null) { return; }

      var item = new TodoItem {Description = description};
      try   { _dataContext.AddTodo(item); }
      catch { return; } //eat the error because logging it at lower level
      newTodoView.Text = String.Empty;
      var vm = new TodoViewModel(item);
      todos.Insert(0, vm);                    // front of the list
      todoGridAdapter.NotifyDataSetChanged(); // redraw   
    }
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Create the Breeze entity manager
            var serviceAddress = "http://localhost:63030/breeze/Todos/";
            //var serviceAddress = "http://sampleservice.breezejs.com/api/todos/";
            var assembly = typeof(TodoItem).Assembly;
            var rslt = Configuration.Instance.ProbeAssemblies(assembly);
            var entityManager = new EntityManager(serviceAddress);

            // Create the main viewModel and view
            _mainViewModel = new TodoViewModel(entityManager);
        }
		public TodoViewController ()
		{
			Title = "Todo Items";
			TableView.Source = DataSource = new ViewModelDataSource<TodoItem>{
				CellForItem = (tv,item)=>{
					var cell = tv.DequeueReusableCell<TodoItemCell>(TodoItemCell.Key);
					cell.Item = item;
					return cell;
				},
				ViewModel = (viewModel = new TodoViewModel()),
			};

			viewModel.ItemsChanged += (object sender, EventArgs e) => TableView.ReloadData();
		}
Beispiel #5
0
        public ActionResult Completed()
        {
            Guid userId = getUserId();

            List <TodoViewModel> todoModels = new List <TodoViewModel>();

            foreach (TodoItem completed in _repository.GetCompleted(userId))
            {
                TodoViewModel todoModel = new TodoViewModel();
                todoModel.DateCompleted = completed.DateCompleted;
                todoModel.Text          = completed.Text;
                todoModel.DateDueText   = generateDateText(completed.DateCompleted.Value);
                todoModel.Id            = completed.Id;
                todoModels.Add(todoModel);
            }

            return(View(todoModels));
        }
        public ActionResult Details(int id)
        {
            
            var todo = _context.ToDos.SingleOrDefault(t => t.ToDoId == id);

            if (todo == null)
                return HttpNotFound();

            var viewModel = new TodoViewModel
            {
                Todo = todo,
                TodoSnoozes = _context.TodoSnoozes.ToList()
            };

            //return View("CustomerForm", viewModel);
            return View("TodoForm", viewModel);            

        }
        // GET
        public async Task <IActionResult> Index()
        {
            var todoItems = await _context.TodoItems.ToListAsync();

            if (_feature.IsFeatureEnabled("FTD-002-Remove-item"))
            {
                foreach (var item in todoItems)
                {
                    item.Done = false;
                }
            }
            var model = new TodoViewModel()
            {
                Items = todoItems
            };

            return(View(model));
        }
Beispiel #8
0
        public async Task <IActionResult> Create([Bind("Id,Name,IsComplete")] TodoViewModel todoItemVM)
        {
            if (ModelState.IsValid)
            {
                var CurrentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var CurrentUser   = await _userManager.Users
                                    .Include(u => u.TodoItems)
                                    .SingleAsync(u => u.Id == CurrentUserId);

                TodoItem todoItem = _mapper.Map <TodoItem>(todoItemVM);

                CurrentUser.TodoItems.Add(todoItem);
                await _userManager.UpdateAsync(CurrentUser);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(todoItemVM));
        }
        public async Task <IActionResult> Index()
        {
            var currentUser = await userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var result = await todoItemService.GetInCompleteItemsAsync(currentUser);

            var viewModel = new TodoViewModel
            {
                Items = result.ToArray()
            };

            return(View(viewModel));
        }
        public IActionResult Edit(TodoViewModel todoViewModel)
        {
            var todoEntity = new Todos
            {
                Id             = todoViewModel.Id,
                UserId         = todoViewModel.UserId,
                Title          = todoViewModel.Title,
                Description    = todoViewModel.Description,
                DateAdded      = todoViewModel.DateAdded,
                DateToCommence = todoViewModel.DateToCommence
            };

            todoService.UpdateTodo(todoEntity);

            todoViewModel.SuccessMessage = "Successfully Updated Todo. Title: " + todoViewModel.Title;

            return(View(todoViewModel));
        }
        public async Task <IActionResult> Index()
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var todoItems = await _todoItemService.GetIncompleteItemsAsync(currentUser);

            var model = new TodoViewModel()
            {
                Items = todoItems
            };

            return(View(model));
        }
Beispiel #12
0
        public IActionResult Create(TodoViewModel newTodo)
        {
            if (ModelState.IsValid)
            {
                var todo = new Todo()
                {
                    Title = newTodo.Title, Text = newTodo.Text, FinishDate = newTodo.FinishDate, Priority = newTodo.Priority, Finished = newTodo.Finished
                };
                _context.Todos.Add(todo);
                _context.SaveChanges();

                return(RedirectToAction("List"));
            }
            else
            {
                return(BadRequest());
            }
        }
Beispiel #13
0
        public IActionResult Update(long id, TodoViewModel todoView)
        {
            if (ModelState.IsValid)
            {
                var todo = new Todo()
                {
                    Id = todoView.Id, Title = todoView.Title, Text = todoView.Text, FinishDate = todoView.FinishDate, Priority = todoView.Priority, Finished = todoView.Finished
                };
                _context.Todos.Update(todo);
                _context.SaveChanges();

                return(RedirectToAction("List"));
            }
            else
            {
                return(BadRequest());
            }
        }
Beispiel #14
0
        public async Task <IActionResult> Index()
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());                     // Validation check
            }
            // Get to-do items from database, put in view-model, pass to view and render
            var todoItems = await _todoItemService.GetIncompleteItemsAsync(currentUser);

            var model = new TodoViewModel()
            {
                Items = todoItems
            };

            return(View(model));
        }
        public IActionResult Create(TodoViewModel todoViewModel)
        {
            int?userId = HttpContext.Session.GetInt32(TodoConstants.UserIdKey);

            var todo = new Todos
            {
                UserId         = userId.Value,
                Title          = todoViewModel.Title,
                Description    = todoViewModel.Description,
                DateAdded      = todoViewModel.DateAdded,
                DateToCommence = todoViewModel.DateToCommence
            };

            todoService.CreateTodo(todo);

            todoViewModel.SuccessMessage = "Todo Created Successfully";

            return(View(todoViewModel));
        }
        public IActionResult GetTodos()
        {
            try
            {
                List <Todo>          todos     = TaskQuery.GetTodos();
                List <TodoViewModel> todoViews = new List <TodoViewModel>();
                foreach (Todo todo in todos)
                {
                    TodoViewModel todoViewModel = new TodoViewModel(todo.Id, todo.TaskName, TaskPropertiesConverter.ConvertPriorityToString(todo));
                    todoViews.Add(todoViewModel);
                }

                return(Ok(todoViews));
            }
            catch (Exception exception)
            {
                return(Problem(exception.Message));
            }
        }
        public ActionResult Index()
        {
            var userId      = User.Identity.GetUserId();
            var userProfile = _context.UserProfiles.FirstOrDefault(x => x.Id == userId);

            if (userProfile != null)
            {
                TodoViewModel model = new TodoViewModel
                {
                    Todoes          = _context.Todoes.Where(x => x.UserProfileId == userId).ToList(),
                    ImportantEvents = _context.ImportantEvents.Where(x => x.UserProfileId == userId).ToList()
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Manage", "Profile"));
            }
        }
Beispiel #18
0
        public void SaveCommandNeedsSummary()
        {
            // Arrange
            var todo = new Todo {
                Summary = "summary", Details = "details"
            };
            var entry = new TodoViewModel(todo);
            var vm    = new EditEntryViewModel(entry);

            // Act
            bool withSummary = vm.SaveCommand.CanExecute(null);

            vm.Summary = string.Empty;
            bool withoutSummary = vm.SaveCommand.CanExecute(null);

            // Assert
            Assert.IsTrue(withSummary);
            Assert.IsFalse(withoutSummary);
        }
Beispiel #19
0
        private void DeleteItemsFromDatabase(TodoViewModel model)
        {
            // Get references
            var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>();

            foreach (TodoItem item in model.Items)
            {
                if (item.Complete == true)
                {
                    // Get the record that needs to be deleted
                    var x = (from n in context.TodoItems
                             where n.ID == item.ID
                             select n).First();

                    context.TodoItems.Remove(x);
                }
            }
            context.SaveChanges();
        }
Beispiel #20
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Title,Description")] Todo todo, List <Guid> TodoLabels)
        {
            if (ModelState.IsValid)
            {
                // If the Todo doesn't belong to our user
                Todo curTodo = _context.Todo.First(t => t.Id == id && t.User == GetCurrentUser().Result);
                if (curTodo == null)
                {
                    return(Unauthorized());
                }
                curTodo.Description          = todo.Description;
                curTodo.Title                = todo.Title;
                curTodo.LastModificationDate = DateTime.Now;
                curTodo.TodoLabels           = new List <TodoLabel>();
                foreach (Guid labelId in TodoLabels)
                {
                    TodoLabel tdl = new TodoLabel();
                    tdl.Todo      = curTodo;
                    tdl.LabelGuid = labelId;
                    curTodo.TodoLabels.Add(tdl);
                }
                try{
                    _context.Update(curTodo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException) {
                    if (!TodoExists(todo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            TodoViewModel tvm = new TodoViewModel();

            tvm.Todo   = todo;
            tvm.Labels = _context.Label.ToList();
            return(View(tvm));
        }
Beispiel #21
0
        public ActionResult Index(TodoViewModel model, string TodoItem)
        {
            var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>();

            // If a user is logged in, make changes to the database aswell as the local copy
            bool bUserLoggedIn = User.Identity.IsAuthenticated;

            // Are there any items that need to be deleted?
            if (bUserLoggedIn)
            {
                DeleteItemsFromDatabase(model);
            }

            // Remove completed items from local list
            model.Items.RemoveAll(item => item.Complete == true);

            // Add new items to list
            TodoItem newItem = new TodoItem {
                Task = TodoItem, Complete = false
            };

            if (TodoItem != "")
            {
                model.Items.Add(newItem);
            }

            // Save local copy of the list
            Session["TODO"] = model;

            if (bUserLoggedIn && TodoItem != "")
            {
                AddItemToDatabase(newItem);
            }

            // Copy values to new model & clear the viewmodel
            // This is done because there were issues with the ViewModel retaining its state between requests
            TodoViewModel newModel = model;

            ModelState.Clear();

            return(View(newModel));
        }
Beispiel #22
0
        public async Task <IActionResult> Index()
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }
            // Get to-do items from database
            var items = await _todoItemService.GetIncompleteItemsAsync(currentUser);

            // Put items into a model
            // Render view using the model
            TodoViewModel vm = new TodoViewModel()
            {
                Items = items
            };

            return(View(vm));
        }
        public async Task <IActionResult> Index(TodoViewModel todo = null)
        {
            //obtencion del usuario logeado
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge()); //fuerza el logeo, mostrando la pagina de logeo
            }
            currentUser = await ObtenerUsuarioSeleccionado(todo);

            var items = await _endedTodoItemService.GetCompletItemsAsync(currentUser);

            var model = new TodoViewModel()
            {
                Items = items
            };

            return(View(model));
        }
        public async Task <IActionResult> UserList(string Id)
        {
            var user = await _userManager.Users
                       .Where(x => x.Id == Id)
                       .SingleOrDefaultAsync();

            if (user == null)
            {
                return(BadRequest());
            }

            var todoItems = await _todoItemService.GetIncompleteItemsAsync(user);

            var viewModel = new TodoViewModel {
                Items = todoItems,
                User  = user
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> Index()
        {
            var CurrentUser = await _userManager.GetUserAsync(User);

            if (CurrentUser == null)
            {
                return(Challenge());
            }
            //Get to-do items from database
            var items = await _todoItemService.GetIncompleteItemsAsync(CurrentUser);

            //put items into a model
            var model = new TodoViewModel()
            {
                Items = items
            };

            // Render view using the model >> users can read and understand
            return(View(model));
        }
Beispiel #26
0
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(Challenge());
            }
            // 从数据库获取 to-do 条目
            var todoItems = await _todoItemService.GetIncompleteItemsAsync(user);

            // 把条目置于 model 中
            var model = new TodoViewModel()
            {
                Items = todoItems
            };

            // 使用 model 渲染视图
            return(View(model));
        }
Beispiel #27
0
        public async Task <TodoViewModel> Detalle(Guid id)
        {
            var result = new TodoViewModel();

            try
            {
                var _item = await _context.Todos
                            .Include(x => x.Usuario.Eps)
                            .FirstOrDefaultAsync(x => x.Id == id);

                result.Item            = TodoDto.ProyectarDto(_item);
                result.HabilitarEditar = true;
                result.HabilitarBorrar = true;
            }
            catch (Exception e)
            {
            }

            return(result);
        }
        // Index action method - display all to-do items
        public async Task <IActionResult> Index()
        {
            // look up the full user details in the database through GetUserAsync() method
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }

            var items = await _todoItemService.GetIncompleteItemsAsync(currentUser);

            // bind a list of items returned from GetIncompleteItemsAsync() method to TodoViewModel()
            var model = new TodoViewModel()
            {
                Items = items
            };

            return(View(model));
        }
Beispiel #29
0
        protected async Task <ApplicationUser> ObtenerUsuarioSeleccionado(TodoViewModel todo)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (await _userManager.IsInRoleAsync(currentUser, "Administrator"))
            {
                ObtenerListaUsuarios();

                //Current user se hace null para poder ver todos los Todo's.
                if (todo.Usuarios == null)
                {
                    currentUser = null;
                }
                else
                {
                    currentUser = await _userManager.FindByIdAsync(todo.Usuarios);
                }
            }
            return(currentUser);
        }
Beispiel #30
0
        public async Task <IActionResult> PutTodo(int id, [FromBody] TodoViewModel todoModel)
        {
            try
            {
                if (todoModel == null)
                {
                    logger.LogError("Todo object sent from client is null.");
                    return(BadRequest("Todo object is null"));
                }

                await todoAdapter.UpdateTodo(todoModel);

                return(Ok(todoModel));
            }
            catch (Exception ex)
            {
                logger.LogError($"Something went wrong inside PutTodo action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task <IActionResult> Index()
        {
            var currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }
            // Get to-do items from database
            var items = await _todoItemService.GetInCompleteItemsAsync(currentUser);

            // Put items into a model
            var model = new TodoViewModel()
            {
                Items = items
            };

            // Pass the view to a model and render
            return(View(model));
        }
Beispiel #32
0
        public IActionResult Index()
        {
            Guid            userId = new Guid(_userManager.GetUserId(User));
            IndexViewModel  models = new IndexViewModel();
            List <TodoItem> items  = _repository.GetActive(userId).OrderByDescending(i => i.DateCreated).ToList();

            foreach (TodoItem item in items.Where(i => i.DateDue.HasValue))
            {
                TodoViewModel model = new TodoViewModel(item.Id, item.Text, item.DateDue, item.IsCompleted);
                model.Labels = TodoViewModel.GetLabelsRaw(item.Labels);
                models.Add(model);
            }
            foreach (TodoItem item in items.Where(i => !i.DateDue.HasValue))
            {
                TodoViewModel model = new TodoViewModel(item.Id, item.Text, item.DateDue, item.IsCompleted);
                model.Labels = TodoViewModel.GetLabelsRaw(item.Labels);
                models.Add(model);
            }
            return(View(models));
        }
Beispiel #33
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            // Load Todo List from storage
            TodoViewModel.getInstance().LoadFromStorage();

            Frame rootFrame = Window.Current.Content as Frame;

            JsonObject args = new JsonObject();

            args.Add("Args", JsonValue.CreateStringValue(e.Arguments));

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Load state from previously suspended application
                    args.Add("MainAdaptiveState", JsonValue.CreateStringValue(ApplicationData.Current.LocalSettings.Values["MainAdaptiveState"] as string));
                    args.Add("EditingTodoData", JsonValue.CreateStringValue(ApplicationData.Current.LocalSettings.Values["EditingTodoData"] as string));
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), args.Stringify());
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Beispiel #34
0
        public void SaveOrUpdate(TodoViewModel todo)
        {
            if (todo.Id != 0)
            {
                var todoAux = _todoRepository.GetById(todo.Id);
                todoAux.Description = todo.Description;
                todoAux.Done        = todo.Done;
                _todoRepository.UpdateAndSave(todoAux);
            }
            else
            {
                var todoSave = new Todo()
                {
                    Description = todo.Description,
                    Done        = todo.Done,
                    CreatDate   = new DateTime()
                };

                _todoRepository.AddAndSave(todoSave);
            }
        }
Beispiel #35
0
        public ActionResult Detail(TodoViewModel task, string id)
        {
            using (var db = new TodoContext())
            {
                var item = db.TodoItems.Find(id);
                if (task != null)
                {
                    item.Done = task.Done;
                }

                db.SaveChanges();

                return RedirectToAction("Index", "Todo");
            }
        }
Beispiel #36
0
        public ActionResult Edit(TodoViewModel task, string id)
        {
            if (ModelState.IsValid)
            {
                using (var db = new TodoContext())
                {
                    try
                    {
                        var item = db.TodoItems.Find(id);
                        if (task != null)
                        {
                            item.Description = task.Description;
                            item.Title = task.Title;
                        }

                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        return RedirectToAction("Index", "Todo");
                    }
                }
            }

            return RedirectToAction("Index", "Todo");
        }