public ActionResult Create() { var friends = _friendService.GetAll(CurrentUser.Id).ToList(); var model = new CreateWishListViewModel() { UserId = CurrentUser.Id, FriendsList = new MultiSelectList(friends, "Id", "UserName") }; return PartialView("_Create", model); }
public ActionResult Create(CreateWishListViewModel model) { if (!ModelState.IsValid) { var friends = _friendService.GetAll(CurrentUser.Id).ToList(); model.FriendsList = new MultiSelectList(friends, "Id", "UserName", model.FriendsId); return PartialView("_Create", model); } var domainWishList = Mapper.Map<DomainWishList>(model); if (model.FriendsId != null) { var friendsList = _friendService.GetAllFriends(model.UserId) .Where(x => model.FriendsId.Contains(x.FriendId.ToString())) .ToList(); domainWishList.Friends = friendsList; } var id = _wishListService.Create(domainWishList); return Json(new { success = true, newWishListId = id }); }