public User GetUserByEmailAddress(string emailAddress)
 {
     var usersSearchCriteria = new UsersSearchCriteria
                                   {
                                       WithEmailAddresses = new[] {  emailAddress }
                                   };
     return Repository.Get<User>(usersSearchCriteria.BuildCriteria());
 }
        public ActionResult Index(GridOptionsModel options)
        {
            options.Column = options.Column == "id" ? options.Column = "Email" : options.Column;

            var userSearchCriteria = new UsersSearchCriteria
                                         {
                                             Ascending = options.Ascending,
                                             OrderByProperty = options.Column,
                                         };

            var users = AccountService.FindUsers(userSearchCriteria);
            var usersModel = new AccountsModel
                                 {
                                     Data = Mapper.Map<IEnumerable<User>, IEnumerable<AccountModel>>(users).AsPagination(options.Page, 10),
                                     Options = options
                                 };
            return View(usersModel);
        }
 public IEnumerable<User> FindUsers(UsersSearchCriteria search)
 {
     return Repository.List<User>(search.BuildCriteria());
 }
 public ActionResult InviteExistingUsers(GridOptionsModel options)
 {
     var userSearchCriteria = new UsersSearchCriteria()
                                  {
                                      DistinctRootEntity = true,
                                      OrderByProperty = "FirstName",
                                      WithoutId = _event.AllMembers.Where(x => x.User != null && (x.Status.IsMember() || x.Status == EventMemberStatus.Invited))
                                                                     .Select(x => x.User.Id).ToArray()
                                  };
     var users = AccountService.FindUsers(userSearchCriteria);
     var model = new ThumbnailsDisplayModel
                     {
                         Data =
                             Mapper.Map<IEnumerable<User>, IEnumerable<ThumbnailDisplayModel>>(users).ToList().
                             AsPagination(options.Page, 12),
                         Options = options
                     };
     return View("ThumbnailsDisplay", model);
 }
 public ActionResult SearchByName(AccountSearchByNameModel searchModel)
 {
     var search = new UsersSearchCriteria
                      {
                          NameIsLike = searchModel.term,
                          DistinctRootEntity = true,
                          OrderByProperty = "FirstName",
                      };
     var users = AccountService.FindUsers(search);
     if (Request.IsAjaxRequest())
         return Json(users.Select(x => new JQueryAutoCompleteResponseModel(x.Id.ToString(), string.Format("{0} {1}", x.FirstName, x.LastName))),
                 JsonRequestBehavior.AllowGet);
     return RedirectToAction("Index", "Home");
 }
        public ActionResult CreateUserPosition(CreateUserPositionModel model)
        {
            var position = _positionService.GetPosition(model.PositionId);

            if(ModelState.IsValid)
            {
                var existingUsers = position.Users;
                var userSearch = new UsersSearchCriteria  { DistinctRootEntity = true, WithId = model.UserIds };
                var users = AccountService.FindUsers(userSearch).Where(x => !existingUsers.Any(r => x.Id == r.User.Id));
                var userPositions = users.Select(x => new UserPosition {Position = position, User = x});
                userPositions = _positionService.SaveUserPositions(userPositions);
                if(!userPositions.Any(x => x.InvalidValues.Any()))
                {
                    DisplayMessage("User positions created successfully");
                    return RedirectToAction("Position", "Positions", new { id = model.PositionId });
                }
                AddValidationResults(userPositions.Where(x => x.InvalidValues.Count() > 0).First().InvalidValues);
                DisplayError("User positions were not created successfully");
            }

            return View(new CreateUserPositionViewModel {Name = position.Name, PositionId = model.PositionId});
        }