예제 #1
0
        private static async Task <CodeForeign> GetOrAddForeign(IDataContract contract, Guid entityId, CodeForeign fore)
        {
            CodeForeign foreign = contract.CodeForeigns.FirstOrDefault(m => m.EntityId == entityId && m.SelfNavigation == fore.SelfNavigation);

            if (foreign != null)
            {
                return(foreign);
            }

            CodeForeignInputDto dto = new CodeForeignInputDto()
            {
                SelfNavigation  = fore.SelfNavigation,
                SelfForeignKey  = fore.SelfForeignKey,
                OtherEntity     = fore.OtherEntity,
                OtherNavigation = fore.OtherNavigation,
                IsRequired      = fore.IsRequired,
                DeleteBehavior  = fore.DeleteBehavior,
                ForeignRelation = fore.ForeignRelation,
                EntityId        = entityId
            };
            await contract.UpdateCodeForeigns(dto);

            foreign = contract.CodeForeigns.First(m => m.EntityId == entityId && m.SelfNavigation == fore.SelfNavigation);

            return(foreign);
        }
        public async void Save()
        {
            if (!CanSave)
            {
                Helper.Notify("实体外键信息验证失败", NotificationType.Warning);
                return;
            }

            CodeForeignInputDto[] dtos   = Foreigns.Select(m => m.MapTo <CodeForeignInputDto>()).ToArray();
            OperationResult       result = null;
            await _provider.ExecuteScopedWorkAsync(async provider =>
            {
                IDataContract contract = provider.GetRequiredService <IDataContract>();
                result = await contract.UpdateCodeForeigns(dtos);
            });

            Helper.Notify(result);
            if (!result.Succeeded)
            {
                return;
            }

            Init();
        }