コード例 #1
0
        public ActionResult AddTest(LabTestTable test)
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (Session["Lab"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            var lab = (LabTable)Session["Lab"];

            test.LabID = lab.LabID;
            if (ModelState.IsValid)
            {
                var findlab = db.LabTestTables.Where(i => i.Name == test.Name).FirstOrDefault();
                if (findlab == null)
                {
                    db.LabTestTables.Add(test);
                    db.SaveChanges();
                    return(RedirectToAction("LabAllTest"));
                }
                else
                {
                    ViewBag.Message = "Already Registered";
                }
            }

            return(View(test));
        }
コード例 #2
0
        public ActionResult EditTest(LabTestTable test)
        {
            if (string.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (Session["Lab"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (ModelState.IsValid)
            {
                var findlab = db.LabTestTables.Where(i => i.Name == test.Name && i.LabTestID != test.LabTestID).FirstOrDefault();
                if (findlab == null)
                {
                    db.Entry(test).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("LabAllTest"));
                }
                else
                {
                    ViewBag.Message = "Already Registered";
                }
            }

            return(View(test));
        }