public ActionResult AddGroup() { var currentUserId = _userService.GetUserByLogin(Thread.CurrentPrincipal.Identity.Name).Id; var friends = _friendService.GetUsersFriends(currentUserId); var friendsSelectList = friends.Select(x => new SelectListItem { Text = x.Nickname, Value = x.Id.ToString() }); var groupCreationViewModel = new GroupCreationViewModel() { CreatorId = currentUserId, Members = friendsSelectList, SelectedMembers = new List <string>() }; return(View(groupCreationViewModel)); }
public ActionResult AddGroup(GroupCreationViewModel groupCreationViewModel) { var currentUserId = _userService.GetUserByLogin(Thread.CurrentPrincipal.Identity.Name).Id; if (string.IsNullOrWhiteSpace(groupCreationViewModel.Name) || groupCreationViewModel.SelectedMembers == null) { var friends = _friendService.GetUsersFriends(currentUserId); var friendsSelectList = friends.Select(x => new SelectListItem { Text = x.Nickname, Value = x.Id.ToString() }); groupCreationViewModel.Members = friendsSelectList; return(View(groupCreationViewModel)); } _groupService.AddGroup(currentUserId, groupCreationViewModel.SelectedMembers.Select(x => int.Parse(x)), groupCreationViewModel.Name); return(RedirectToAction("Messages", "Message", new { area = "" })); }