// GET: AddTodoItem/Edit/5 public async Task <ActionResult> Edit(string listId, string itemId) { ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string); var item = await toDoItemService.GetItemInfoByItemId(itemId); AddTodoItemModel addTodoItemModel = new AddTodoItemModel(); addTodoItemModel.Id = item.Id; addTodoItemModel.IsCompleted = item.IsCompleted; addTodoItemModel.Text = item.Text; addTodoItemModel.TodoListId = item.TodoListId; ViewBag.ListId = listId; if (await AccessAdmin(listId)) { return(View(addTodoItemModel)); } else if (await AccessEditor(listId)) { return(View(addTodoItemModel)); } else { return(View("AccessDenied")); } }
public async Task <ActionResult> Create(string listId, AddTodoItemModel addTodoItemModel) { DTO.ToDoItem toDoItem = new ToDoItem(); toDoItem.Id = Guid.NewGuid().ToString(); toDoItem.Text = addTodoItemModel.Text; toDoItem.IsCompleted = false; toDoItem.IsDeleted = false; toDoItem.CreatedDateTime = DateTime.Now; toDoItem.Deadline = DateTime.Now.AddYears(100); toDoItem.TodoListId = listId; ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string); try { // TODO: Add insert logic here await toDoItemService.InsertTodoItem(toDoItem); return(RedirectToAction("Index", new { listId })); } catch { return(View()); } }
public async Task <bool> AddItemAsync(AddTodoItemModel newItemModel, IdentityUser user) { var newItem = new TodoItemModel { Id = Guid.NewGuid(), IsDone = false, Title = newItemModel.Title, DueAt = DateTimeOffset.Now.AddDays(newItemModel.DaysUntil), UserId = user.Id }; await _context.Items.AddAsync(newItem); var result = await _context.SaveChangesAsync(); return(result == 1); }
public async Task <IActionResult> AddItem(AddTodoItemModel newItemModel) { if (!ModelState.IsValid) { return(RedirectToAction("Index")); } var user = await _userManager.GetUserAsync(User); var successful = await _todoItemService.AddItemAsync(newItemModel, user); if (!successful) { return(BadRequest("Could not add item.")); } return(RedirectToAction("Index")); }
public async Task <ActionResult> Delete(string listId, string itemId, AddTodoItemModel addTodoItemModel) { try { // TODO: Add delete logic here ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string); DTO.ToDoItem tdItem = await toDoItemService.GetItemInfoByItemId(itemId); tdItem.IsDeleted = true; await toDoItemService.UpdateTodoItem(tdItem); return(RedirectToAction("Index", new { listId })); } catch { return(View()); } }
public async Task <ActionResult> Edit(string listId, string itemId, AddTodoItemModel addTodoItemModel) { try { string accessToken = Session["MicrosoftAccessToken"] as string; ToDoItemService toDoItemService = new ToDoItemService(accessToken); // TODO: Add update logic here DTO.ToDoItem tdItem = await toDoItemService.GetItemInfoByItemId(itemId); //tdItem.Id = itemId; tdItem.Text = addTodoItemModel.Text; tdItem.IsCompleted = addTodoItemModel.IsCompleted; //tdItem.IsDeleted = false; //tdItem.TodoListId = listId; //ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string); await toDoItemService.UpdateTodoItem(tdItem); var allListItems = await toDoItemService.GetTodoListsItems(listId); if (allListItems.All(i => i.IsCompleted)) { var todoListService = new ToDoListService(accessToken); var list = await todoListService.GetListById(listId); list.IsCompleted = true; await todoListService.UpdateTodoList(list); } ViewBag.ListId = listId; //ViewBag.ItemId = itemId; return(RedirectToAction("Index", new { listId })); } catch { return(View()); } }
public Task <bool> AddItemAsync(AddTodoItemModel newItemModel, IdentityUser user) { throw new NotImplementedException(); }