예제 #1
0
        public ActionResult Create()
        {
            deptModels dept = new deptModels();

            ModelState.Clear();

            return(View(dept));
        }
예제 #2
0
 public ActionResult Update(deptModels dept)
 {
     if (dept.IdDept == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     else
     {
         deptRepos repos = new deptRepos();
         repos.EditDept(dept);
         return(Json(new { success = true, message = "Update Successfully" }, JsonRequestBehavior.AllowGet));
         //return RedirectToAction("Index");
     }
 }
예제 #3
0
 public void AddDept(deptModels dept)
 {
     try
     {
         string query = string.Format("" +
                                      "INSERT INTO mDept(IdDept,NamaDept)" +
                                      "VALUES('" + dept.IdDept + "'," +
                                      "'" + dept.NamaDept + "')");
         dbAccess.strConn = conn;
         dbAccess.ExecQuery(query);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #4
0
 public void EditDept(deptModels dept)
 {
     try
     {
         string query = string.Format("" +
                                      "UPDATE mDept " +
                                      "SET NamaDept = '" + dept.NamaDept + "'" +
                                      "WHERE IdDept = '" + dept.IdDept + "'");
         dbAccess.strConn = conn;
         dbAccess.ExecQuery(query);
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #5
0
        public ActionResult Create(deptModels dept)
        {
            try
            {
                deptRepos repo = new deptRepos();
                if (dept == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                var IdDept   = dept.IdDept.Trim().ToUpper();
                var NamaDept = dept.NamaDept.Trim().ToUpper();

                if (IdDept == null || IdDept == "")
                {
                    throw new Exception("ID Dept empty !");
                }

                if (NamaDept == "")
                {
                    throw new Exception("Nama Department empty !");
                }

                bool isValid = repo.isDeptExist(IdDept);
                if (isValid)
                {
                    throw new Exception("Data Exist !");
                }

                var ObjDept = new deptModels {
                    IdDept = IdDept, NamaDept = NamaDept
                };

                repo.AddDept(ObjDept);
                this.AddToastMessage("", "Data saved", ToastType.Success);
                return(Redirect("~/Dept/Index"));
            }
            catch (Exception ex)
            {
                this.AddToastMessage("Error", ex.Message, ToastType.Error);
                //ModelState.AddModelError(string.Empty, ex.Message);
                return(View(dept));
            }
        }