예제 #1
0
        public ActionResult Insert_Staff(Staff s)
        {
            if (ModelState.IsValid)
            {
                TempData["StaffModel"] = s;
                try
                {
                    if (!StaffTool.InsertStaff(s))
                    {
                        TempData["ERROR"] = "Insert Fail, Error at Model";

                        return(RedirectToAction("Insert_Staff"));
                    }
                }
                catch (SqlException ex)
                {
                    if (ex.Message.Contains("duplicate"))
                    {
                        TempData["DUPLICATE"] = "Existed Username, please try again";
                    }
                    else
                    {
                        TempData["ERROR"] = "Insert Fail, SQL ERROR";
                    }
                    return(RedirectToAction("Insert_Staff"));
                }
                catch (Exception)
                {
                    TempData["ERROR"] = "Insert Fail, Unexpected ERROR";
                    return(RedirectToAction("Insert_Staff"));
                }


                return(RedirectToAction("Show_Staff"));
            }
            else
            {
                return(View());
            }
        }