Пример #1
0
        public int InsertCommentAndUser(CommentDto comment)
        {
            using (var conn = DbUtilities.Connection)
            {
                conn.Open();
                using (var transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted))
                {
                    try
                    {
                        var identity = conn.Query<int>(QueryCommentStore.InsertUser + " " + QueryStore.LastInsertedId,
                            new
                            {
                                idsocialuserid = comment.UserId,
                                name = comment.Name,
                                email = comment.UserMail
                            }, transaction: transaction).SingleOrDefault();
                        ;

                        identity = InsertComment(comment, identity, transaction);

                        transaction.Commit();

                        return identity;
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Пример #2
0
        public BaseResponse InsertComment(CommentDto comment)
        {
            comment.CannotBeNull("comment");
            var user = _commentRepository.GetUserBySocialId(comment.UserId);
            int res;
            if (user == null)
            {
               res =  _commentRepository.InsertCommentAndUser(comment);
            }
            else
            {
                res = _commentRepository.InsertComment(comment, user.IdUser);
                if (string.IsNullOrEmpty(user.Email) && comment.UserMail != null)
                {
                    user.Email = comment.UserMail;
                    _commentRepository.UpdateSocialUser(user);
                }
            }

            return new BaseResponse() { Message = res > 0 ? res.ToString() : "ko", Success = res > 0 };
        }
Пример #3
0
        public int InsertComment(CommentDto comment, long idUser, IDbTransaction transaction = null)
        {
            comment.CannotBeNull("comment");
                var conn = transaction != null ? transaction.Connection :  DbUtilities.Connection;

                var res = conn.Query<int>(QueryCommentStore.InsertPostComment + " " + QueryStore.LastInsertedId,
                new
                {
                    idsocialcomment = comment.IdComment,
                    idpost = comment.IdPost,
                    iduser = idUser,
                    text = comment.Comment,
                    pageurl = comment.PageUrl,
                    timestamp = DateTime.Now
                }, transaction: transaction).SingleOrDefault();

            if (transaction != null) return res;

            conn.Close();
            conn.Dispose();
            return res;
        }