Exemplo n.º 1
0
        public override void OnAfterSave(ISaveRequestHandler handler)
        {
            foreach (var info in infoList)
            {
                object mappingsObj;
                if (!handler.StateBag.TryGetValue("UpdatableExtensionBehavior_Assignments_" + info.Attr.Alias, out mappingsObj))
                {
                    continue;
                }

                var mappings = (IEnumerable <Tuple <Field, Field> >)mappingsObj;
                if (mappings == null || !mappings.Any())
                {
                    continue;
                }

                var thisKey = info.ThisKeyField.AsObject(handler.Row);
                if (ReferenceEquals(null, thisKey))
                {
                    continue;
                }

                object oldID = GetExistingID(handler.Connection, info, thisKey);
                if (oldID == null && !CheckPresenceValue(info, handler.Row))
                {
                    continue;
                }

                var extension = info.RowFactory();

                if (oldID != null)
                {
                    ((Field)((IIdRow)extension).IdField).AsObject(extension, oldID);
                }

                info.OtherKeyField.AsObject(extension, thisKey);
                if (!ReferenceEquals(null, info.FilterField))
                {
                    info.FilterField.AsObject(extension, info.FilterValue);
                }

                var request = DefaultHandlerFactory.SaveRequestFor(info.Attr.RowType);
                request.Entity   = extension;
                request.EntityId = oldID;

                foreach (var mapping in mappings)
                {
                    mapping.Item2.AsObject(extension, mapping.Item1.AsObject(handler.Row));
                }

                DefaultHandlerFactory.SaveHandlerFor(info.Attr.RowType)
                .Process(handler.UnitOfWork, request, oldID == null ? SaveRequestType.Create : SaveRequestType.Update);
            }
        }
Exemplo n.º 2
0
        private void SaveLocalRow(IUnitOfWork uow, Row localRow, object masterId, object localRowId)
        {
            localRow = localRow.Clone();

            foreignKeyField.AsObject(localRow, masterId);
            ((Field)((IIdRow)localRow).IdField).AsObject(localRow, localRowId);

            var saveHandler = DefaultHandlerFactory.SaveHandlerFor(localRowType);
            var saveRequest = DefaultHandlerFactory.SaveRequestFor(localRowType);

            saveRequest.Entity = localRow;
            saveHandler.Process(uow, saveRequest, localRowId == null ? SaveRequestType.Create : SaveRequestType.Update);
        }
        private void InsertDetail(IUnitOfWork uow, object masterId, object itemKey)
        {
            var detail = rowFactory();

            thisKeyField.AsObject(detail, masterId);
            itemKeyField.AsObject(detail, itemKeyField.ConvertValue(itemKey, CultureInfo.InvariantCulture));
            if (!ReferenceEquals(null, filterField))
            {
                filterField.AsObject(detail, filterValue);
            }

            var saveHandler = DefaultHandlerFactory.SaveHandlerFor(rowType);
            var saveRequest = DefaultHandlerFactory.SaveRequestFor(rowType);

            saveRequest.Entity = detail;
            saveHandler.Process(uow, saveRequest, SaveRequestType.Create);
        }
        private void SaveDetail(IUnitOfWork uow, Row detail, object masterId, object detailId)
        {
            detail = detail.Clone();

            foreignKeyField.AsObject(detail, masterId);
            if (!ReferenceEquals(null, filterField))
            {
                filterField.AsObject(detail, filterValue);
            }

            ((Field)((IIdRow)detail).IdField).AsObject(detail, detailId);

            var saveHandler = DefaultHandlerFactory.SaveHandlerFor(rowType);
            var saveRequest = DefaultHandlerFactory.SaveRequestFor(rowType);

            saveRequest.Entity = detail;
            saveHandler.Process(uow, saveRequest, detailId == null ? SaveRequestType.Create : SaveRequestType.Update);
        }