/// <summary> /// Create a venue. A venue can not be created without layouts /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task Create(VenueDto entity) { if (entity == null) { throw new ArgumentNullException(); } if (!IsNameUnique(entity, true)) { throw new VenueException("Such venue already exists"); } if (entity.LayoutList == null || !entity.LayoutList.Any()) { throw new VenueException("Incorrect state of the venue. The venue must have at least one layout"); } var venueAdd = VenueParser.MapToVenue(entity); using (var transaction = CustomTransactionScope.GetTransactionScope()) { _context.VenueRepository.Create(venueAdd); await _context.SaveAsync(); entity.Id = venueAdd.Id; foreach (var layout in entity.LayoutList) { layout.VenueId = venueAdd.Id; await _layoutService.Create(layout); } transaction.Complete(); } }