Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            IssueID = int.Parse(Request.Query["id"]);
            Issue   = await _context.Issue.Where(m => m.IssueId == IssueID).FirstOrDefaultAsync();

            Answer.Issue = Issue;
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            byte[] result;
            HttpContext.Session.TryGetValue("CurrentUser", out result);
            if (result == null)
            {
                ModelState.AddModelError("ULogin", "需要登录才能继续操作!");
                Message = "需要登录才能继续操作!";
                return(Page());
            }
            Answer.Name      = System.Text.Encoding.UTF8.GetString(result);
            Answer.Email     = Answer.Name;
            Answer.CreatedBy = Answer.Name;
            Answer.CreatedOn = DateTime.Now;
            _context.Answer.Add(Answer);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./IssueDetail", new { id = Request.Query["id"] }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync([FromForm] Issue issue)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            byte[] result;
            HttpContext.Session.TryGetValue("CurrentUser", out result);
            if (result == null)
            {
                ModelState.AddModelError("ULogin", "需要登录才能继续操作!");
                Message = "需要登录才能继续操作!";
                return(Page());
            }
            issue.CommitBy  = System.Text.Encoding.UTF8.GetString(result);
            issue.CommitOn  = DateTime.Now;
            issue.CreatedBy = issue.CommitBy;
            issue.CreatedOn = DateTime.Now;
            _context.Issue.Add(issue);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }