Example #1
0
        public void Update(Post obj)
        {
            var procedure = new ProcedureSql("Update_Post");

            procedure.AddParameter("@Id", obj.Id);
            procedure.AddParameter("@AuthorId", obj.Author.Id);
            procedure.AddParameter("@Title", obj.Title);
            procedure.AddParameter("@Body", obj.Body);
            procedure.AddParameter("@IsPublished", obj.IsPublished);

            // Sql Server 2008 compatible
            // http://www.mssqltips.com/sqlservertip/2112/table-value-parameters-in-sql-server-2008-and-net-c/
            var categories = new DataTable();
            categories.Columns.Add("Id", typeof(Int32));
            if (obj.Categories != null)
            {
                foreach (Category category in obj.Categories)
                {
                    categories.Rows.Add(category.Id);
                }
            }
            procedure.AddParameter("@Categories", categories, SqlDbType.Structured);

            procedure.Execute();            
        }
Example #2
0
        public IValidationResult Update(Post obj)
        {
            if (obj == null)
                throw new NullReferenceException("obj");

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

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

            return validationResult;
        }
Example #3
0
        private Post FillPost(SqlDataReader reader)
        {
            var post = new Post();

            post.Id = reader.GetInt32(0);
            post.Author = new Author();
            post.Author.Id = reader.GetInt32(1);
            post.Title = reader.GetValueOrDefault<string>(2);
            post.Body = reader.GetValueOrDefault<string>(3);
            post.IsPublished = reader.GetBoolean(4);
            post.DateCreated = reader.GetDateTime(5);

            return post;
        }
Example #4
0
        public IValidationResult Add(Post obj)
        {
            if (obj == null)
                throw new NullReferenceException("obj");

            obj.DateCreated = DateTime.UtcNow;

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

            if (validationResult.IsValid)
                this.postRepository.Add(obj);

            return validationResult;
        }
Example #5
0
        public void Shoud_Not_Add_Post_Without_Author()
        {
            var post = new Post();
            post.Title = "Post Title";
            post.Body = "Post body.";
            post.IsPublished = true;

            var postValidation = new PostValidation();
            var postRepository = new FakePostRepository();
            var postService = new PostService(postRepository, postValidation);

            var result = postService.Add(post);
                        
            Assert.IsFalse(result.IsValid);
            Assert.IsTrue(result.Errors.Count == 1);
            Assert.IsTrue(result.Errors[0].PropertyName == "Author.Id");
            
        }
Example #6
0
 public IValidationResult Update(Post obj)
 {
     return this.postService.Update(obj);
 }
Example #7
0
 public IValidationResult Add(Post obj)
 {            
     return this.postService.Add(obj);
 }
Example #8
0
 public void Update(Post obj)
 {
     throw new NotImplementedException();
 }
Example #9
0
 public void Add(Post obj)
 {
     this.Posts.Add(obj);
 }
Example #10
0
 public ActionResult Save(Post post)
 {
     return View();
 }