Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,comment,comment_time,userID,essayID")] Forum_msgViewModel forum_msgViewModel)
        {
            if (id != forum_msgViewModel.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(forum_msgViewModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!Forum_msgViewModelExists(forum_msgViewModel.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["essayID"] = new SelectList(_context.Science_essay, "ID", "ID", forum_msgViewModel.essayID);
            //ViewData["userID"] = new SelectList(_context.users, "ID", "password", forum_msgViewModel.userID);
            ViewData["userID"] = new SelectList(_context.users, "ID", "userID", forum_msgViewModel.userID);
            return(View(forum_msgViewModel));
        }
Ejemplo n.º 2
0
        public static void Initialize(NaturalDisasterDatabaseWebsiteContext context)
        {
            //EnsureCreated方法自动创建数据库
            context.Database.EnsureCreated();

            // 查找用户
            if (context.users.Any())
            {
                return;   // DB 已有测试(基本)数据
            }

            var users = new UsersViewModel[]
            {
                new UsersViewModel {
                    username = "******", password = "******", sex = "女", email = "*****@*****.**", status = "管理员", img = "head-default.png", telephone = "18877524840", workplace = "广西师范大学", occupation = "Web前端", address = "广西师范大学雁山校区"
                },
                new UsersViewModel {
                    username = "******", password = "******", sex = "男", email = "*****@*****.**", status = "普通用户", img = "head-default.png", telephone = "18877524840", workplace = "广西师范大学", occupation = "运维工程师", address = "广西师范大学雁山校区"
                }
            };

            foreach (UsersViewModel u in users)
            {
                context.users.Add(u);
            }
            context.SaveChanges();

            var essays = new Science_essayViewModel[]
            {
                new Science_essayViewModel {
                    ID = 1, title = "习近平总书记关于防灾减灾救灾重要论述摘录", author = "灾协", source = "云南防震减灾网", fb_time = DateTime.Parse("2019-07-26 19:53:00"), wz_content = "要坚持抗震救灾工作和经济社会发展两手抓、两不误,大力弘扬伟大抗震救灾精神,大力发挥各级党组织领导核心和战斗堡垒作用、广大党员先锋模范作用,引导灾区群众广泛开展自力更生、生产自救活动,在中央和四川省大力支持下,积极发展生产、建设家园,用自己的双手创造幸福美好的生活", wz_style = "科普", state = "已发布", userID = 1
                },
                new Science_essayViewModel {
                    ID = 2, title = "古人如何应对洪涝灾害", author = "灾协", source = "中国水运报", fb_time = DateTime.Parse("2019-11-29 14:53:00"), wz_content = "今年入夏以来,从南到北各地水灾多发,抗洪救灾成为舆论热点。事实上,洪涝灾害自古以来就是人类最常面对的自然灾害。因此,人类历史也是一部与洪涝灾害斗争的历史。那么,我国古代在条件有限的情况下是如何应对洪涝灾害呢?", wz_style = "科普", state = "待审核", userID = 2
                }
            };

            foreach (Science_essayViewModel s in essays)
            {
                context.Science_essay.Add(s);
            }
            context.SaveChanges();

            var fMsgs = new Forum_msgViewModel[]
            {
                new Forum_msgViewModel {
                    ID = 1, comment = "习大大的胸怀是真的非常宽广!赞赞赞~~~", comment_time = DateTime.Parse("2020-1-6 14:24:00"), userID = 2, essayID = 1
                },
                new Forum_msgViewModel {
                    ID = 1, comment = "古人头脑真睿智啊~赞赞赞~", comment_time = DateTime.Parse("2019-12-28 10:43:00"), userID = 5, essayID = 2
                },
            };

            foreach (Forum_msgViewModel e in fMsgs)
            {
                context.Forum_msg.Add(e);
            }
            context.SaveChanges();
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("ID,comment,comment_time,userID,essayID")] Forum_msgViewModel forum_msgViewModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(forum_msgViewModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["essayID"] = new SelectList(_context.Science_essay, "ID", "ID", forum_msgViewModel.essayID);
            //ViewData["userID"] = new SelectList(_context.users, "ID", "password", forum_msgViewModel.userID);
            ViewData["userID"] = new SelectList(_context.users, "ID", "userID", forum_msgViewModel.userID);
            return(View(forum_msgViewModel));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> NewForumMsg([Bind("comment,comment_time,userID,essayID")] Forum_msgViewModel forum_msgViewModel, string essayID, string comment)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (comment == null)
                    {
                        return(Content("<meta http-equiv='content-type' content='text/html; charset = utf-8' /><script>alert('请输入评论内容');history.go(-1);</script>", "text/html"));
                    }
                    _context.Add(forum_msgViewModel);
                    await _context.SaveChangesAsync();

                    return(Content("<meta http-equiv='content-type' content='text/html; charset = utf-8' /><script>alert('发表成功');history.go(-1);</script>", "text/html"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                ModelState.AddModelError("", "发布信息失败" + "再次尝试,如果问题仍然存在" + "请联系系统管理者.");
            }
            return(View(forum_msgViewModel));
        }