Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Blog_id,Blog_title,Create_time,Create_id,Blog_tag,Classify,Content,PageViews")] mb_blog mb_blog)
        {
            if (id != mb_blog.Blog_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(mb_blog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!mb_blogExists(mb_blog.Blog_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(mb_blog));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Blog_id,Blog_title,Create_time,Create_id,Blog_tag,Classify,Content,PageViews")] mb_blog mb_blog)
        {
            if (ModelState.IsValid)
            {
                //博客创建者
                mb_blog.Create_id = User.Identity.Name;
                //博客创建时间
                mb_blog.Create_time = DateTime.Now;
                mb_blog.PageViews   = 0;
                _context.Add(mb_blog);

                //每创建一个博客,博客数加1
                var mb_user = await _context.mb_user.SingleOrDefaultAsync(m => m.User_id == mb_blog.Create_id);

                mb_user.Blog_num++;
                try
                {
                    _context.Update(mb_user);
                    await _context.SaveChangesAsync();
                }
                catch { }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(mb_blog));
        }