Beispiel #1
0
    //添加
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (this.txtDepartmentName.Text == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('部门不能为空');</script>");
            return;
        }
        Department dep = new Department();

        dep.DepartmentId   = Guid.NewGuid().ToString();
        dep.DepartmentName = this.txtDepartmentName.Text;
        dep.Account        = AccountsManager.GetAccountByAccountId(oepr.Account.AccountId);
        dep.IsDefault      = false;
        dep.AddDate        = DateTime.Now.ToString();
        bool b = DepartmentManager.AddDepartment(dep);

        if (b)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('添加成功'); window.location='DepartmentManager.aspx';</script>");
            return;
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script>alert('已经存在此部门');</script>");
            return;
        }
    }
        public ActionResult Create(DepartmentEntities departmentEntity)
        {
            try
            {
                departmentManager.AddDepartment(departmentEntity);
                if (departmentEntity != null)
                {
                    TempData["Success"] = "Department created successfully";
                }                                                                                          // for alert
                //return RedirectToAction("Index");
            }
            catch (Exception e) // for error handling database action and show in bootstrap alert
            {
                #region Print error message on Index page in Bootstrap alert(danger)
                string msg = e.InnerException.InnerException.Message;
                //if (e.Message != null) { TempData["Error"] = e.InnerException.InnerException.Message; }
                //else { TempData["Error"] = "Unknown"; }
                #endregion

                //Using ModelState Object to check Server side Validations
                if (msg.Contains("Violation of UNIQUE KEY constraint"))
                {
                    // ViewBag.UserEmailValidation = "User Email already exists. Please choose another Email.";
                    ModelState.AddModelError("Code", "Department Code already exists. Please enter a different code.");
                    return(View(departmentEntity));
                }
            }
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult Create(Department department)
        {
            if (ModelState.IsValid)
            {
                if (_departmentManager.IsDepartmentCodeExist(department.DepartmentCode))
                {
                    FlashMessage.Danger("Department code already exist");
                    return(View(department));
                }

                if (_departmentManager.IsDepartmentNameExist(department.DepartmentName))
                {
                    FlashMessage.Danger("Department name already exist");
                    return(View(department));
                }

                if (_departmentManager.AddDepartment(department))
                {
                    FlashMessage.Confirmation("Department saved successfully");
                    return(RedirectToAction("Create"));
                }
                FlashMessage.Danger("Some error occured, please try again later");
                return(View(department));
            }
            FlashMessage.Danger("Some error occured please check all the inputs.");
            return(View(department));
        }
 private void SetupDepartments()
 {
     Assert.True(DbContext.Departments.Count() == 0);
     DepartmentManager.AddDepartment("deptName1");
     DepartmentManager.AddDepartment("deptName2");
     Assert.True(DbContext.Departments.ToList().Count == 2);
     Assert.True(DbContext.Departments.Any(d => d.DepartmentName == "deptName1"));
     Assert.True(DbContext.Departments.Any(d => d.DepartmentName == "deptName2"));
 }
 public IActionResult Create([Bind("Id,DepartmentName")] Department department)
 {
     if (ModelState.IsValid)
     {
         _deptMgr.AddDepartment(department.DepartmentName);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(department));
 }
        public void TestFailedConnectionAddDepatrment()
        {
            IDepartmentManager departmentManager = new DepartmentManager(_brokenDepartmentAccessor);
            string             goodID            = "Fake";
            string             goodDescription   = "Fake Description";


            departmentManager.AddDepartment(goodID, goodDescription);
        }
        public void AddDepartmentTestTooLongIDEdge()
        {
            string             tooLong           = "111111111111111111111111111111111111111111111111111";
            string             goodDescription   = "Good description Test";
            IDepartmentManager departmentManager = new DepartmentManager(_departmentAccessor);

            bool result = departmentManager.AddDepartment(tooLong, goodDescription);

            Assert.AreEqual(false, result);
        }
        public void AddDepartmentTestBadRepeatId()
        {
            string             badDepartmentId   = "Fake Department";
            string             goodDescription   = "Good description Test";
            IDepartmentManager departmentManager = new DepartmentManager(_departmentAccessor);

            bool result = departmentManager.AddDepartment(badDepartmentId, goodDescription);

            Assert.AreEqual(false, result);
        }
        public void AddDepartmentTestGood()
        {
            string             goodDepartmentId  = "Good departmentId Test";
            string             goodDescription   = "Good description Test";
            IDepartmentManager departmentManager = new DepartmentManager(_departmentAccessor);

            bool result = departmentManager.AddDepartment(goodDepartmentId, goodDescription);

            Assert.AreEqual(true, result);
        }
        public void AddDepartmentTestTooLongDescription()
        {
            string tooLong = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" +
                             "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
            string             goodDepartmentId  = "Good departmentId Test";
            IDepartmentManager departmentManager = new DepartmentManager(_departmentAccessor);

            bool result = departmentManager.AddDepartment(goodDepartmentId, tooLong);

            Assert.AreEqual(false, result);
        }
        public void GetDepartmentTest()
        {
            string deptName = "deptName1";

            Assert.True(DbContext.Departments.Count() == 0);
            DepartmentManager.AddDepartment(deptName);
            Assert.True(DbContext.Departments.Count() == 1);

            var dept = DepartmentManager.GetDepartmentByName(deptName);

            Assert.Equal(dept.DepartmentName, deptName);
        }
 public int AddDepartment(Department department)
 {
     try
     {
         return(_departmentManager.AddDepartment(department));
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
        public void AddDepartmentTestTooLongID()
        {
            string tooLong = "012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970" +
                             "012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970" +
                             "012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970";
            string             goodDescription   = "Good description Test";
            IDepartmentManager departmentManager = new DepartmentManager(_departmentAccessor);

            bool result = departmentManager.AddDepartment(tooLong, goodDescription);

            Assert.AreEqual(false, result);
        }
Beispiel #14
0
        private void ok_Click(object sender, EventArgs e)
        {
            Department        department = new Department();
            DepartmentManager dManager   = new DepartmentManager();

            department.DepartmentName   = textBox1_DepartmentName.Text;
            department.DepartmentNumber = textBox2_DepartmentID.Text.Trim();
            if (dManager.AddDepartment(department))
            {
                MessageBox.Show("添加成功!");
            }

            this.Close();
        }
Beispiel #15
0
        private bool tryPost(ref Model.Department model, out string errMsg)
        {
            errMsg = "";
            bool re = false;

            model.Creater      = this.auth.UserId;
            model.CreatedDate  = DateTime.Now;
            model.Modifier     = this.auth.UserId;
            model.ModifiedDate = DateTime.Now;
            if (DepartmentManager.AddDepartment(ref model, out errMsg))
            {
                re = true;
            }
            return(re);
        }
Beispiel #16
0
 public IHttpActionResult post([FromBody] DepartmentModel value)
 {
     if (ModelState.IsValid)
     {
         bool succsess = departmentBll.AddDepartment(value);
         if (succsess)
         {
             return(Ok());
         }
         return(BadRequest());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
        public void UpdateDepartmentTest()
        {
            string deptName       = "deptName1";
            string deptNameUpdate = "deptNameUpdated";

            Assert.True(DbContext.Departments.Count() == 0);

            DepartmentManager.AddDepartment(deptName);
            Assert.True(DbContext.Departments.Count() == 1);

            var dept = DepartmentManager.GetDepartmentByName(deptName);

            Assert.Equal(dept.DepartmentName, deptName);

            dept.DepartmentName = deptNameUpdate;
            DepartmentManager.UpdateDepartmemt(dept);

            var updated = DepartmentManager.GetDepartmentByName(deptNameUpdate);

            Assert.Equal(updated.DepartmentName, deptNameUpdate);
        }
 public ActionResult SaveDepartment(Department aDepartment)
 {
     ViewBag.Result = departmentManager.AddDepartment(aDepartment);
     return(View());
 }