private ObservableCollection <ItemsViewModel> GetPlan() { var service = new ToDoListService(); var result = service.GetPlan(); return(result); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var toDoListService = new ToDoListService(Configuration); services.AddSingleton <IToDoListService>(toDoListService); //if (Configuration.GetValue<bool>("Services:EnableCache")) //{ // services.AddSingleton<IToDoListService>(new CacheService(toDoListService)); //} services.Configure <GetOptions>(Configuration.GetSection("GetOptions")); services.Configure <GetOptions>("SearchOptions", Configuration.GetSection("SearchOptions")); services.AddOptions <GetOptions>().Bind(Configuration.GetSection("GetOptions")).ValidateDataAnnotations(); services.AddControllers(); services.AddSwaggerGen(); services.AddSwaggerGen(c => { var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var xmlFiles = Directory.GetFiles(folder, "*.xml").ToList(); xmlFiles.ForEach(x => c.IncludeXmlComments(x)); }); }
private void AddTask() { var vm = new ItemsViewModel(); vm.WorkContent = inputText.Text; if (ListMenu.SelectedIndex == (int)MenuOptions.important) { vm.IsImportant = true; } if (ListMenu.SelectedIndex == (int)MenuOptions.planned) { vm.PlanedDate = DateTime.Now; } var service = new ToDoListService(); //存入資料庫 var result = service.AddTasks(vm); if (result.IsSuccessful) { //成功再改變畫面 var index = (MenuOptions)ListMenu.SelectedIndex; Show(index); } else { var path = result.WriteLog(); MessageBox.Show($"發生錯誤,請參考{path}"); } inputText.Text = string.Empty; }
public ToDoListController(ToDoListService toDoListService, UserService userService, IWriter writer, IReader reader) { _toDoListService = toDoListService; _userService = userService; _writer = writer; _reader = reader; }
public ToDoListsController() { var unitOfWork = IoCUtility.Resolve <IUnitOfWork <DbContext> >(); var repositoryFactory = IoCUtility.Resolve <IRepositoryFactory>(); _toDoListService = new ToDoListService(unitOfWork, repositoryFactory); }
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()); } }
private ObservableCollection <ItemsViewModel> GetMyday() { var service = new ToDoListService(); var dateString = DateTime.Now.ToString("yyyy-MM-dd"); var result = service.GetTaskList(dateString); return(result); }
public NotificationSender() { var unitOfWork = IoCUtility.Resolve <IUnitOfWork <DbContext> >("isolatedUnitOfWork"); var repositoryFactory = IoCUtility.Resolve <IRepositoryFactory>("isolatedRepositoryFactory"); _toDoListService = new ToDoListService(unitOfWork, repositoryFactory); _taskService = new TaskService(unitOfWork, repositoryFactory); }
private ObservableCollection <ItemsViewModel> GetTasks() { var service = new ToDoListService(); var dateString = string.Empty; var result = service.GetTaskList(dateString); return(result); }
public async void GetById_throwsIfdoesNotExist() { var mockedRepositoru = new Mock <IToDoListRepository>(); var userId = Guid.NewGuid(); var taskId = Guid.NewGuid(); mockedRepositoru.Setup(x => x.GetById(taskId)).Returns(Task.FromResult(null as ToDoTask)); var todoListService = new ToDoListService(mockedRepositoru.Object); await Assert.ThrowsAsync <Exception>(() => todoListService.GetById(userId, taskId)); }
// GET: AddTodoList/Create public async Task <ActionResult> Create() { ToDoListService toDoListService = new ToDoListService(Session["MicrosoftAccessToken"] as string); var usrGroups = await toDoListService.GetGroupForUser(Session["UserId"] as string); var defaultGroup = usrGroups.SingleOrDefault(g => g.GroupName.Contains("Default group for user:"******"Id", "GroupNameTruncated", defaultGroup.Id); return(View()); }
public void Create_throwsIfIdExists() { var mockedRepositoru = new Mock <IToDoListRepository>(); var userId = Guid.NewGuid(); var taskId = Guid.NewGuid(); mockedRepositoru.Setup(x => x.GetById(taskId)).Returns(Task.FromResult(new ToDoTask() { Id = taskId, UserId = userId })); var todoListService = new ToDoListService(mockedRepositoru.Object); Assert.ThrowsAsync <Exception>(() => todoListService.GetById(userId, taskId)); }
private async Task GetToDoListService() { try { toDoList = await ToDoListService.GetAsync(); } catch (Exception ex) { Console.WriteLine(ex.Message); // Process the exception from a user challenge ConsentHandler.HandleException(ex); } }
public async Task <bool> AccessAdmin(string groupId) { var accessToken = Session["MicrosoftAccessToken"] as string; ToDoListService toDoListService = new ToDoListService(accessToken); UserService userService = new UserService(accessToken); string userId = await userService.GetUserInternalId(Session["UserId"] as string, UserDomainEnum.Microsoft); RoleTypeService roleTypeService = new RoleTypeService(accessToken); return(await roleTypeService.CanUserAddOrDeleteItem(userId, groupId)); }
public async Task RemoveToDoItem_DoesNotExist() { using (var context = new ToDoListContext(ContextOptions)) { // arrange var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper); const int idToRemove = 4; // act var result = await toDoListService.RemoveToDoItem(idToRemove); // assert Assert.AreEqual(default, result);
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var toDoListService = new ToDoListService(Configuration); //services.AddSingleton<IToDoListService>(toDoListService); //if (Configuration.GetValue<bool>("Services:EnableCache")) //{ // services.AddSingleton<IToDoListService>(new CacheService(toDoListService)); //} services.Configure <GetOptions>(Configuration.GetSection("GetOptions")); services.AddControllers(); services.AddSwaggerGen(); }
public async Task <bool> AccessEditor(string listId) { var accessToken = Session["MicrosoftAccessToken"] as string; ToDoListService toDoListService = new ToDoListService(accessToken); string groupId = (await toDoListService.GetListById(listId)).GroupId; UserService userService = new UserService(accessToken); string userId = await userService.GetUserInternalId(Session["UserId"] as string, UserDomainEnum.Microsoft); RoleTypeService roleTypeService = new RoleTypeService(accessToken); return(await roleTypeService.CanUserEditItem(userId, groupId)); }
public async void Update_throwsIfWrongUser() { var mockedRepositoru = new Mock <IToDoListRepository>(); var userId = Guid.NewGuid(); var taskId = Guid.NewGuid(); mockedRepositoru.Setup(x => x.GetById(taskId)).Returns(Task.FromResult(new ToDoTask() { Id = taskId, UserId = Guid.NewGuid() })); var todoListService = new ToDoListService(mockedRepositoru.Object); await Assert.ThrowsAsync <Exception>(() => todoListService.UpdateTask(new UpdateToDoTask { UserId = userId, TaskId = taskId })); }
public async void GetById_OK() { var mockedRepositoru = new Mock <IToDoListRepository>(); var userId = Guid.NewGuid(); var taskId = Guid.NewGuid(); mockedRepositoru.Setup(x => x.GetById(taskId)).Returns(Task.FromResult(new ToDoTask() { Id = taskId, UserId = userId })); var todoListService = new ToDoListService(mockedRepositoru.Object); var result = await todoListService.GetById(userId, taskId); Assert.NotNull(result); }
public async void Update_OK() { var mockedRepositoru = new Mock <IToDoListRepository>(); var userId = Guid.NewGuid(); var taskId = Guid.NewGuid(); mockedRepositoru.Setup(x => x.GetById(taskId)).Returns(Task.FromResult(new ToDoTask() { Id = taskId, UserId = userId })); var todoListService = new ToDoListService(mockedRepositoru.Object); await todoListService.UpdateTask(new UpdateToDoTask { UserId = userId, TaskId = taskId }); mockedRepositoru.Verify(x => x.Update(It.IsAny <ToDoTask>()), Times.Once); }
public async Task AddToDoItem_NoNameTask() { using (var context = new ToDoListContext(ContextOptions)) { // arrange var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper); var newToDo = new ToDoItemVm { TaskName = "" }; // act var result = await toDoListService.AddToDoItem(newToDo); // assert Assert.IsNull(result); } }
private void Completed_Click(object sender, RoutedEventArgs e) { Button completed = (Button)sender; var taskId = completed.Tag; var service = new ToDoListService(); var result = service.Completed((int)taskId); if (result.IsSuccessful) { //成功再改變畫面 var index = (MenuOptions)ListMenu.SelectedIndex; Show(index); } else { var path = result.WriteLog(); MessageBox.Show($"發生錯誤,請參考{path}"); } }
public async Task GetAllToDoItems_Expected() { using (var context = new ToDoListContext(ContextOptions)) { // arrange var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper); // act var result = await toDoListService.GetAllToDoItems(); // assert Assert.AreEqual(2, result.Count()); var task1 = result.First(); var task2 = result.Last(); Assert.AreEqual("Task 1", task1.TaskName); Assert.AreEqual("Task 2", task2.TaskName); } }
public async Task RemoveToDoItem_Expected() { using (var context = new ToDoListContext(ContextOptions)) { // arrange var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper); const int idToRemove = 1; // act var result = await toDoListService.RemoveToDoItem(idToRemove); // assert Assert.IsNotNull(result); Assert.AreEqual(idToRemove, result.Id); var searchResult = context.Set <ToDoItem>().FirstOrDefault(x => x.Id == idToRemove); Assert.IsNull(searchResult); } }
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, 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 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()); } }
public async Task AddToDoItem_Expected() { using (var context = new ToDoListContext(ContextOptions)) { // arrange var toDoListService = new ToDoListService(new ToDoItemRepository(context), _mapper); var newToDo = new ToDoItemVm { TaskName = "Task 3" }; // act var result = await toDoListService.AddToDoItem(newToDo); // assert Assert.IsNotNull(result); Assert.AreEqual("Task 3", result.TaskName); var toDoCount = context.Set <ToDoItem>().Count(); Assert.AreEqual(3, toDoCount); } }
private Engine() { // Read config file _configuration = ConfigInitializer.InitConfig(); _connectionStringCreate = _configuration.GetConnectionString("Create"); _connectionStringEdit = _configuration.GetConnectionString("Edit"); InitializeDb(_connectionStringCreate, _connectionStringEdit); UserRepository userRepositiry = new UserRepository(_connectionStringEdit); ToDoListRepository toDoListRepository = new ToDoListRepository(_connectionStringEdit); _userService = new UserService(userRepositiry); _toDoListService = new ToDoListService(toDoListRepository); _reader = new ConsoleReader(); _writer = new ConsoleWriter(); _userController = new UserController(_userService, _writer, _reader); _toDoListController = new ToDoListController(_toDoListService, _userService, _writer, _reader); _menu = new Menu(_writer, _reader, _userController, _toDoListController); }
// 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")); } }