コード例 #1
0
        public ActionResult PostAddDrugsAdmin(DrugViewModel model)
        {
            using (ProjectEntities1 db = new ProjectEntities1())
            {
                /* if (ModelState.IsValid)
                 * {*/

                if (!ModelState.IsValid)
                {
                    return(View("AddDrugsAdmin"));
                }

                Boolean isdeleted = false;
                var     getdata   = db.Drugs.FirstOrDefault(a => a.DrugId == model.DrugId);
                if (getdata != null)
                {
                    db.UpadateDrug(model.DrugId, model.DrugName, model.ManufactureDate, model.ExpiredDate, model.UsedFor,
                                   model.SideEffects, model.TotalQuantityAvailable, isdeleted);
                    ViewBag.Message = "Updated";
                }
                else
                {
                    db.InsertDrug(model.DrugName, model.ManufactureDate, model.ExpiredDate, model.UsedFor,
                                  model.SideEffects, model.TotalQuantityAvailable, isdeleted);
                    ViewBag.Message = "Inserted";
                }
                return(View("AddDrugsAdmin"));
            }

            /*  else
             * {
             *    return View("AddDrugsAdmin");
             * }*/
        }