Exemple #1
0
        public async Task <ActionResult <SFComments> > PostSFComments(SFComments sFComments)
        {
            _context.SFComments.Add(sFComments);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSFComments", new { id = sFComments.CommentId }, sFComments));
        }
        public static void Initialize(SFCommentContext context)
        {
            context.Database.EnsureCreated();

            var sfCommentss = new SFComments[]
            {
                new SFComments
                {
                    PostId  = 1,
                    UserId  = 1,
                    Comment = "Mooi man",
                },
                new SFComments
                {
                    PostId  = 1,
                    UserId  = 2,
                    Comment = "Super mooi !",
                },
                new SFComments
                {
                    PostId  = 1,
                    UserId  = 4,
                    Comment = "Daar zou ik ook wel eens willen zijn.",
                },
            };

            foreach (SFComments sfComments in sfCommentss)
            {
                context.SFComments.Add(sfComments);
            }
            context.SaveChanges();
        }
Exemple #3
0
        public async Task <IActionResult> PutSFComments(long id, SFComments sFComments)
        {
            if (id != sFComments.CommentId)
            {
                return(BadRequest());
            }

            _context.Entry(sFComments).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SFCommentsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }