Blog.Logic.Core.PostLikesLogic.Add C# (CSharp) 메소드

Add() 공개 메소드

public Add ( PostLike postLike ) : PostLike
postLike Blog.Common.Contracts.PostLike
리턴 Blog.Common.Contracts.PostLike
        public PostLike Add(PostLike postLike)
        {
            try
            {
                var tmpPostLike = _postLikeRepository.Find(a => a.PostId == postLike.PostId && a.UserId == postLike.UserId, false).ToList();
                if (tmpPostLike.Count > 0)
                {
                    _postLikeRepository.Delete(tmpPostLike.FirstOrDefault());
                    return null;
                }

                return PostLikeMapper.ToDto(_postLikeRepository.Add(PostLikeMapper.ToEntity(postLike)));
            }
            catch (Exception ex)
            {
                throw new BlogException(ex.Message, ex.InnerException);
            }
        }
    }