public ParticipantLibraryItemDetailsDto ReadDetailsByKey(Guid key) { ParticipantLibraryItem domainPli; List <ParticipantLibraryItemType> domainTypes; try { using (var db = new ParticipantLibraryContext(optionsBuilder.Options)) { domainPli = db.ParticipantLibraryItems.SingleOrDefault(p => p.NexusKey == key); domainTypes = db.ParticipantLibraryItemTypes.ToList(); } var toReturn = Mapper.Map <ParticipantLibraryItemDetailsDto>(domainPli); foreach (var domainType in domainTypes) { toReturn.Types.Add(Mapper.Map <ParticipantLibraryItemTypeDto>(domainType)); } return(toReturn); } catch (Exception ex) { throw ex; } }
public IEnumerable <ParticipantLibraryItemDto> ReadAll() { IEnumerable <ParticipantLibraryItem> domainPlItems; try { using (var db = new ParticipantLibraryContext(optionsBuilder.Options)) { domainPlItems = db.ParticipantLibraryItems .Include(x => x.Type) .OrderBy(x => x.DisplayName); var toReturn = new List <ParticipantLibraryItemDto>(); foreach (var dto in domainPlItems) { toReturn.Add(Mapper.Map <ParticipantLibraryItemDto>(dto)); } return(toReturn.OrderBy(x => x.DisplayName)); } } catch (Exception ex) { throw ex; } }
private void SetupInMemoryDb() { _dbOptions = new DbContextOptionsBuilder <ParticipantLibraryContext>(); _dbOptions.UseInMemoryDatabase(); _plContext = new ParticipantLibraryContext(_dbOptions.Options); var iStoreReadConnectionConfig = A.Fake <IStoreReadConnectionConfig>(); var iStoreWriteConnectionConfig = A.Fake <IStoreWriteConnectionConfig>(); _publishEndpoint = A.Fake <IPublishEndpoint>(); _libraryReader = new EfParticipantLibraryReader(_dbOptions, iStoreReadConnectionConfig); _libraryWriter = new EfParticipantLibraryWriter(_dbOptions, iStoreWriteConnectionConfig); _piLibrary = new ParticipantItemLibrary(_libraryWriter, _libraryReader, _publishEndpoint); }
public void Configuration(IAppBuilder app) { // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888 IParticipantLibraryLogger logWriter = new ParticipantLibraryLogger(); app.Map("/api", parLibApp => parLibApp.UseParticipantLibraryCore(apiAppSettings, BootStrapParticipantLibrary(logWriter))); var optionsBuilder = new DbContextOptionsBuilder <ParticipantLibraryContext>(); optionsBuilder.UseSqlServer(apiAppSettings.ConnectionString_ParticipantLibrary_Read); var ctx = new ParticipantLibraryContext(optionsBuilder.Options); app.MapSignalR(); }
private void SetupIntegrationDb() { var connString = @"Data Source=HV-MUFASA\DEV01;Initial Catalog=ParticipantLibraryTests;Integrated Security=true;Connect Timeout=15;"; _dbOptions = new DbContextOptionsBuilder <ParticipantLibraryContext>(); _dbOptions.UseSqlServer(connString); _plContext = new ParticipantLibraryContext(_dbOptions.Options); var iStoreReadConnectionConfig = new ParticipantLibraryReadConnectionConfig(connString); var iStoreWriteConnectionConfig = new ParticipantLibraryWriteConnectionConfig(connString); _libraryReader = new EfParticipantLibraryReader(_dbOptions, iStoreReadConnectionConfig); _libraryWriter = new EfParticipantLibraryWriter(_dbOptions, iStoreWriteConnectionConfig); _piLibrary = new ParticipantItemLibrary(_libraryWriter, _libraryReader, Bus); }
public ParticipantLibraryItemTypeDto ReadTypeByKey(Guid key) { ParticipantLibraryItemType domainPlType; try { using (var db = new ParticipantLibraryContext(optionsBuilder.Options)) { domainPlType = db.ParticipantLibraryItemTypes.SingleOrDefault(x => x.NexusKey == key); var toReturn = Mapper.Map <ParticipantLibraryItemTypeDto>(domainPlType); return(toReturn); } } catch (Exception ex) { throw ex; } }
public ParticipantLibraryItemDto ReadByKey(Guid key) { ParticipantLibraryItem domainPli; try { using (var db = new ParticipantLibraryContext(optionsBuilder.Options)) { domainPli = db.ParticipantLibraryItems .Include(x => x.Type) .SingleOrDefault(p => p.NexusKey == key); } var toReturn = Mapper.Map <ParticipantLibraryItemDto>(domainPli); return(toReturn); } catch (Exception ex) { throw ex; } }
public DbOperationType Save(ParticipantLibraryItemDto item) { var dto = Mapper.Map <Domain.ParticipantLibraryItem>(item); DbOperationType dbOperationType; try { using (var db = new ParticipantLibraryContext(optionsBuilder.Options)) { var existingItem = db.ParticipantLibraryItems.SingleOrDefault(p => p.NexusKey == item.NexusKey); if (existingItem == null) { dbOperationType = DbOperationType.Create; db.ParticipantLibraryItems.Add(dto); } else { dbOperationType = DbOperationType.Update; existingItem.Name = item.Name; existingItem.DisplayCode = item.DisplayCode; existingItem.DisplayName = item.DisplayName; existingItem.Iso2Code = item.Iso2Code; existingItem.Iso3Code = item.Iso3Code; existingItem.TypeKey = item.TypeKey; } db.SaveChanges(); } return(dbOperationType); } catch (Exception) { throw; } #region oldcode //using (var connection = new SqlConnection(ConnectionStringWrite)) //{ // connection.Open(); // using (var tran = connection.BeginTransaction()) // { // try // { // connection.Execute(EndorsementCatalogStatements.Save, dto,tran); // tran.Commit(); // } // catch (SqlException exception) // { // tran.Rollback(); // if (exception.Message.Contains(EndorsementCatalogStatements.UniqueConstraintViolation)) // { // throw new CatalogLibraryDuplicateItemException( // string.Format( // "The Library already contains an item with Key:'{0}' and VersionNumber:{1}", // item.Key, item.VersionNumber)); // } // if (exception.Message.Contains(EndorsementCatalogStatements.PrimaryKeyViolation)) // { // throw new CatalogLibraryDuplicateItemException( // string.Format( // "The Library already contains an item with VersionKey:'{0}'",item.VersionKey)); // } // if (exception.Message.Contains(EndorsementCatalogStatements.OutOfSequenceViolation)) // { // throw new CatalogLibraryOutOfSequenceException(exception.Message); // } // throw; // } // catch (Exception) // { // tran.Rollback(); // throw; // } // } //} #endregion }