Exemple #1
0
        /// <summary>
        /// Creates an active Blog Post together with an image. Defaults to the current date
        /// </summary>
        /// <param name="title"></param>
        /// <param name="post"></param>
        /// <param name="filename"></param>
        /// <param name="image"></param>
        /// <param name="tag"></param>
        /// <param name="user"></param>
        public void CreateBlogPost(string title, string post, string filename, byte[] image, string tag, string user)
        {
            using (var context = new BlogContext())
            {
                var repo = new BlogRespository(context);

                repo.Add(new BlogDataModel
                {
                    Id    = Guid.NewGuid(),
                    Title = title,
                    Post  = post,
                    Tags  = tag,
                    Image = new ImageDataModel
                    {
                        Filename = filename,
                        Data     = image,
                    },

                    Active     = true,
                    LastUpdate = DateTime.Now,
                    Author     = user,
                });

                context.Commit();
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates a blog post. When no image is uploaded, the existing image is retained.
        /// The active active status indicates whether a blog post is deleted.
        /// </summary>
        /// <param name="dto"></param>
        public void UpdateBlogPost(EditBlogDto dto)
        {
            using (var context = new BlogContext())
            {
                var repo = new BlogRespository(context);
                var blog = repo.GetById(dto.Id);

                blog.Title = dto.Title;
                blog.Post  = dto.Post;

                //only add image, when uploaded
                if (dto.Image != null)
                {
                    blog.Image.Filename = dto.Filename;
                    blog.Image.Data     = dto.Image;
                }

                blog.Tags       = dto.Tags;
                blog.Author     = dto.Author;
                blog.Active     = dto.Active;
                blog.LastUpdate = DateTime.Now;

                context.Commit();
            }
        }