Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Content,PublicationDate,OwnerID,BlogPostId")] Comment 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(View(comment));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Title,PubDate,Image,Content,cats")] BlogPost blogPost, IFormFile Image)
        {
            if (id != blogPost.ID)
            {
                return(NotFound());
            }

            if (Image != null)
            {
                blogPost.Image = await _fileManager.SaveImage(Image);
            }


            string ctg = "";
            bool   yes = false;

            foreach (string a in blogPost.cats.Split(" "))
            {
                foreach (Category i in _context.Categories)
                {
                    if (i.catname == a)
                    {
                        yes = true;
                    }
                }
                if (yes == true)
                {
                    ctg += a;
                    ctg += " ";
                    yes  = false;
                }
            }

            blogPost.cats = ctg;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(blogPost);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BlogPostExists(blogPost.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(blogPost));
        }