public ActionResult Add(AddUserToSiteViewModel model) { //Chck are there selected users if (!model.Users.Any(x => x.IsSelected)) { this.ModelState.AddModelError("", UserSiteTr.PleaseSelectUser); return(View(model)); } var userIds = model.Users.Where(x => x.IsSelected).Select(x => x.Id).ToList(); this.siteService.AddUsersToSite(model.SiteId, userIds); return(Redirect("/Admin/Site/Details/" + model.SiteId)); }
public ActionResult Add(int id) { var users = this.userService.GetAll().ToList().Where(x => x.Status == "Active"); var availableUsers = this.siteService.GetById(id).Users.ToList(); users = users.ExceptBy(availableUsers, x => x.Id).ToList(); var usersViewModel = users.ToList().ConvertAll(x => new ChooseUserViewModel { Id = x.Id, Name = (x.FirstName != null && x.SecondName != null && x.LastName != null) ? x.FirstName + " " + x.SecondName + " " + x.LastName : x.Email, IsSelected = false }); var viewModel = new AddUserToSiteViewModel { SiteId = id, Users = usersViewModel }; return(View(viewModel)); }