Пример #1
0
        public async Task <ActionResult> Delete([FromHeader] string Authentication, string userId)
        {
            if (SessionManager.GetSessionState(Authentication) != SessionManager.SessionState.Authorized)
            {
                return(Unauthorized());
            }
            SessionInfo sessionInfo = SessionManager.GetSessionInfo(Authentication);

            if (sessionInfo == null)
            {
                return(Unauthorized());
            }

            int userIdNum = 0;

            if (!int.TryParse(userId, out userIdNum))
            {
                return(NotFound(userId));
            }

            using (UnitOfWork uow = new UnitOfWork())
            {
                FriendshipsRepository friendshipsRepository = new FriendshipsRepository(uow);
                FriendshipDTO         friendship            = await friendshipsRepository.GetFriendship(userIdNum, sessionInfo.UserId);

                if (friendship != null)
                {
                    await friendshipsRepository.Remove(friendship.Id);
                }

                uow.Commit();
            }

            return(Ok());
        }