Exemple #1
0
        public virtual async Task DoRealDeleteAsync()
        {
            try
            {
                List <Guid> fileids = new List <Guid>();
                var         pros    = typeof(TModel).GetProperties();
                //如果包含附件,则先删除附件
                var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBasePoco).IsAssignableFrom(x.PropertyType)).ToList();
                foreach (var f in fa)
                {
                    if (f.GetValue(Entity) is FileAttachment file)
                    {
                        fileids.Add(file.ID);
                    }
                    f.SetValue(Entity, null);
                }
                DC.DeleteEntity(Entity);
                await DC.SaveChangesAsync();

                foreach (var item in fileids)
                {
                    FileAttachmentVM ofa = new FileAttachmentVM();
                    ofa.CopyContext(this);
                    ofa.SetEntityById(item);
                    await ofa.DoDeleteAsync();
                }
            }
            catch (Exception)
            {
                MSD.AddModelError("", "数据使用中,无法删除");
            }
        }
Exemple #2
0
        public virtual async Task DoRealDeleteAsync()
        {
            try
            {
                List <Guid> fileids = new List <Guid>();
                var         pros    = typeof(TModel).GetProperties();

                //如果包含附件,则先删除附件
                var fa = pros.Where(x => x.PropertyType == typeof(FileAttachment) || typeof(TopBasePoco).IsAssignableFrom(x.PropertyType)).ToList();
                foreach (var f in fa)
                {
                    if (f.GetValue(Entity) is FileAttachment file)
                    {
                        fileids.Add(file.ID);
                    }
                    f.SetValue(Entity, null);
                }

                var fas = pros.Where(x => typeof(IEnumerable <ISubFile>).IsAssignableFrom(x.PropertyType)).ToList();
                foreach (var f in fas)
                {
                    var subs = f.GetValue(Entity) as IEnumerable <ISubFile>;
                    foreach (var sub in subs)
                    {
                        fileids.Add(sub.FileId);
                    }
                    f.SetValue(Entity, null);
                }
                if (typeof(TModel) != typeof(FileAttachment))
                {
                    foreach (var pro in pros)
                    {
                        if (pro.PropertyType.GetTypeInfo().IsSubclassOf(typeof(TopBasePoco)))
                        {
                            pro.SetValue(Entity, null);
                        }
                    }
                }
                DC.DeleteEntity(Entity);
                await DC.SaveChangesAsync();

                foreach (var item in fileids)
                {
                    FileAttachmentVM ofa = new FileAttachmentVM();
                    ofa.CopyContext(this);
                    ofa.SetEntityById(item);
                    await ofa.DoDeleteAsync();
                }
            }
            catch (Exception e)
            {
                MSD.AddModelError("", Program._localizer["DeleteFailed"]);
            }
        }
Exemple #3
0
 public virtual async Task DoAddAsync()
 {
     DoAddPrepare();
     //删除不需要的附件
     if (DeletedFileIds != null)
     {
         foreach (var item in DeletedFileIds)
         {
             FileAttachmentVM ofa = new FileAttachmentVM();
             ofa.CopyContext(this);
             ofa.SetEntityById(item);
             await ofa.DoDeleteAsync();
         }
     }
     await DC.SaveChangesAsync();
 }
Exemple #4
0
        public virtual async Task DoEditAsync(bool updateAllFields = false)
        {
            DoEditPrepare(updateAllFields);

            await DC.SaveChangesAsync();

            //删除不需要的附件
            if (DeletedFileIds != null)
            {
                foreach (var item in DeletedFileIds)
                {
                    FileAttachmentVM ofa = new FileAttachmentVM();
                    ofa.CopyContext(this);
                    ofa.SetEntityById(item);
                    await ofa.DoDeleteAsync();
                }
            }
        }