示例#1
0
        public static async Task <ResultsItem> DeleteBBComment(int commentId, LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    BBComments serviceComment = db.BBComments.FirstOrDefault(x => x.CommentId == commentId);
                    if (serviceComment == null)
                    {
                        return(ResultsItem.Error("This comment was not found or has already been deleted."));
                    }
                    if (serviceComment.UserId != user.UserId)
                    {
                        return(ResultsItem.Error("This comment belongs to another user."));
                    }

                    db.Remove(serviceComment);
                    await db.SaveChangesAsync();

                    return(ResultsItem.Success("Successfully deleted this comment. Please refresh the page to see changes."));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}" }, ex);
                return(ResultsItem.Error($"Unable to delete this comment. {ex.Message}"));
            }
        }
示例#2
0
        public static async Task <ResultsItem> CreateBBComment(LocalCommunity.BBComment comment, LocalAccount.PegaUser user)
        {
            try
            {
                using (PegasunDBContext db = new PegasunDBContext())
                {
                    comment.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });

                    BBComments serviceComment = comment.Adapt <BBComments>();
                    serviceComment.CreateDate = DateTime.Now;
                    serviceComment.UserId     = user.UserId;
                    serviceComment.Message    = serviceComment.Message.Clean(new[] { Types.CleanInputType.AZ09CommonCharsSM });

                    db.BBComments.Add(serviceComment);
                    await db.SaveChangesAsync();

                    return(ResultsItem.Success("Successfully posted a new comment."));
                }
            }
            catch (Exception ex)
            {
                Utilities.LogException(new[] { $"User:{user.Username}" }, ex);
                return(ResultsItem.Error($"Unable to create a comment. {ex.Message}"));
            }
        }