public async Task <ActionResult> Create(AddTodoListModel addTodoListModel) { DTO.ToDoList toDoList = new ToDoList(); toDoList.Id = Guid.NewGuid().ToString(); toDoList.ListName = addTodoListModel.ListName; toDoList.GroupId = addTodoListModel.GroupId; toDoList.IsCompleted = false; ToDoListService todoListService = new ToDoListService(Session["MicrosoftAccessToken"] as string); UserService userService = new UserService(Session["MicrosoftAccessToken"] as string); var usrId = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft); try { // TODO: Add insert logic here await todoListService.InsertTodoList(toDoList, usrId); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <ActionResult> Delete(string listId, AddTodoListModel addTodoListModel) { try { ToDoListService toDoList = new ToDoListService(Session["MicrosoftAccessToken"] as string); UserService userService = new UserService(Session["MicrosoftAccessToken"] as string); var userId = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft); DTO.ToDoList tdList = await toDoList.GetUserListById(addTodoListModel.ListId, userId); tdList.IsDeleted = true; await toDoList.UpdateTodoList(tdList); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <ActionResult> Edit(string listId, AddTodoListModel addTodoListModel) { try { // TODO: Add update logic here DTO.ToDoList tdList = new ToDoList(); tdList.Id = listId; tdList.GroupId = addTodoListModel.GroupId; tdList.ListName = addTodoListModel.ListName; tdList.IsCompleted = addTodoListModel.IsCompleted; ToDoListService toDoList = new ToDoListService(Session["MicrosoftAccessToken"] as string); await toDoList.UpdateTodoList(tdList); return(RedirectToAction("Index")); } catch { return(View()); } }
// GET: AddTodoList/Edit/5 public async Task <ActionResult> Edit(string listId) { UserService userService = new UserService(Session["MicrosoftAccessToken"] as string); var userId = await userService.GetUserId(Session["UserId"] as string, UserDomainEnum.Microsoft); ToDoListService toDoListService = new ToDoListService(Session["MicrosoftAccessToken"] as string); var listByListId = await toDoListService.GetUserListById(listId, userId); var usrGroups = await toDoListService.GetGroupForUser(Session["UserId"] as string); //var defaultGroup = usrGroups.SingleOrDefault(g => g.GroupName.Contains("Default group for user:"******"MicrosoftAccessToken"] as string, listByListId.GroupId); ViewBag.GroupID = new SelectList(usrGroups, "Id", "GroupNameTruncated", listByListId.GroupId); string groupId = listByListId.GroupId; AddTodoListModel addTodoListModel = new AddTodoListModel(); addTodoListModel.ListName = listByListId.ListName; addTodoListModel.IsCompleted = listByListId.IsCompleted; if (await AccessAdmin(userId, groupId)) { return(View(addTodoListModel)); } else if (await AccessEditor(userId, groupId)) { return(View(addTodoListModel)); } else { return(View("AccessDenied")); } }