예제 #1
0
        public async Task <PublicationResponse> SaveAsync(Publication publication, int userId)
        {
            var existingUser = await _userCommonRepository.FindById(userId);

            if (existingUser == null)
            {
                return(new PublicationResponse("User not found"));
            }

            publication.User = existingUser;

            try
            {
                await _publicationRepository.AddAsync(publication);

                await _unitOfWork.CompleteAsync();

                return(new PublicationResponse(publication));
            }
            catch (Exception ex)
            {
                return(new PublicationResponse(
                           $"An error ocurred while saving the publication: {ex.Message}"));
            }
        }
        public async Task <PublicationResponse> SaveAsync(Publication publication)
        {
            try
            {
                await _publicationRepository.AddAsync(publication);

                await _unitOfWork.CompleteAsync();

                return(new PublicationResponse(publication));
            }
            catch (Exception ex)
            {
                return(new PublicationResponse($"An error ocurred while saving the publication: {ex.Message}"));
            }
        }