public async Task <IActionResult> UpdateVersion([FromBody] string type, string language)
        {
            var currentVersion = await _catalogContext.Versions.Where(y => y.Type.Equals(type) && y.Language.Equals(language)).SingleOrDefaultAsync();

            if (currentVersion == null)
            {
                currentVersion = new Version()
                {
                    Type          = type,
                    VersionNumber = 1,
                    Language      = language
                };
                _catalogContext.Versions.Add(currentVersion);
            }
            else
            {
                currentVersion.VersionNumber++;

                _catalogContext.Versions.Update(currentVersion);
            }


            await _catalogContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetVersionByType), new { type = type, language = language }, null));
        }
示例#2
0
        public async Task <IActionResult> PutBranding(Guid id, Branding brand)
        {
            if (id != brand.id)
            {
                return(BadRequest());
            }

            _context.Entry(brand).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BrandingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
 {
     //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction():
     //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
     await ResilientTransaction.New(_catalogContext)
     .ExecuteAsync(async() => {
         // Achieving atomicity between original catalog database operation and the IntegrationEventLog thanks to a local transaction
         await _catalogContext.SaveChangesAsync();
         await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction.GetDbTransaction());
     });
 }