public GeneralResponse DeleteCenter(IEnumerable <DeleteRequest> requests) { GeneralResponse response = new GeneralResponse(); foreach (var request in requests) { Center center = new Center(); center = _centerRepository.FindBy(request.ID); if (center != null) { try { #region Remove Dependencies Infrastructure.Querying.Query query = new Infrastructure.Querying.Query(); Criterion criterion = new Criterion("Center.ID", center.ID, CriteriaOperator.Equal); query.Add(criterion); IEnumerable <Code> codesOfThisCenter = _codeRepository.FindBy(query); if (codesOfThisCenter != null) { _codeRepository.Remove(codesOfThisCenter); } Infrastructure.Querying.Query query2 = new Infrastructure.Querying.Query(); Criterion criterion2 = new Criterion("Center.ID", center.ID, CriteriaOperator.Equal); query.Add(criterion); IEnumerable <NetworkCenter> networkCenters = _networkCenterRepository.FindBy(query); if (networkCenters != null) { _networkCenterRepository.Remove(networkCenters); } _uow.Commit(); #endregion _centerRepository.Remove(center); _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { //response.ErrorMessages.Add("INNER EX: " + ex.InnerException.Message); response.ErrorMessages.Add("این مرکز شامل یک یا تعدادی مشتری ثبت شده میباشد"); } return(response); } } else { response.ErrorMessages.Add("NoItemToDeleteKey"); return(response); } } return(response); }