public bool UpdateConnection(ConnectionModel model, bool isForExport) { var connection = _connectionRepository.GetById(model.Id); if (connection == null) { return(false); } connection.IsActive = model.IsActive; connection.PublicKey = model.PublicKey; connection.SecretKey = model.SecretKey; connection.UpdatedOnUtc = DateTime.UtcNow; connection.Url = model.Url; if (isForExport) { connection.LimitedToManufacturerIds = string.Join(",", model.LimitedToManufacturerIds ?? new int[0]); connection.LimitedToStoreIds = string.Join(",", model.LimitedToStoreIds ?? new int[0]); } _connectionRepository.Update(connection); ConnectionCache.Remove(); return(true); }
public ShopConnectorConnectionRecord InsertConnection(ConnectionModel model) { var utcNow = DateTime.UtcNow; ShopConnectorConnectionRecord connection = null; if (model.IsForExport) { var hmac = new HmacAuthentication(); string publicKey, secretKey; for (var i = 0; i < 9999; ++i) { if (hmac.CreateKeys(out publicKey, out secretKey) && !_connectionRepository.TableUntracked.Any(x => x.PublicKey == publicKey)) { connection = new ShopConnectorConnectionRecord { IsActive = true, IsForExport = model.IsForExport, Url = model.Url, PublicKey = publicKey, SecretKey = secretKey, LimitedToManufacturerIds = string.Join(",", model.LimitedToManufacturerIds ?? new int[0]), LimitedToStoreIds = string.Join(",", model.LimitedToStoreIds ?? new int[0]), CreatedOnUtc = utcNow, UpdatedOnUtc = utcNow }; break; } } } else { connection = new ShopConnectorConnectionRecord { IsActive = true, IsForExport = model.IsForExport, Url = model.Url, PublicKey = model.PublicKey, SecretKey = model.SecretKey, LimitedToManufacturerIds = string.Join(",", model.LimitedToManufacturerIds ?? new int[0]), LimitedToStoreIds = string.Join(",", model.LimitedToStoreIds ?? new int[0]), CreatedOnUtc = utcNow, UpdatedOnUtc = utcNow }; } if (connection != null) { _connectionRepository.Insert(connection); ConnectionCache.Remove(); } return(connection); }
public void DeleteConnection(int id) { var connection = _connectionRepository.GetById(id); if (connection != null) { // hooks not working here, so do it manually // TODO: remove during uninstall too. //var mappings = _storeMappingService.GetStoreMappings(connection); //mappings.Each(x => _storeMappingService.DeleteStoreMapping(x)); _connectionRepository.Delete(connection); ConnectionCache.Remove(); } }