示例#1
0
        public async Task <UpdateEntityResult <PersonDbEntity> > UpdatePersonByIdAsync(UpdatePersonRequestObject requestObject, string requestBody,
                                                                                       PersonQueryObject query, int?ifMatch)
        {
            var existingPerson = await _dynamoDbContext.LoadAsync <PersonDbEntity>(query.Id).ConfigureAwait(false);

            if (existingPerson == null)
            {
                return(null);
            }

            if (ifMatch != existingPerson.VersionNumber)
            {
                throw new VersionNumberConflictException(ifMatch, existingPerson.VersionNumber);
            }

            var result = _updater.UpdateEntity(existingPerson, requestBody, requestObject);

            if (result.NewValues.Any())
            {
                _logger.LogDebug($"Calling IDynamoDBContext.SaveAsync to update id {query.Id}");
                result.UpdatedEntity.LastModified = DateTime.UtcNow;
                await _dynamoDbContext.SaveAsync(result.UpdatedEntity).ConfigureAwait(false);
            }

            return(result);
        }
        /// <summary>
        /// Merge all changes from the supplied model to a corresponding entity in the context or attaches the
        /// model to the context if it's new
        /// </summary>
        /// <param name="model">Model that contains the changes</param>
        public void MergeEntityChanges(TModel model)
        {
            var entity = scalarUpdater.UpdateEntity(model);
            IRecursiveEntityUpdater updater = new EntityUpdater(DbContext, reflector, scalarUpdater, collectionMerger);

            updater.UpdateEntity <TModel>(model, navUpdater);

            OnMergeChanges(entity, model);
        }