Exemplo n.º 1
0
        public JsonResult UpdateDatabase(EResDatabaseViewModel viewModel)
        {
            bool   bReturn = false;
            string message = "failed";

            EResDatabase myDb = _db.EResDatabases.Find(viewModel.DatabaseID);

            if (myDb != null)
            {
                myDb.DatabaseName  = viewModel.DatabaseName;
                myDb.VendorID      = viewModel.VendorID;
                myDb.DatabaseType  = viewModel.DatabaseType;
                myDb.DatabaseCost  = viewModel.DatabaseCost;
                myDb.FundingSource = viewModel.FundingSource;

                try
                {
                    _db.SaveChanges();

                    bReturn = true;
                    message = "success";
                }
                catch (InvalidOperationException ex)
                {
                    message = ex.Message;
                }
            }

            return(Json(new
            {
                Success = bReturn,
                Message = message,
                SelectList = _db.EResDatabasesDropdown()
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult CreateDatabase(EResDatabaseViewModel viewModel)
        {
            bool   bReturn = false;
            string message = "failed";

            // TODO: Add insert logic here
            EResDatabase newDb = new EResDatabase()
            {
                DatabaseName  = viewModel.DatabaseName,
                VendorID      = viewModel.VendorID,
                DatabaseType  = viewModel.DatabaseType,
                DatabaseCost  = viewModel.DatabaseCost,
                FundingSource = viewModel.FundingSource
            };

            if (_db.EResDatabases.Add(newDb) != null)
            {
                if (_db.SaveChanges() > 0)
                {
                    bReturn = true;
                    message = "success";
                }
            }

            return(Json(new
            {
                Success = bReturn,
                Message = message,
                SelectList = _db.EResDatabasesDropdown()
            }, JsonRequestBehavior.AllowGet));
        }