Пример #1
0
        public ActionResult Edit(ArticleComment comment)
        {
            try
            {
                comment.LastUpdate = DateTime.Now;

                ViewBag.Success = true;

                if (comment.ID == -1)
                {
                    ArticleComments.Insert(comment);

                    UserNotifications.Send(UserID, String.Format("ویرایش نظر '{0}'", comment.Subject), "/Admin/ArticleComments/Edit/" + comment.ID, NotificationType.Success);

                    comment = new ArticleComment();
                }
                else
                {
                    ArticleComments.Update(comment);
                }
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(ClearView(model: comment));
        }
Пример #2
0
        public JsonResult AddComment(int id, string userName, string email, string subject, string text)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                ArticleComment comment = new ArticleComment
                {
                    ArticleID     = id,
                    CommentStatus = ArticleCommentStatus.NotChecked,
                    UserName      = userName,
                    Email         = email,
                    Subject       = subject,
                    Text          = text,
                    LastUpdate    = DateTime.Now,
                    UserID        = User.Identity.IsAuthenticated ? UserID : null
                };

                ArticleComments.Insert(comment);

                // اطلاع رسانی به مدیر
                #region Apprise Admin

                string body = "مدیریت محترم، در بخش نظرات وبلاگ، نظر جدیدی ثبت شد:";
                body += "<br/>";
                body += String.Format("ایمیل: {0} <br/> موضوع: {1} <br/> پیام: {2}", email, subject, text);

                EmailServices.NotifyAdminsByEmail(AdminEmailType.NewBlogComment, body, null);

                #endregion Apprise Admin

                jsonSuccessResult.Success = true;
            }
            catch (DbException ex)
            {
                jsonSuccessResult.Errors  = ex.Errors.ToArray();
                jsonSuccessResult.Success = false;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }