public async Task <IActionResult> AddFriendToTask(MyTaskWithFriendViewModel viewModel) { if (ModelState.IsValid) { TaskModelBL task = await _client.Get <TaskModelBL>("api/mytask/details/" + viewModel.TaskId.ToString()); IEnumerable <UserFriendBL> friends = await _identityClient.Get <List <UserFriendBL> >("api/friends"); UserFriendBL friend = friends.FirstOrDefault(fr => fr.FriendId == viewModel.FriendId.ToString()); if (task == null || friend == null) { return(NotFound()); } task.Friends = new List <UserFriendBL> { friend }; await _client.Put("api/mytask/update", task.Id, task); return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public async Task <IActionResult> AddFriendToTask(int id) { if (id <= 0) { throw new ArgumentException(); } MyTaskWithFriendViewModel model = new MyTaskWithFriendViewModel { TaskId = id }; IEnumerable <UserFriendBL> friends = await _identityClient.Get <List <UserFriendBL> >("api/friends"); TaskModelBL task = await _client.Get <TaskModelBL>("api/mytask/details/" + id.ToString()); IEnumerable <string> UserIds = task.UserIds; var friendslist = friends.Where(fr => !UserIds.Any(uid => uid == fr.UserId)); ViewBag.UserFriends = new SelectList(friendslist, "FriendId", "Friend.UserName"); return(View(model)); }