public ActionResult Save(Comment comment)
        {
            if (comment == null)
                throw new InvalidOperationException();

            if (comment.Id > 0)
            {
                var validationResult = this.commentAppService.Update(comment);
                if (validationResult.IsValid == false)
                {
                    ViewBag.Error = "There are erros, please correct and try again.";
                    ControllerHelpers.AddErrors(validationResult.Errors, ModelState);
                }
                else
                {
                    ViewBag.Message = "Comment successful updated.";
                }
            }
            else
            {
                var validationResult = this.commentAppService.Add(comment);
                if (validationResult.IsValid == false)
                {
                    ViewBag.Error = "There are erros, please correct and try again.";
                    ControllerHelpers.AddErrors(validationResult.Errors, ModelState);
                    RedirectToAction("New");
                }
                else
                {
                    ViewBag.Message = "Comment successful added.";
                }
            }

            return RedirectToAction("Edit", new { id = comment.Id });
        }
Example #2
0
        public ActionResult AddComment(Comment comment)
        {
            var validationResult = this.commentAppService.Add(comment);

            if (validationResult.IsValid == false)
                ControllerHelpers.AddErrors(validationResult.Errors, ModelState);            

            return RedirectToAction("Post", new { id = comment.PostId });
        }
Example #3
0
        public IValidationResult Update(Comment obj)
        {
            if (obj == null)
                throw new NullReferenceException("obj");

            var validationResult = this.commentValidation.Validate(obj);

            if (validationResult.IsValid)
                this.commentRepository.Update(obj);

            return validationResult;
        }
        private Comment FillComment(SqlDataReader reader)
        {
            var comment = new Comment();
            comment.Id = reader.GetInt32(0);
            comment.PostId = reader.GetInt32(1);
            comment.Name = reader.GetString(2);
            comment.Email = reader.GetValueOrDefault<string>(3);
            comment.Url = reader.GetValueOrDefault<string>(4);
            comment.Body = reader.GetString(5);
            comment.Status = (CommentStatus)reader.GetInt32(6);
            comment.DateCreated = reader.GetDateTime(7);

            return comment;
        }
Example #5
0
        public IValidationResult Add(Comment obj)
        {
            if (obj == null)
                throw new NullReferenceException("obj");

            obj.DateCreated = DateTime.UtcNow;

            var validationResult = this.commentValidation.Validate(obj);
            
            if(validationResult.IsValid)
                this.commentRepository.Add(obj);

            return validationResult;
        }
        public void Update(Comment obj)
        {
            var procedure = new ProcedureSql("Update_Comment");

            procedure.AddParameter("@Id", obj.Id);
            procedure.AddParameter("@PostId", obj.PostId);
            procedure.AddParameter("@Name", obj.Name);
            procedure.AddParameter("@Email", obj.Email);
            procedure.AddParameter("@Url", obj.Url);
            procedure.AddParameter("@Body", obj.Body);
            procedure.AddParameter("@Status", obj.Status);
            procedure.AddParameter("@DateCreated", obj.DateCreated);

            procedure.Execute();
        }
        public void Add(Comment obj)
        {
            var procedure = new ProcedureSql("Add_Comment");

            procedure.AddParameter("@Id", SqlDbType.Int, ParameterDirection.Output);
            procedure.AddParameter("@PostId", obj.PostId);
            procedure.AddParameter("@Name", obj.Name);
            procedure.AddParameter("@Email", obj.Email);
            procedure.AddParameter("@Url", obj.Url);
            procedure.AddParameter("@Body", obj.Body);
            procedure.AddParameter("@Status", obj.Status);
            procedure.AddParameter("@DateCreated", obj.DateCreated);

            obj.Id = procedure.Insert();
        }
 public IValidationResult Update(Comment obj)
 {
     return commentService.Update(obj);
 }
 public IValidationResult Add(Comment obj)
 {
     return commentService.Add(obj);
 }