예제 #1
0
 public void DeleteDepartment(Department department)
 {
     try
     {
         schoolRepository.DeleteDepartment(department);
     }
     catch (Exception ex)
     {
         //Include catch blocks for specific exceptions first,
         //and handle or log the error as appropriate in each.
         //Include a generic catch block like this one last.
         throw ex;
     }
 }
 public void UpdateDepartment(Department department, Department origDepartment)
 {
     try
     {
         context.Departments.Attach(origDepartment);
         context.ApplyCurrentValues("Departments", department);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         //Include catch blocks for specific exceptions first,
         //and handle or log the error as appropriate in each.
         //Include a generic catch block like this one last.
         throw ex;
     }
 }
 public void InsertDepartment(Department department)
 {
     try
     {
         department.DepartmentID = GenerateDepartmentID();
         context.Departments.AddObject(department);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         //Include catch blocks for specific exceptions first,
         //and handle or log the error as appropriate in each.
         //Include a generic catch block like this one last.
         throw ex;
     }
 }
 /// <summary>
 /// Create a new Department object.
 /// </summary>
 /// <param name="departmentID">Initial value of the DepartmentID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="budget">Initial value of the Budget property.</param>
 /// <param name="startDate">Initial value of the StartDate property.</param>
 public static Department CreateDepartment(global::System.Int32 departmentID, global::System.String name, global::System.Decimal budget, global::System.DateTime startDate)
 {
     Department department = new Department();
     department.DepartmentID = departmentID;
     department.Name = name;
     department.Budget = budget;
     department.StartDate = startDate;
     return department;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Departments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDepartments(Department department)
 {
     base.AddObject("Departments", department);
 }
 public void UpdateDepartment(Department department, Department origDepartment)
 {
     departments.Remove(origDepartment);
     departments.Add(department);
 }
 public void InsertDepartment(Department department)
 {
     departments.Add(department);
 }
 public void DeleteDepartment(Department department)
 {
     departments.Remove(department);
 }
예제 #9
0
 public void InsertDepartment(Department department)
 {
     ValidateOneAdministratorAssignmentPerInstructor(department);
     try
     {
         schoolRepository.InsertDepartment(department);
     }
     catch (Exception ex)
     {
         //Include catch blocks for specific exceptions first,
         //and handle or log the error as appropriate in each.
         //Include a generic catch block like this one last.
         throw ex;
     }
 }
예제 #10
0
 private void ValidateOneAdministratorAssignmentPerInstructor(Department department)
 {
     if (department.Administrator != null)
     {
         var duplicateDepartment = schoolRepository.GetDepartmentsByAdministrator(department.Administrator.GetValueOrDefault()).FirstOrDefault();
         if (duplicateDepartment != null && duplicateDepartment.DepartmentID != department.DepartmentID)
         {
             throw new DuplicateAdministratorException(String.Format(
                 "Instructor {0} {1} is already administrator of the {2} department.",
                 duplicateDepartment.Person.FirstMidName,
                 duplicateDepartment.Person.LastName,
                 duplicateDepartment.Name));
         }
     }
 }