public GeneralResponse GetLocalPhoneStoresFromAsterisk() { GeneralResponse response = new GeneralResponse(); try { MonitoringControllerService monitoring = new MonitoringControllerService(); string Token = monitoring.login("saman", "102030"); List <DeviceWSDL> devices = monitoring.getDevice(Token).ToList <DeviceWSDL>(); List <LocalPhoneStore> savedLocalPhoneStores = _localPhoneStoreRepository.FindAll().ToList <LocalPhoneStore>(); foreach (var item in devices) { foreach (var _item in savedLocalPhoneStores) { if (item.dialString == _item.AsteriskID) { _item.LocalPhoneStoreNumber = item.name; _localPhoneStoreRepository.Save(_item); } } } if (devices.Count() > savedLocalPhoneStores.Count()) { var result = devices.Where(x => savedLocalPhoneStores.All(s => s.AsteriskID != x.dialString)); foreach (var item in result) { LocalPhoneStore localPhoneStore = new LocalPhoneStore(); localPhoneStore.AsteriskID = item.dialString ?? string.Empty; localPhoneStore.ID = Guid.NewGuid(); localPhoneStore.LocalPhoneStoreNumber = item.name; localPhoneStore.Reserved = false; _localPhoneStoreRepository.Add(localPhoneStore); } } if (devices.Count() < savedLocalPhoneStores.Count()) { IEnumerable <LocalPhoneStore> queueLocalPhone = _localPhoneStoreRepository.FindAll(); var result = queueLocalPhone.Where(x => devices.All(s => s.id != x.AsteriskID)); foreach (var item in result) { _localPhoneStoreRepository.Remove(item); } } _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { response.ErrorMessages.Add(ex.InnerException.Message); } } return(response); }
public GeneralResponse AddLocalPhoneStoreEmployee(IEnumerable <AddLocalPhoneStoreEmployeeRequest> requests, Guid OwnerEmployeeID, Guid CreateEployeeID) { GeneralResponse response = new GeneralResponse(); try { foreach (var request in requests) { Query localPhoneStoreEployeeQuery = new Query(); Criterion crt = new Criterion("LocalPhoneStore.ID", request.LocalPhoneStoreID, CriteriaOperator.Equal); localPhoneStoreEployeeQuery.Add(crt); Response <LocalPhoneStoreEmployee> localPhoneStoreEmployeeSaved = _localPhoneStoreEployeeRepository.FindByQuery(localPhoneStoreEployeeQuery); if (localPhoneStoreEmployeeSaved.totalCount > 0) { response.ErrorMessages.Add("این شماره داخلی قبلا برای کارمند دیگری تعریف شده است"); return(response); } LocalPhoneStoreEmployee localPhoneStoreEmployee = new LocalPhoneStoreEmployee(); localPhoneStoreEmployee.ID = Guid.NewGuid(); localPhoneStoreEmployee.CreateDate = PersianDateTime.Now; localPhoneStoreEmployee.CreateEmployee = _employeeRepository.FindBy(CreateEployeeID); localPhoneStoreEmployee.DangerousRing = request.DangerousRing; localPhoneStoreEmployee.DangerousSeconds = request.DangerousSeconds; localPhoneStoreEmployee.LocalPhoneStore = _localPhoneStoreRepository.FindBy(request.LocalPhoneStoreID); localPhoneStoreEmployee.OwnerEmployee = _employeeRepository.FindBy(OwnerEmployeeID); localPhoneStoreEmployee.SendSmsToOffLineUserOnDangerous = request.SendSmsToOffLineUserOnDangerous; localPhoneStoreEmployee.SendSmsToOnLineUserOnDangerous = request.SendSmsToOnLineUserOnDangerous; localPhoneStoreEmployee.SmsText = request.SmsText; localPhoneStoreEmployee.RowVersion = 1; _localPhoneStoreEployeeRepository.Add(localPhoneStoreEmployee); #region برچسب رزرو شده به لیست شماره های داخلی LocalPhoneStore localPhoneStore = _localPhoneStoreRepository.FindBy(request.LocalPhoneStoreID); localPhoneStore.Reserved = true; _localPhoneStoreRepository.Save(localPhoneStore); #endregion } _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { response.ErrorMessages.Add(ex.InnerException.Message); } } return(response); }