コード例 #1
0
        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));
        }
コード例 #2
0
        public async Task <IViewComponentResult> InvokeAsync(int?id)
        {
            if (id == null)
            {
                id = -1;
            }

            QuestionnaireM questionnaireM = _context.QuestionnaireMs.Find(id);

            return(View(questionnaireM));
        }
コード例 #3
0
 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("案件有誤!"));
 }
コード例 #4
0
        // 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));
        }
コード例 #5
0
        // 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));
        }