示例#1
0
        public async Task <IHttpActionResult> FriendsUserById(FriendshipIdModel model)
        {
            try
            {
                var user = await UserManager.FindByIdAsync(model.Id);

                if (user == null || !user.Friendships.Any())
                {
                    return(BadRequest("Пользователь или его друзья не найдены"));
                }

                List <FrienResult> result = new List <FrienResult>();

                foreach (var userFriendship in user.Friendships)
                {
                    var friend = await UserManager.FindByIdAsync(userFriendship.FriendId);

                    result.Add(new FrienResult()
                    {
                        FriendId           = userFriendship.FriendId,
                        FirstName          = friend.FirstName,
                        LastName           = friend.LastName,
                        FriendshipType     = userFriendship.FriendshipType,
                        FriendshipDuration = userFriendship.FriendshipDuration
                    });
                }

                return(Json(result));
            }
            catch (Exception)
            {
                //todo: здесь реализация логирования
                throw;
            }
        }
示例#2
0
        public async Task <IHttpActionResult> DeleteFriend(FriendshipIdModel model)
        {
            try
            {
                var carentUser = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                var friend = carentUser.Friendships.FirstOrDefault(e => e.FriendId == model.Id);

                if (friend == null)
                {
                    return(BadRequest("Данный пользователь отутвует в списке друзей"));
                }
                await context.RemoveFriendAsync(carentUser.Id, model.Id);

                return(Ok());
            }
            catch (Exception)
            {
                //todo: здесь реализация логирования
                throw;
            }
        }