public Guid SaveConnection(ConnectionModel data, SaveMode saveMode) { var connection = connectionRepository.Get(data.Id); if (saveMode == SaveMode.CreateNew) { if (connection != null) { throw new DataValidationException(MessageResource.Error_InsertDuplicateKey); } connection = new Connection(); connection.Id = Guid.NewGuid(); connectionRepository.Add(connection); } else { if (connection == null) { throw new DataValidationException(string.Format(MessageResource.Error_DataNotFoundForUpdate, "Connection")); } } var isDup = connectionRepository.GetAll().Where(t => t.Id != connection.Id && t.Name == data.Name).Any(); if (isDup) { throw new DataValidationException(string.Format(MessageResource.Error_UpdateDuplicateUniqeField, "Name")); } connection.DatabaseName = data.DatabaseName; connection.Description = data.Description; connection.Name = data.Name; if (data.IsSetPassword) { if (!string.IsNullOrEmpty(data.Password)) { connection.Password = CryptoHelper.EncryptText(data.Password); } else { connection.Password = null; } } connection.Server = data.Server; connection.LocalServer = data.LocalServer; connection.IsActive = data.IsActive; unitOfWork.SaveChanges(); return(connection.Id); }
public IEnumerable <Connection> Get() { return(_connectionRepository.Get()); }
public ResultDTO Index() { var connections = _connectionRepository.Get().Count(); return(new ResultDTO(true, "All connections", connections)); }