Пример #1
0
        private async Task Update(CRUDContext <TService> ctx, RunTimeMetadata metadata, ChangeSetRequest changeSet, RowInfo rowInfo)
        {
            TService service = ctx.Service;
            IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper();

            CheckRowInfo(rowInfo);

            using (RequestCallContext callContext = new RequestCallContext(CRUDContext <TService> .CreateRequestContext(service, changeSet, rowInfo)))
            {
                rowInfo.SetChangeState(new EntityChangeState());
                await serviceHelper.UpdateEntity(metadata, rowInfo);
            }
        }
Пример #2
0
        protected virtual void ApplyChangesToEntity(RowInfo rowInfo)
        {
            var metadata  = MetadataHelper.GetInitializedMetadata(this);
            var dbSetInfo = rowInfo.dbSetInfo;

            if (dbSetInfo.EntityType == null)
            {
                throw new DomainServiceException(string.Format(ErrorStrings.ERR_DB_ENTITYTYPE_INVALID,
                                                               dbSetInfo.dbSetName));
            }
            try
            {
                switch (rowInfo.changeType)
                {
                case ChangeType.Added:
                    _serviceHelper.InsertEntity(metadata, rowInfo);
                    break;

                case ChangeType.Deleted:
                    _serviceHelper.DeleteEntity(metadata, rowInfo);
                    break;

                case ChangeType.Updated:
                    _serviceHelper.UpdateEntity(metadata, rowInfo);
                    break;

                default:
                    throw new DomainServiceException(string.Format(ErrorStrings.ERR_REC_CHANGETYPE_INVALID,
                                                                   dbSetInfo.EntityType.Name, rowInfo.changeType));
                }
            }
            catch (Exception ex)
            {
                var dbEntity = rowInfo.changeState == null ? null : rowInfo.changeState.Entity;
                rowInfo.changeState = new EntityChangeState {
                    Entity = dbEntity, Error = ex
                };
                _OnError(ex);
                throw new DummyException(ex.Message, ex);
            }
        }