/// <summary>
 /// Deletes a variable from the repository.
 /// </summary>
 /// <param name="variable">The variable to be deleted.</param>
 public void DeleteVariable(Variable variable)
 {
     _dataContext.Variables.DeleteObject(variable);
 }
 /// <summary>
 /// Adds a variable to the repository.
 /// </summary>
 /// <param name="variable">The variable to be added.</param>
 public void AddVariable(Variable variable)
 {
     _dataContext.Variables.AddObject(variable);
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Variables EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToVariables(Variable variable)
 {
     base.AddObject("Variables", variable);
 }
Beispiel #4
0
        public ActionResult AddComment(FormCollection formCollection)
        {
            PostComment newComment = new PostComment();
            TryUpdateModel<INewPostComment>(newComment, formCollection);
            newComment.PostedDate = DateTime.UtcNow;
            newComment.IPAddress = Request.UserHostAddress;
            if (ModelState.IsValid)
            {
                newComment.Body = Server.HtmlEncode(newComment.Body);
                _postCommentRepository.AddPostComment(newComment);
                _postCommentRepository.SaveChanges();

                if (!User.Identity.IsAuthenticated || (User.Identity.IsAuthenticated && _userRepository.GetUser(User.Identity.Name).Email.ToUpper() != newComment.Email.ToUpper()))
                {
                    try
                    {
                        SmtpClient smtpClient = new SmtpClient();
                        MailMessage notificationEmail = new MailMessage
                        {
                            IsBodyHtml = true,
                            Subject = string.Format("{0} posted a comment on CodeTunnel!", newComment.Author),
                            Body = string.Format(
                                "{0} posted a comment on your blog post titled <a href='{2}'>{1}</a>.<br /><br />{3}",
                                newComment.Author,
                                newComment.BlogPost.Title,
                                ConfigurationManager.AppSettings["FullUrl"] + Url.Action("Post", new { Id = newComment.PostID }),
                                newComment.Body)
                        };
                        notificationEmail.To.Add(newComment.BlogPost.User.Email);
                        smtpClient.Send(notificationEmail);
                    }
                    catch { }
                }

                if (Request.IsAjaxRequest())
                    return Json(new
                    {
                        Valid = true,
                        Html = MvcUtilities.Utilities.CommonUtils.RenderViewToString(this, "PostComments", newComment.BlogPost.PostComments.OrderBy(x => x.PostedDate), true)
                    });
                else
                    return RedirectToAction("Post", new { Id = newComment.PostID });
            }
            else
            {
                if (ModelState.ContainsKey("spam"))
                {
                    Variable spamCaught = this._variableRepository.GetVariable("spamCaught");
                    bool addNew = (spamCaught == null);
                    int spamCount = 0;
                    if (addNew)
                        spamCaught = new Variable { Name = "spamCaught" };
                    else
                        spamCount = int.Parse(spamCaught.Value);
                    spamCount++;
                    spamCaught.Value = spamCount.ToString();
                    if (addNew)
                        _variableRepository.AddVariable(spamCaught);
                    _variableRepository.SaveChanges();
                }

                if (!Request.IsAjaxRequest())
                {
                    var blogPost = _blogPostRepository.GetBlogPost(newComment.PostID);
                    var viewModel = new BlogPostViewModel
                    {
                        BlogPost = blogPost,
                        NewComment = newComment
                    };
                    return View("Post", viewModel);
                }
                else
                {
                    return Json(new
                    {
                        Valid = false,
                        Html = MvcUtilities.Utilities.CommonUtils.RenderViewToString(this, "NewComment", newComment, true)
                    });
                }
            }
        }
 /// <summary>
 /// Create a new Variable object.
 /// </summary>
 /// <param name="name">Initial value of the Name property.</param>
 public static Variable CreateVariable(global::System.String name)
 {
     Variable variable = new Variable();
     variable.Name = name;
     return variable;
 }