public void DispatcherTimerTick(object sender) { TodoItemRepository repo = new TodoItemRepository(); using (var pc = new PrincipalContext(ContextType.Domain, _loginProvider.GetConnectionString())) { UserPrincipal qbeUser = new UserPrincipal(pc); qbeUser.DisplayName = "*"; PrincipalSearcher srch = new PrincipalSearcher(qbeUser); foreach (var found in srch.FindAll()) { UserPrincipal user = (found as UserPrincipal); if (user != null) { //Infusion hack: remove users that start with ext- or that have - or _ in their username if (/*user.SamAccountName.Contains("-") ||*/ user.SamAccountName.Contains("_")) { continue; } User dbUser = repo.Query <User>().FirstOrDefault(u => u.Username == user.SamAccountName); if (dbUser == null) { dbUser = new DomanUserLoginProvider(_loginProvider.GetConnectionString()).CreateUser(user.SamAccountName); if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username)) { repo.Add <User>(dbUser); } } } } } repo.SaveChanges(); }
public void TodoItemRepositoryTests_AddItemShouldBeAppearInRepo() //C { //Act var sut = new TodoItemRepository(); var todoItem = new TodoItemDTO { Title = "Tejet venni a palacsintához", IsDone = false, Opened = DateTime.Now, Closed = null, SeverityId = 3 }; try { //Arrange sut.Add(todoItem); var newTotoItem = sut.Find(todoItem.Id); //Assert Assert.IsNotNull(newTotoItem); Assert.AreEqual(todoItem.Title, newTotoItem.Title); } finally { sut.Remove(todoItem.Id); } }
public async Task GetNextSortOrder_ShouldReturnMaximumSortOrderPlusOne_WhenThereAreExistingTodoItems() { // Given: A database with multiple todo items TodoItemRepository todoItemRepository = new TodoItemRepository(this.DbContext); todoItemRepository.Add(new TodoItem() { ApplicationUser = this.CurrentUser, SortOrder = 1 }); todoItemRepository.Add(new TodoItem() { ApplicationUser = this.CurrentUser, SortOrder = 2 }); await todoItemRepository.SaveChangesAsync(); // When: We call GetNextSortOrder int nextSortOrder = todoItemRepository.GetNextSortOrder(); // Then: The sortorder should be three Assert.Equal(3, nextSortOrder); }
public async Task <ActionResult <TodoItemDto> > PostTodoItem(TodoItemDto todoItemDto, ApiVersion apiVersion) { if (!ModelState.IsValid) { return(BadRequest()); } var todoItem = _mapper.Map <TodoItem>(todoItemDto); _repo.Add(todoItem); await _repo.SaveChangesAsync(); return(CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id, version = apiVersion.ToString() }, todoItem)); }
public List <User> GetMatchingUsersFromDomain(string searchString) { try { List <User> userList = new List <User>(); TodoItemRepository repo = new TodoItemRepository(); using (var pc = new PrincipalContext(ContextType.Domain, _domain)) { UserPrincipal qbeUser = new UserPrincipal(pc); qbeUser.DisplayName = string.Format("*{0}*", searchString); PrincipalSearcher srch = new PrincipalSearcher(qbeUser); foreach (var found in srch.FindAll()) { UserPrincipal user = (found as UserPrincipal); if (user != null) { //Infusion hack: remove users that start with ext- or that have - or _ in their username if (user.SamAccountName.Contains("-") || user.SamAccountName.Contains("_")) { continue; } User dbUser = repo.Query <User>().FirstOrDefault(u => u.Username == user.SamAccountName); if (dbUser == null) { dbUser = new DomanUserLoginProvider(_domain).CreateUser(user.SamAccountName); if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username)) { repo.Add <User>(dbUser); } } if (!string.IsNullOrEmpty(dbUser.Firstname) && !string.IsNullOrEmpty(dbUser.Lastname) && !string.IsNullOrEmpty(dbUser.Username)) { userList.Add(dbUser); } } } } repo.SaveChanges(); return(userList); } catch (Exception ex) { Log.Error("Cannot connect to domain", ex); return(null); } }