/// <summary> /// Creator: Jordan Lindo /// Created: 2/6/2020 /// Approver: Alex Diers /// /// This is the method to update a department. /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Approver: NA /// /// </remarks> /// <param name="oldDepartmentId"></param> /// <param name="newDepartmentId"></param> /// <returns></returns> public bool EditDepartment(Department oldDepartment, Department newDepartment) { bool result = false; if (oldDepartment.DepartmentID.Equals(newDepartment.DepartmentID) && ValidateERole.checkDepartmentID(oldDepartment.DepartmentID) && ValidateERole.checkDepartmentID(newDepartment.DepartmentID) && ValidateERole.checkDescription(oldDepartment.Description) && ValidateERole.checkDescription(newDepartment.Description)) { List <Department> departments = RetrieveAllDepartments(); foreach (Department department in departments) { if (department.DepartmentID == oldDepartment.DepartmentID && department.Description == oldDepartment.Description) { try { result = (1 == _departmentAccessor.UpdateDepartment(oldDepartment, newDepartment)); } catch (Exception ex) { throw new ApplicationException("Department Data Not Found", ex); } } } } return(result); }
/// <summary> /// Creator: Jordan Lindo /// Created: 2/15/2020 /// Approver: Alex Diers /// /// This button click listener sends the data for creating a new department record to the logic layer /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddDepartmentSave_Click(object sender, RoutedEventArgs e) { string departmentID = txtAddDepartmentDepartmentName.Text; string description = txtAddDepartmentDescription.Text; if (ValidateERole.checkDepartmentID(departmentID) && ValidateERole.checkDescription(description)) { try { if (_departmentManager.AddDepartment(departmentID, description)) { ShiftTimeManager _shiftTimeManger = new ShiftTimeManager(); try { foreach (PetUniverseShiftTime shiftTime in DEFAULT_SHIFTTIMES) { shiftTime.DepartmentID = departmentID; _shiftTimeManger.AddShiftTime(shiftTime); } } catch (Exception ex) { WPFErrorHandler.ErrorMessage("failed to save departments Default Shift Times. " + ex.Message); } WPFErrorHandler.SuccessMessage("Department added, with default shift times"); canAddDepartment.Visibility = Visibility.Hidden; canDepartmentList.Visibility = Visibility.Visible; showDGDepartments(); } else { WPFErrorHandler.ErrorMessage("Department not added."); } } catch (Exception ex) { WPFErrorHandler.ErrorMessage("Department failed to save. " + ex.Message); } }
/// <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); }