public IActionResult Create(QuestionnaireM questionnaireM) { string msg = ""; try { if (ModelState.IsValid) { questionnaireM.Rtt = DateTime.Now; _context.QuestionnaireMs.Add(questionnaireM); _context.SaveChanges(); return(View(questionnaireM)); } else { msg = ""; foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors)) { msg += error.ErrorMessage + Environment.NewLine; } throw new Exception(msg); } } catch (Exception ex) { msg = ex.Message; } return(BadRequest(msg)); }
public async Task <IViewComponentResult> InvokeAsync(int?id) { if (id == null) { id = -1; } QuestionnaireM questionnaireM = _context.QuestionnaireMs.Find(id); return(View(questionnaireM)); }
public ActionResult Update(QuestionnaireM questionnaireM) { if (ModelState.IsValid) { questionnaireM.Rtt = DateTime.Now; _context.Entry(questionnaireM).State = EntityState.Modified; _context.SaveChanges(); return(new JsonResult(questionnaireM) { Value = new { success = true, error = "" } }); } return(BadRequest("案件有誤!")); }
// GET: public IActionResult Create() { AppUserModel ur = _context.AppUsers.Where(u => u.UserName == this.User.Identity.Name).FirstOrDefault(); if (userManager.IsInRole(User, "Admin") || userManager.IsInRole(User, "MedMgr") || userManager.IsInRole(User, "MedAssetMgr")) { QuestionnaireM que = new QuestionnaireM(); que.Rtp = ur.Id; que.RtpName = ur.FullName; return(View(que)); } return(StatusCode(404)); }
// GET: MedEngMgt/QuestionnaireMs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(StatusCode(404)); } AppUserModel ur = _context.AppUsers.Where(u => u.UserName == User.Identity.Name).FirstOrDefault(); QuestionnaireM questionnaireM = _context.QuestionnaireMs.Find(id); questionnaireM.Rtp = ur.Id; questionnaireM.RtpName = ur.FullName; if (questionnaireM == null) { return(StatusCode(404)); } return(View(questionnaireM)); }