public Entities.Blog Put(int id, [FromBody] Entities.Blog value)
        {
            var entity = dbContext.Blogs.Where(t => t.Id == id).FirstOrDefault();

            entity.Title   = value.Title;
            entity.Content = value.Content;
            dbContext.SaveChanges();
            return(entity);
        }
Exemple #2
0
        protected override void Seed(Data.RetroContext context)
        {
            context.Comment.ToList().ForEach(x => context.Comment.Remove(x));
            context.Blog.ToList().ForEach(x => context.Blog.Remove(x));


            var blog1 = new Entities.Blog
            {
                Author  = "Hermon Yohannes",
                Content = "blah",
                Title   = "Liked, Loved & Suggestions"
            };

            //blog1.Comments.Add(new Entities.Comment {Text = "lorem ipsum"});
            context.Blog.Add(blog1);

            var blog2 = new Entities.Blog
            {
                Author  = "Hermon Yohannes2",
                Content = "blah",
                Title   = "Liked, Loved & Suggestions"
            };

            //blog2.Comments.Add(new Entities.Comment { Text = "lorem ipsum2" });
            context.Blog.Add(blog2);

            var blog3 = new Entities.Blog
            {
                Author  = "Hermon Yohannes3",
                Content = "blah",
                Title   = "Liked, Loved & Suggestions"
            };

            //blog3.Comments.Add(new Entities.Comment { Text = "lorem ipsum3" });
            context.Blog.Add(blog3);

            context.SaveChanges();
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //
        }
Exemple #3
0
        /// <summary>
        /// Updates a blog.
        /// </summary>
        /// <param name="blogId">Id of the object being updated.</param>
        /// <param name="blog">The updated blog.</param>
        /// <param name="metafields">Optional metafield data that can be returned by the <see cref="MetaFieldService"/>.</param>
        /// <param name="cancellationToken">Cancellation Token</param>
        public virtual async Task <Entities.Blog> UpdateAsync(long blogId, Entities.Blog blog, IEnumerable <Entities.MetaField> metafields = null, CancellationToken cancellationToken = default)
        {
            var request = PrepareRequest($"blogs/{blogId}.json");
            var body    = blog.ToDictionary();

            if (metafields != null && metafields.Count() >= 1)
            {
                body.Add("metafields", metafields);
            }

            var content = new JsonContent(new
            {
                blog = body
            });

            var response = await ExecuteRequestAsync <Entities.Blog>(request, HttpMethod.Put, cancellationToken, content, "blog");

            return(response.Result);
        }
Exemple #4
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var blog = new Entities.Blog
                {
                    Content     = request.Content,
                    Title       = request.Title,
                    CreatorId   = request.CreatorId,
                    CreatorName = request.CreatorName,
                    Created     = DateTime.Now
                };

                await dbContext.AddAsync(blog, cancellationToken);

                await dbContext.SaveChangesAsync(cancellationToken);

                await bus.Publish(new UserPostedBlogEvent(request.CreatorId), cancellationToken);

                return(Unit.Value);
            }
 public Entities.Blog Post([FromBody] Entities.Blog value)
 {
     dbContext.Blogs.Add(value);
     dbContext.SaveChanges();
     return(value);
 }
 public void Put(int id, [FromBody] Entities.Blog value)
 {
     db.Blogs.Update(value);
     db.SaveChanges();
 }
 public void Post([FromBody] Entities.Blog value)
 {
     db.Blogs.Add(value);
     db.SaveChanges();
 }