Example #1
0
        public override async Task <TEntity?> InsertAsync(IEditContext <TEntity> editContext)
        {
            editContext.Entity.Id = new Random().Next(0, int.MaxValue).ToString();

            await HandleRelationsAsync(editContext.Entity, editContext.GetRelationContainer());

            GetListForParent(editContext.Parent).Add(editContext.Entity);

            return((TEntity)editContext.Entity.Clone());
        }
        public override async Task <TEntity?> InsertAsync(IEditContext <TEntity> editContext)
        {
            editContext.Entity.Id = new Random().Next(0, int.MaxValue).ToString();

            await HandleRelationsAsync(editContext.Entity, editContext.GetRelationContainer());

            GetListForParent(editContext.Parent).Add(editContext.Entity);

            _mediator.NotifyEvent(this, new MessageEventArgs(MessageType.Success, "Entity created."));

            return((TEntity)editContext.Entity);
        }
Example #3
0
        // using editContext overload of UpdateAsync, you can access the state of the edit form
        // with this, you can check whether fields were edited (using editContext.IsModified(..))
        public override async Task UpdateAsync(IEditContext <TEntity> editContext)
        {
            var list = GetListForParent(editContext.Parent);

            var index = list.FindIndex(x => x.Id == editContext.Entity.Id);

            var newEntity = (TEntity)editContext.Entity.Clone();

            await HandleRelationsAsync(newEntity, editContext.GetRelationContainer());

            list.Insert(index, newEntity);
            list.RemoveAt(index + 1);
        }
        public EditContextModel(IEditContext <TEntity> editContext)
        {
            EntityModel = ApiBridge.EntityModel.Create(editContext.Entity);
            ParentPath  = editContext.Parent?.GetParentPath()?.ToPathString();

            var container = editContext.GetRelationContainer();

            RelationContainer = new RelationContainerModel
            {
                Relations = container.Relations.Select(relation =>
                {
                    return(new RelationModel
                    {
                        Elements = relation.RelatedElements.Select(el => el.Id),
                        PropertyName = relation.Property.PropertyName,
                        VariantAlias = AliasHelper.GetEntityVariantAlias(relation.RelatedEntityType)
                    });
                })
            };
        }
Example #5
0
        public EditContextModel(IEditContext <TEntity> editContext)
        {
            Entity     = editContext.Entity;
            ParentPath = editContext.Parent?.GetParentPath()?.ToPathString();

            var container = editContext.GetRelationContainer();

            RelationContainer = new RelationContainerModel
            {
                Relations = container.Relations.Select(relation =>
                {
                    return(new RelationModel
                    {
                        Elements = relation.RelatedElements.Select(el => el.Id),
                        PropertyName = relation.Property.PropertyName,
                        RelatedTypeName = relation.RelatedEntity.AssemblyQualifiedName
                    });
                })
            };
        }
        // using editContext overload of UpdateAsync, you can access the state of the edit form
        // with this, you can check whether fields were edited (using editContext.IsModified(..))
        public override async Task UpdateAsync(IEditContext <TEntity> editContext)
        {
            var list = GetListForParent(editContext.Parent);

            var newEntity = (TEntity)editContext.Entity;

            var index = list.FindIndex(x => x.Id == editContext.Entity.Id);

            if (index == -1)
            {
                list.Add(newEntity);
            }
            else
            {
                list.Insert(index, newEntity);
                list.RemoveAt(index + 1);
            }

            await HandleRelationsAsync(newEntity, editContext.GetRelationContainer());

            _mediator.NotifyEvent(this, new MessageEventArgs(MessageType.Success, "Entity updated."));
        }
 /// <summary>
 /// This method inserts a new entity in the database.
 ///
 /// The editContext parameter contains the state of the form at the time of saving, allowing to check which property was edited.
 ///
 /// The relations parameter contains all the relations that are set to this entity.
 /// </summary>
 /// <param name="editContext"></param>
 /// <returns></returns>
 public virtual Task <TEntity?> InsertAsync(IEditContext <TEntity> editContext)
 => InsertAsync(editContext.Parent, editContext.Entity, editContext.GetRelationContainer());