public ActionResult Edit(int id, DepartmentEntities departmentEntity)

        {
            try
            {
                departmentManager.EditDepartment(id, departmentEntity);
                if (departmentEntity != null)
                {
                    TempData["Update"] = "DepartmentEntity updated successfully";
                }               // for alert
            }
            catch (Exception e) // for error handling database action and show in bootstrap alert
            {
                #region Print error message on Index page in Bootstrap alert(danger)
                //if (e.Message != null) { TempData["Error"] = e.InnerException.InnerException.Message; }
                //else { TempData["Error"] = "Unknown"; }
                //return RedirectToAction("Index");
                #endregion

                //Using ModelState Object to check Server side Validations
                string msg = e.InnerException.InnerException.Message;
                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"));
        }
        public void UpdateDepartmentTestTooLongID()
        {
            IDepartmentManager departmentManager = new DepartmentManager(_departmentAccessor);
            Department         department        = new Department
            {
                DepartmentID = "Fake Department",
                Description  = "Fake Description"
            };
            Department anotherDepartment = new Department
            {
                DepartmentID = "111111111111111111111111111111111111111111111111111",
                Description  = "Fake Description"
            };

            bool result = departmentManager.EditDepartment(department, anotherDepartment);

            Assert.AreEqual(false, result);
        }
        public void UpdateDepartmentTestNoMatchID()
        {
            IDepartmentManager departmentManager  = new DepartmentManager(_departmentAccessor);
            Department         mismatchDepartment = new Department
            {
                DepartmentID = "firstDepartment",
                Description  = "A Description"
            };
            Department otherDepartment = new Department
            {
                DepartmentID = "secondDepartment",
                Description  = "A new Description"
            };

            bool result = departmentManager.EditDepartment(mismatchDepartment, otherDepartment);

            Assert.AreEqual(false, result);
        }
        public void UpdateDepartmentTestDepartmentNotFound()
        {
            IDepartmentManager departmentManager = new DepartmentManager(_departmentAccessor);

            Department missingDepartment = new Department
            {
                DepartmentID = "Missing",
                Description  = "None"
            };
            Department newDepartment = new Department
            {
                DepartmentID = "Missing",
                Description  = "Other"
            };
            bool result = departmentManager.EditDepartment(missingDepartment, newDepartment);

            Assert.AreEqual(false, result);
        }
Beispiel #5
0
 public async Task <ActionResult <Result> > EditDepartment([FromForm] DepartmentViewModel DepartmentViewModel)
 {
     try
     {
         var Result = _DepartmentManager.EditDepartment(DepartmentViewModel, GetUserName());
         return(await Result);
     }
     catch (Exception ex)
     {
         _exceptionManager.SaveLog(Request.Path, DepartmentViewModel, ex, GetUserName());
         return(new Result()
         {
             IsSuccess = false,
             Errors = new List <string> {
                 Resources.ExceptionMessage
             }
         });
     }
 }
        public void TestFailedConnectionEditDepatrment()
        {
            IDepartmentManager departmentManager = new DepartmentManager(_brokenDepartmentAccessor);
            string             goodID            = "Fake";
            string             goodDescription   = "Fake Description";
            string             otherDescription  = "Other Words";



            departmentManager.EditDepartment(
                new Department
            {
                DepartmentID = goodID,
                Description  = goodDescription
            },
                new Department
            {
                DepartmentID = goodID,
                Description  = otherDescription
            }
                );
        }