Example #1
0
        public Friend Create(int savedUserId, int userToSaveId)
        {
            Friend newFriend = Friend.Create(UserService.Obj.FindById(savedUserId), UserService.Obj.FindById(userToSaveId));

            List <Friend> friends = GetAllFriends();

            if (newFriend.AreTheyAlreadyFriend(friends))
            {
                return(null);
            }

            if (savedUserId == userToSaveId)
            {
                return(null);
            }

            Friend createdEntity = repository.Create(newFriend);

            if (createdEntity == null)
            {
                throw new RepositoryException("Entity not created");
            }

            Tracer.Log.EntityCreated(nameof(Friend), createdEntity.Id);

            return(createdEntity);
        }