Esempio n. 1
0
        public async Task <FriendDto> Handle(CreateFriendCommand request, CancellationToken cancellationToken)
        {
            var user = await _userManager.FindByEmailAsync("*****@*****.**");

            var adress = new Address(request.Number, request.Street, request.Neighborhood, request.City);

            var friend = new Friend(request.Name, request.Email, request.Phone, adress, user);

            var photoUploadResult = _photoAccesor.AddPhoto(request.File);

            friend.AddPhoto(photoUploadResult);

            _entityValidator.Validate(new Entity[] { friend, adress });

            if (_notification.HasNotifications)
            {
                _photoAccesor.DeletePhoto(photoUploadResult?.PublicId);
                return(null);
            }

            _context.Friends.Add(friend);

            await _context.Commit();

            return(_mapper.Map <FriendDto>(friend));
        }