/// <summary> /// this method is used to add designations to the department /// </summary> /// <param name="departmentId">department id</param> /// <param name="designations">list of designations</param> /// <returns>string stating the status of the method</returns> public async Task <string> AddDesignationToDepartmentAsync(int departmentId, List <string> designations) { if (designations == null) { throw new Exception("Not Found. No designations added"); } var validDeptartment = await _designationRepository.GetDepartementDetailsAsync(departmentId); if (validDeptartment == null) { throw new Exception("NotFound.Requested department does not exist"); } var designationList = new List <Designation>(); foreach (var item in designations) { designationList.Add(new Designation { Title = item, IsDeleted = false }); } _designationRepository.AddDesignations(designationList); await _designationRepository.SaveChangesAsync(); var designationIds = _designationRepository.GetDesignationIds(designations); var departmentDesignationList = new List <DepartmentDesignation>(); foreach (var item in designationIds) { departmentDesignationList.Add(new DepartmentDesignation { DepartmentId = departmentId, DesignationId = item, IsDeleted = false }); } _departmentDesignationRepository.AddDepartmentDesignation(departmentDesignationList); await _departmentDesignationRepository.SaveChangesAsync(); return("Designations added successfully in the department"); }