Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Body,Author")] Comment comment)
        {
            using (AuditScope.Create("Edit", () => comment))
            {
                if (id != comment.Id)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(comment);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CommentExists(comment.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                return(View(comment));
            }
        }
        public async Task <ActionResult <Models.Comment> > PutComment(long id, Models.Comment comment)
        {
            var originalComment = await _context.GetComment(id);

            comment.id   = id;
            comment.date = originalComment.date;
            comment._id  = originalComment._id;

            await _context.Update(comment);

            try
            {
                await _context.SaveChangesAsync();

                return(comment);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Author,Text")] CommentModel comment)
        {
            if (id != comment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(comment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommentExists(comment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(Content("Piola"));
        }