Example #1
0
        /// <summary author="Austin Berquam" created="2019/02/06">
        /// Method that creates a department through the accessor
        /// </summary>
        /// <param name="department">Object department to create</param>
        /// <returns> bool on if the department was created </returns>
        public bool CreateDepartment(Department department)
        {
            ValidationExtensionMethods.ValidateID(department.DepartmentID);
            ValidationExtensionMethods.ValidateDescription(department.Description);
            bool result = false;

            try
            {
                result = (1 == departmentAccessor.InsertDepartment(department));
            }
            catch (Exception ex)
            {
                ExceptionLogManager.getInstance().LogException(ex);
                throw ex;
            }
            return(result);
        }
        /// <summary>
        /// Creator: Jordan Lindo
        /// Created: 2/6/2020
        /// Approver: Alex Diers
        ///
        /// This is the method to add a department.
        /// </summary>
        /// <remarks>
        /// Updater: Jordan Lindo
        /// Updated: Added reactivation and update description.
        /// Updated: Standarized exception handling.
        /// Approver: NA
        ///
        /// </remarks>
        /// <param name="departmentId"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public bool AddDepartment(string departmentId, string description)
        {
            bool added = false;


            if (null != departmentId && ValidateERole.checkDepartmentID(departmentId) && ValidateERole.checkDescription(description))
            {
                try
                {
                    Department department = _departmentAccessor.SelectDepartmentByID(departmentId);

                    if (null == department)
                    {
                        if (_departmentAccessor.InsertDepartment(departmentId, description) == 1)
                        {
                            added = true;
                        }
                    }
                    else if (_departmentAccessor.SelectDeactivatedDepartments().Contains(departmentId))
                    {
                        if (EditDepartmentActive(departmentId, true))
                        {
                            Department aDepartment = new Department
                            {
                                DepartmentID = departmentId,
                                Description  = description
                            };
                            if (EditDepartment(department, aDepartment))
                            {
                                added = true;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Department Not Added.", ex);
                }
            }
            return(added);
        }