コード例 #1
0
        // GET: Medicines
        public ActionResult Index(string name)
        {
            ControllerMedicine instance = ControllerMedicine.getInstance();

            instance.loadData();
            //ViewBag.MedicineList = instance.listMedicine;
            return(View(instance.listMedicine));
        }
コード例 #2
0
        // GET: Medicine
        public ActionResult Index(string name, string id, string freq, string qty, string msr, string srtD, string endD)
        {
            if (Request.Form["option"] != null)
            {
                ControllerMedicine instance = ControllerMedicine.getInstance();

                if (Request.Form["option"].Equals("edit"))
                {
                    Recipe   recipe   = new Recipe();
                    Medicine medicine = new Medicine();
                    medicine.name    = Request.Form["medName"];
                    medicine.measure = Request.Form["medMsr"];
                    recipe.medicine  = medicine;

                    recipe.quantity  = int.Parse(Request.Form["medQty"]);
                    recipe.frequency = int.Parse(Request.Form["medFreq"]);
                    recipe.startDate = DateTime.ParseExact(Request.Form["medStrD"], "yyyy-mm-dd",
                                                           System.Globalization.CultureInfo.InvariantCulture);

                    instance.updateMedicine(recipe);

                    return(RedirectToAction("Index", "Medicines"));
                }
                if (Request.Form["option"].Equals("delete"))
                {
                    return(RedirectToAction("Index", "Medicines"));
                }
                if (Request.Form["option"].Equals("add"))
                {
                    Recipe   recipe   = new Recipe();
                    Medicine medicine = new Medicine();
                    medicine.name    = Request.Form["medName"];
                    medicine.measure = Request.Form["medMsr"];
                    recipe.medicine  = medicine;

                    recipe.quantity  = int.Parse(Request.Form["medQty"]);
                    recipe.frequency = int.Parse(Request.Form["medFreq"]);

                    Debug.Print(instance.user.email);

                    Debug.Print(Request.Form["medStrD"]);
                    recipe.startDate = DateTime.ParseExact(Request.Form["medStrD"], "yyyy-mm-dd",
                                                           System.Globalization.CultureInfo.InvariantCulture);
                    recipe.endDate = DateTime.ParseExact(Request.Form["medEndD"], "yyyy-mm-dd",
                                                         System.Globalization.CultureInfo.InvariantCulture);

                    instance.addMedicine(recipe);
                    return(RedirectToAction("Index", "Medicines"));
                }
            }

            if (id == "new")
            {
                ViewBag.addNew = true;
                ViewBag.id     = null;
            }
            else
            {
                ViewBag.addNew = false;
                ViewBag.id     = id;
            }

            ViewBag.name = name;
            ViewBag.freq = freq;
            ViewBag.qty  = qty;
            ViewBag.msr  = msr;
            ViewBag.srtD = srtD;
            ViewBag.endD = endD;

            return(View());
        }