public int CreateTodoItem(string Content) { if (!TodoItemValidator.Validate(Content)) { return(-1); } TodoItem todoItem = new TodoItem { Content = Content, Finish = false }; _todoItemRepository.Items.Add(todoItem); _todoItemRepository.SaveChanges(); return(todoItem.Id); }
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 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); } }
public IEnumerable <TodoItem> Adicionar(TodoItem item) { _repository.Itens.Add(item); _repository.SaveChanges(); return(_repository.Itens.ToList()); }