コード例 #1
0
ファイル: DemoController.cs プロジェクト: hw3jung/BookRack
 public ActionResult Index()
 {
     DemoModel statusModel = new DemoModel();
     statusModel.StatusID = 0;
     statusModel.StatusName = "Default Text";
     return View(statusModel);
 }
コード例 #2
0
ファイル: DemoController.cs プロジェクト: hw3jung/BookRack
        public JsonResult InsertStatus(string status)
        {
            DemoModel statusModel = new DemoModel();
            statusModel.StatusName = status;
            statusModel.StatusID = 0;

            bool success = this._DemoHandler.InsertStatus(statusModel);
            if (success)
                return Json("Successfully inserted status: " + status);
            else
                return Json("Failed to insert status: " + status);
        }
コード例 #3
0
ファイル: DemoHandler.cs プロジェクト: hw3jung/BookRack
        public bool InsertStatus(DemoModel Status)
        {
            DataAccessLayer dal = new DataAccessLayer();
            bool Success = true;
            try
            {
                /* Testing Insert */
                Dictionary<string, string> dict = new Dictionary<string,string>();
                dict.Add("StatusName", Status.StatusName);
                // no need to add statusID, as that column is an identity column
                dal.insert(dict, "TransactionStatus");

                /* Testing Select */
                DataTable dt = new DataTable();
                dt = dal.select("StatusName = 'a'", "TransactionStatus");
                foreach (DataRow row in dt.Rows) // Loop over the rows.
                {
                    foreach (var col in row.ItemArray)
                    {
                        Debug.Write(col);
                    }
                    Debug.Write('\n');
                }

                /* Testing Update */
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add("StatusName", "'asma_rox'");
                dal.update("TransactionStatus", "StatusName = 'asma_sux'", d);
                /* Manually go into SQL Server to see if the row is correctly updated */

                /* Testing Delete */
                dal.delete("StatusName = 'johnny'", "TransactionStatus");
                /* now the db should not contain an entry with StatusName = 'johnny' */

            }
            catch (Exception)
            {
                Success = false;
            }
            return Success;
        }