public List <DepartmentOptionResult> GetDepartmentOptions(int departmentId) { List <DepartmentOptionResult> result = new List <DepartmentOptionResult>(); if (departmentId == 0 && IsSystem) { // Get All var departments = _departmentsService.GetAll(); foreach (var department in departments) { var emailSettings = _departmentsService.GetDepartmentEmailSettings(department.DepartmentId); var optionsResult = new DepartmentOptionResult(); optionsResult.DepartmentId = department.DepartmentId; optionsResult.EmailFormatType = emailSettings.FormatType; result.Add(optionsResult); } return(result); } else if (departmentId >= 1) { if (departmentId == DepartmentId) { var emailSettings = _departmentsService.GetDepartmentEmailSettings(departmentId); var optionsResult = new DepartmentOptionResult(); optionsResult.DepartmentId = departmentId; optionsResult.EmailFormatType = emailSettings.FormatType; result.Add(optionsResult); return(result); } else { throw HttpStatusCode.Unauthorized.AsException(); } } else { throw HttpStatusCode.BadRequest.AsException(); } }
public async Task <ActionResult <List <DepartmentOptionResult> > > GetDepartmentOptions(int departmentId) { List <DepartmentOptionResult> result = new List <DepartmentOptionResult>(); if (departmentId == 0 && IsSystem) { // Get All var departments = await _departmentsService.GetAllAsync(); foreach (var department in departments) { var emailSettings = await _departmentsService.GetDepartmentEmailSettingsAsync(department.DepartmentId); var optionsResult = new DepartmentOptionResult(); optionsResult.DepartmentId = department.DepartmentId; optionsResult.EmailFormatType = emailSettings.FormatType; result.Add(optionsResult); } return(result); } else if (departmentId >= 1) { if (departmentId == DepartmentId) { var emailSettings = await _departmentsService.GetDepartmentEmailSettingsAsync(departmentId); var optionsResult = new DepartmentOptionResult(); optionsResult.DepartmentId = departmentId; optionsResult.EmailFormatType = emailSettings.FormatType; result.Add(optionsResult); return(result); } else { return(Unauthorized()); } } else { return(BadRequest()); } }