public override bool DoBatchEdit() { var entityList = DC.Set <FrameworkUser>().AsNoTracking().CheckIDs(Ids.ToList()).ToList(); foreach (var entity in entityList) { List <Guid> todelete = new List <Guid>(); todelete.AddRange(DC.Set <FrameworkUserRole>().AsNoTracking().Where(x => x.UserCode == entity.ITCode).Select(x => x.ID)); foreach (var item in todelete) { DC.DeleteEntity(new FrameworkUserRole { ID = item }); } if (LinkedVM.SelectedRolesCodes != null) { foreach (var rolecode in LinkedVM.SelectedRolesCodes) { FrameworkUserRole r = new FrameworkUserRole { RoleCode = rolecode, UserCode = entity.ITCode }; DC.AddEntity(r); } } } return(base.DoBatchEdit()); }
public dynamic PutLabel(string label) { LabelTemplateModel _labelTemplateModel = new LabelTemplateModel(); _labelTemplateModel.LabelJson = label; DC.AddEntity(_labelTemplateModel); int rows = DC.SaveChanges(); return(null); }
public bool DoRecPop() { if (Location == null || Location == Guid.Empty) { MSD.AddModelError("NullLocation", "请选择上架货位"); return(false); } if (RecQty > (Entity.OrderQty - Entity.RecQty)) { MSD.AddModelError("QtyOver", "实收数量不能大于剩余可收货数量"); return(false); } var loc = DC.Set <area_location>().AsNoTracking().Where(r => r.ID == Location.Value).FirstOrDefault(); if (!loc.isMix.Value) { var invs = DC.Set <inventory>().Where(r => r.LocationID == Location.Value); var InInvs = DC.Set <inventoryIn>().Include("OrderPop.ContractPop").Where(r => invs.Select(x => x.ID).Contains(r.InvID)); List <Guid> pops = InInvs.Select(r => r.OrderPop.ContractPop.PopID).ToList(); pops.Add(Entity.ContractPop.PopID); if (pops.Distinct().Count() > 1) { MSD.AddModelError("LocNotMix", "货位不可混放,但当前货位已经有其他货品了"); return(false); } } inventory inv = new inventory { ID = Guid.NewGuid(), LocationID = Location.Value, Stock = RecQty, PutUser = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name, PutTime = DateTime.Now }; inventoryIn InvIn = new inventoryIn { CreateBy = LoginUserInfo.ITCode, CreateTime = DateTime.Now, InvID = inv.ID, OrderPopID = Entity.ID, InQty = RecQty }; DC.AddEntity(inv); DC.AddEntity(InvIn); var OrderPop = DC.Set <order_pop>().Where(r => r.ID == Entity.ID).FirstOrDefault(); OrderPop.Status = OrderPop.RecQty + RecQty == OrderPop.OrderQty ? RecStatus.FINISH : RecStatus.ING; OrderPop.RecQty += RecQty; OrderPop.RecTime = DateTime.Now; OrderPop.RecUser = LoginUserInfo.ITCode + " | " + LoginUserInfo.Name; DC.UpdateEntity(OrderPop); return(DC.SaveChanges() > 0 ? true : false); }
public override async Task DoAddAsync() { using (var trans = DC.BeginTransaction()) { if (SelectedRolesCodes != null) { foreach (var rolecode in SelectedRolesCodes) { FrameworkUserRole r = new FrameworkUserRole { RoleCode = rolecode, UserCode = Entity.ITCode }; DC.AddEntity(r); } } if (SelectedGroupCodes != null) { foreach (var groupcode in SelectedGroupCodes) { FrameworkUserGroup g = new FrameworkUserGroup { GroupCode = groupcode, UserCode = Entity.ITCode }; DC.AddEntity(g); } } Entity.IsValid = true; Entity.Password = Utils.GetMD5String(Entity.Password); await base.DoAddAsync(); if (MSD.IsValid) { trans.Commit(); } else { trans.Rollback(); } } }
public override async Task DoEditAsync(bool updateAllFields = false) { if (FC.ContainsKey("Entity.ITCode")) { FC.Remove("Entity.ITCode"); } using (var trans = DC.BeginTransaction()) { if (SelectedRolesCodes != null) { List <Guid> todelete = new List <Guid>(); todelete.AddRange(DC.Set <FrameworkUserRole>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID)); foreach (var item in todelete) { DC.DeleteEntity(new FrameworkUserRole { ID = item }); } } if (SelectedGroupCodes != null) { List <Guid> todelete = new List <Guid>(); todelete.AddRange(DC.Set <FrameworkUserGroup>().AsNoTracking().Where(x => x.UserCode == Entity.ITCode).Select(x => x.ID)); foreach (var item in todelete) { DC.DeleteEntity(new FrameworkUserGroup { ID = item }); } } if (SelectedRolesCodes != null) { foreach (var rolecode in SelectedRolesCodes) { FrameworkUserRole r = new FrameworkUserRole { RoleCode = rolecode, UserCode = Entity.ITCode }; DC.AddEntity(r); } } if (SelectedGroupCodes != null) { foreach (var groupcode in SelectedGroupCodes) { FrameworkUserGroup g = new FrameworkUserGroup { GroupCode = groupcode, UserCode = Entity.ITCode }; DC.AddEntity(g); } } await base.DoEditAsync(updateAllFields); if (MSD.IsValid) { trans.Commit(); await Wtm.RemoveUserCache(Entity.ID.ToString()); } else { trans.Rollback(); } } }
private void DoEditPrepare(bool updateAllFields) { if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BasePoco))) { BasePoco ent = Entity as BasePoco; if (ent.UpdateTime == null) { ent.UpdateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.UpdateBy)) { ent.UpdateBy = LoginUserInfo?.ITCode; } } var pros = typeof(TModel).GetProperties(); #region 更新子表 foreach (var pro in pros) { //找到类型为List<xxx>的字段 if (pro.PropertyType.GenericTypeArguments.Count() > 0) { //获取xxx的类型 var ftype = pro.PropertyType.GenericTypeArguments.First(); //如果xxx继承自TopBasePoco if (ftype.IsSubclassOf(typeof(TopBasePoco))) { //界面传过来的子表数据 if (pro.GetValue(Entity) is IEnumerable <TopBasePoco> list && list.Count() > 0) { //获取外键字段名称 string fkname = DC.GetFKName <TModel>(pro.Name); PropertyInfo[] itemPros = ftype.GetProperties(); bool found = false; foreach (var newitem in list) { var subtype = newitem.GetType(); if (subtype.IsSubclassOf(typeof(BasePoco))) { BasePoco ent = newitem as BasePoco; if (ent.UpdateTime == null) { ent.UpdateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.UpdateBy)) { ent.UpdateBy = LoginUserInfo?.ITCode; } } //循环页面传过来的子表数据,将关联到TopBasePoco的字段设为null,并且把外键字段的值设定为主表ID foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(newitem, null); } if (!string.IsNullOrEmpty(fkname)) { if (itempro.Name.ToLower() == fkname.ToLower()) { itempro.SetValue(newitem, Entity.GetID()); found = true; } } } } //如果没有找到相应的外建字段,则可能是多对多的关系,或者做了特殊的设定,这种情况框架无法支持,直接退出本次循环 if (found == false) { continue; } TModel _entity = null; //打开新的数据库联接,获取数据库中的主表和子表数据 using (var ndc = DC.CreateNew()) { _entity = ndc.Set <TModel>().Include(pro.Name).AsNoTracking().CheckID(Entity.GetID()).FirstOrDefault(); } //比较子表原数据和新数据的区别 IEnumerable <TopBasePoco> toadd = null; IEnumerable <TopBasePoco> toremove = null; IEnumerable <TopBasePoco> data = _entity.GetType().GetProperty(pro.Name).GetValue(_entity) as IEnumerable <TopBasePoco>; Utils.CheckDifference(data, list, out toremove, out toadd); //设定子表应该更新的字段 List <string> setnames = new List <string>(); foreach (var field in FC.Keys) { if (field.StartsWith("Entity." + pro.Name + "[0].")) { string name = field.Replace("Entity." + pro.Name + "[0].", ""); setnames.Add(name); } } //前台传过来的数据 foreach (var newitem in list) { //数据库中的数据 foreach (var item in data) { //需要更新的数据 if (newitem.GetID().ToString() == item.GetID().ToString()) { dynamic i = newitem; var newitemType = item.GetType(); foreach (var itempro in itemPros) { if (!itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)) && (updateAllFields == true || setnames.Contains(itempro.Name))) { var notmapped = itempro.GetCustomAttribute <NotMappedAttribute>(); if (itempro.Name != "ID" && notmapped == null && itempro.PropertyType.IsList() == false) { DC.UpdateProperty(i, itempro.Name); } } } if (item.GetType().IsSubclassOf(typeof(BasePoco))) { DC.UpdateProperty(i, "UpdateTime"); DC.UpdateProperty(i, "UpdateBy"); } } } } //需要删除的数据 foreach (var item in toremove) { //如果是PersistPoco,则把IsValid设为false,并不进行物理删除 if (ftype.IsSubclassOf(typeof(PersistPoco))) { (item as PersistPoco).IsValid = false; (item as PersistPoco).UpdateTime = DateTime.Now; (item as PersistPoco).UpdateBy = LoginUserInfo?.ITCode; dynamic i = item; DC.UpdateEntity(i); } else { foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(item, null); } } dynamic i = item; DC.DeleteEntity(i); } } //需要添加的数据 foreach (var item in toadd) { if (item.GetType().IsSubclassOf(typeof(BasePoco))) { BasePoco ent = item as BasePoco; if (ent.CreateTime == null) { ent.CreateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.CreateBy)) { ent.CreateBy = LoginUserInfo?.ITCode; } } DC.AddEntity(item); } } else if (FC.Keys.Contains("Entity." + pro.Name + ".DONOTUSECLEAR") || (FC.ContainsKey("Entity." + pro.Name) && pro.GetValue(Entity) is IEnumerable <TopBasePoco> list2 && list2?.Count() == 0)) { PropertyInfo[] itemPros = ftype.GetProperties(); var _entity = DC.Set <TModel>().Include(pro.Name).AsNoTracking().CheckID(Entity.GetID()).FirstOrDefault(); if (_entity != null) { IEnumerable <TopBasePoco> removeData = _entity.GetType().GetProperty(pro.Name).GetValue(_entity) as IEnumerable <TopBasePoco>; //如果是PersistPoco,则把IsValid设为false,并不进行物理删除 if (removeData is IEnumerable <PersistPoco> removePersistPocoData) { foreach (var item in removePersistPocoData) { (item as PersistPoco).IsValid = false; (item as PersistPoco).UpdateTime = DateTime.Now; (item as PersistPoco).UpdateBy = LoginUserInfo?.ITCode; dynamic i = item; DC.UpdateEntity(i); } } else { foreach (var item in removeData) { foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(item, null); } } dynamic i = item; DC.DeleteEntity(i); } } } } } } } #endregion if (updateAllFields == false) { foreach (var field in FC.Keys) { if (field.StartsWith("Entity.") && !field.Contains("[")) { string name = field.Replace("Entity.", ""); try { DC.UpdateProperty(Entity, name); } catch (Exception ea) { } } } if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BasePoco))) { try { DC.UpdateProperty(Entity, "UpdateTime"); DC.UpdateProperty(Entity, "UpdateBy"); } catch (Exception) { } } } else { DC.UpdateEntity(Entity); } }
public virtual void UpdateEntityList(bool updateAllFields = false) { if (EntityList != null) { var ftype = EntityList.GetType().GenericTypeArguments.First(); PropertyInfo[] itemPros = ftype.GetProperties(); foreach (var newitem in EntityList) { var subtype = newitem.GetType(); if (subtype.IsSubclassOf(typeof(BasePoco))) { BasePoco ent = newitem as BasePoco; if (ent.UpdateTime == null) { ent.UpdateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.UpdateBy)) { ent.UpdateBy = LoginUserInfo?.ITCode; } } //循环页面传过来的子表数据,将关联到TopBasePoco的字段设为null,并且把外键字段的值设定为主表ID foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(newitem, null); } } } IEnumerable <TopBasePoco> data = null; //打开新的数据库联接,获取数据库中的主表和子表数据 using (var ndc = DC.CreateNew()) { var ids = EntityList.Select(x => x.GetID().ToString()).ToList(); data = ndc.Set <TModel>().AsNoTracking().Where(ids.GetContainIdExpression <TModel>()).ToList(); } //比较子表原数据和新数据的区别 IEnumerable <TopBasePoco> toadd = null; IEnumerable <TopBasePoco> toremove = null; Utils.CheckDifference(data, EntityList, out toremove, out toadd); //设定子表应该更新的字段 List <string> setnames = new List <string>(); foreach (var field in FC.Keys) { if (field.StartsWith("EntityList[0].")) { string name = field.Replace("EntityList[0].", ""); setnames.Add(name); } } //前台传过来的数据 foreach (var newitem in EntityList) { //数据库中的数据 foreach (var item in data) { //需要更新的数据 if (newitem.GetID().ToString() == item.GetID().ToString()) { dynamic i = newitem; var newitemType = item.GetType(); foreach (var itempro in itemPros) { if (!itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)) && (updateAllFields == true || setnames.Contains(itempro.Name))) { var notmapped = itempro.GetCustomAttribute <NotMappedAttribute>(); if (itempro.Name != "ID" && notmapped == null && itempro.PropertyType.IsList() == false) { DC.UpdateProperty(i, itempro.Name); } } } if (item.GetType().IsSubclassOf(typeof(BasePoco))) { DC.UpdateProperty(i, "UpdateTime"); DC.UpdateProperty(i, "UpdateBy"); } } } } //需要删除的数据 foreach (var item in toremove) { //如果是PersistPoco,则把IsValid设为false,并不进行物理删除 if (ftype.IsSubclassOf(typeof(PersistPoco))) { (item as PersistPoco).IsValid = false; (item as PersistPoco).UpdateTime = DateTime.Now; (item as PersistPoco).UpdateBy = LoginUserInfo?.ITCode; dynamic i = item; DC.UpdateEntity(i); } else { foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(item, null); } } dynamic i = item; DC.DeleteEntity(i); } } //需要添加的数据 foreach (var item in toadd) { if (item.GetType().IsSubclassOf(typeof(BasePoco))) { BasePoco ent = item as BasePoco; if (ent.CreateTime == null) { ent.CreateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.CreateBy)) { ent.CreateBy = LoginUserInfo?.ITCode; } } DC.AddEntity(item); } DC.SaveChanges(); } }
public string CreatedNewPlayer(PlayerInfoCreatedModel model) { //创建基本信息 var vm = CreateVM <PlayerInfoApiVM>(); vm.Entity = new PlayerInfo() { Name = model.Name, NickName = model.NickName, IsAlive = true, BirthPlace = model.BirthPlace, ID = Guid.NewGuid(), Sect = 0, Sex = model.Sex }; string newplayerID = vm.Entity.ID.ToString(); vm.DoAdd(); //生成七维属性 var ps = new PlayerInitialization().InitPlayerSpecial(); ps.FK_PlayerGuId = newplayerID; DC.AddEntity(ps); //生成人物核心属性 PlayerAttribute //灵根 DC.AddEntity(new PlayerAttribute() { AttributeType = (int)EnumAttrbuteType.Core, AttrName = PlayerFields.BodySprit, AttrValue = model.BodySprit, FK_PlayerGuid = newplayerID }); //体魄 DC.AddEntity(new PlayerAttribute() { AttributeType = (int)EnumAttrbuteType.Core, AttrName = PlayerFields.Defense, AttrValue = ps.Endurance * 49, FK_PlayerGuid = newplayerID }); //血量 DC.AddEntity(new PlayerAttribute() { AttributeType = (int)EnumAttrbuteType.Core, AttrName = PlayerFields.Hp, AttrValue = (ps.Endurance * 2 + ps.Strength * 3) * 9, FK_PlayerGuid = newplayerID }); //神识 DC.AddEntity(new PlayerAttribute() { AttributeType = (int)EnumAttrbuteType.Core, AttrName = PlayerFields.Mind, AttrValue = ps.Perception * 49, FK_PlayerGuid = newplayerID }); //真元 DC.AddEntity(new PlayerAttribute() { AttributeType = (int)EnumAttrbuteType.Core, AttrName = PlayerFields.Mp, AttrValue = (ps.Strength * 2 + ps.Perception * 3) * 9, FK_PlayerGuid = newplayerID }); //初始化角色状态--境界、经验、寿元、精力、灵石仙玉 var playerState = new PlayerState() { StateLevel = SimpleState.Default.GetDescription() + SmallState.Inferior.GetDescription(), LevelExp = 0, LifeRemark = GlobalConsts.LifeDefaultRemark, CurrentLife = 15, MaxLifeTime = RandMethod.GetRandNumber(20, 80), Energy = 100, Gold = 0, Money = 0, }; playerState.FK_PlayerGuId = newplayerID; playerState.LifeRemark = PlayerBaseLogic.PlayerLifeRemark(playerState.CurrentLife, playerState.MaxLifeTime); //重定义人物宗门、境界 ,可不从练气初期开局--TODO DC.AddEntity(playerState); //分配人物初始资产 PlayerProperty DC.AddEntity(new PlayerProperty() { FK_PlayerGuId = newplayerID, ItemName = "道元真解", Level = RandMethod.GetRandNumber(0, 50), Value = RandMethod.GetRandNumber(0, 20000), TypeId = 1 }); //添加新手礼包 //生成随机词条 --TODO //生成特质 --TODO DC.SaveChanges(); //返回角色ID return(newplayerID); }
/// <summary> /// 修改,进行默认的修改操作。子类如有自定义操作应重载本函数 /// </summary> public virtual void DoEdit(bool updateAllFields = false) { //自动设定修改日期和修改人 if (typeof(TModel).GetTypeInfo().IsSubclassOf(typeof(BasePoco))) { BasePoco ent = Entity as BasePoco; if (ent.UpdateTime == null) { ent.UpdateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.UpdateBy)) { ent.UpdateBy = LoginUserInfo?.ITCode; } } var pros = typeof(TModel).GetProperties(); #region 更新子表 foreach (var pro in pros) { //找到类型为List<xxx>的字段 if (pro.PropertyType.GenericTypeArguments.Count() > 0) { //获取xxx的类型 var ftype = pro.PropertyType.GenericTypeArguments.First(); //如果xxx继承自TopBasePoco if (ftype.IsSubclassOf(typeof(TopBasePoco))) { //界面传过来的子表数据 if (pro.GetValue(Entity) is IEnumerable <TopBasePoco> list && list.Count() > 0) { //获取外键字段名称 string fkname = DC.GetFKName <TModel>(pro.Name); PropertyInfo[] itemPros = ftype.GetProperties(); bool found = false; foreach (var newitem in list) { foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(newitem, null); } if (!string.IsNullOrEmpty(fkname)) { if (itempro.Name.ToLower() == fkname.ToLower()) { itempro.SetValue(newitem, Entity.ID); found = true; } } } } //如果没有找到相应的外建字段,则可能是多对多的关系,或者做了特殊的设定,这种情况框架无法支持,直接退出本次循环 if (found == false) { continue; } //循环页面传过来的子表数据,将关联到TopBasePoco的字段设为null,并且把外键字段的值设定为主表ID foreach (var newitem in list) { var subtype = newitem.GetType(); if (subtype.IsSubclassOf(typeof(BasePoco))) { BasePoco ent = newitem as BasePoco; if (ent.UpdateTime == null) { ent.UpdateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.UpdateBy)) { ent.UpdateBy = LoginUserInfo.ITCode; } } foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(newitem, null); } if (!string.IsNullOrEmpty(fkname)) { if (itempro.Name.ToLower() == fkname.ToLower()) { itempro.SetValue(newitem, Entity.ID); found = true; } } } } TModel _entity = null; //打开新的数据库联接,获取数据库中的主表和子表数据 using (var ndc = DC.CreateNew()) { _entity = ndc.Set <TModel>().Include(pro.Name).AsNoTracking().Where(x => x.ID == Entity.ID).FirstOrDefault(); } //比较子表原数据和新数据的区别 IEnumerable <TopBasePoco> toadd = null; IEnumerable <TopBasePoco> toremove = null; IEnumerable <TopBasePoco> data = _entity.GetType().GetProperty(pro.Name).GetValue(_entity) as IEnumerable <TopBasePoco>; Utils.CheckDifference(data, list, out toremove, out toadd); //设定子表应该更新的字段 List <string> setnames = new List <string>(); foreach (var field in FC.Keys) { if (field.StartsWith("Entity." + pro.Name + "[0].")) { string name = field.Replace("Entity." + pro.Name + "[0].", ""); if (name != "UpdateTime" && name != "UpdateBy") { setnames.Add(name); } } } //前台传过来的数据 foreach (var newitem in list) { //数据库中的数据 foreach (var item in data) { //需要更新的数据 if (newitem.ID == item.ID) { dynamic i = newitem; var newitemType = item.GetType(); foreach (var itempro in itemPros) { if (!itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco)) && setnames.Contains(itempro.Name)) { if (itempro.Name != "ID") { DC.UpdateProperty(i, itempro.Name); } } } DC.UpdateProperty(i, "UpdateTime"); DC.UpdateProperty(i, "UpdateBy"); } } } //需要删除的数据 foreach (var item in toremove) { foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(item, null); } } dynamic i = item; DC.DeleteEntity(i); } //需要添加的数据 foreach (var item in toadd) { if (item.GetType().IsSubclassOf(typeof(BasePoco))) { BasePoco ent = item as BasePoco; if (ent.CreateTime == null) { ent.CreateTime = DateTime.Now; } if (string.IsNullOrEmpty(ent.CreateBy)) { ent.CreateBy = LoginUserInfo?.ITCode; } } DC.AddEntity(item); } } else if (FC.Keys.Contains("Entity." + pro.Name + ".DONOTUSECLEAR")) { PropertyInfo[] itemPros = ftype.GetProperties(); var _entity = DC.Set <TModel>().Include(pro.Name).AsNoTracking().Where(x => x.ID == Entity.ID).FirstOrDefault(); IEnumerable <TopBasePoco> removeData = _entity.GetType().GetProperty(pro.Name).GetValue(_entity) as IEnumerable <TopBasePoco>; foreach (var item in removeData) { foreach (var itempro in itemPros) { if (itempro.PropertyType.IsSubclassOf(typeof(TopBasePoco))) { itempro.SetValue(item, null); } } dynamic i = item; DC.DeleteEntity(i); } } } } } #endregion if (updateAllFields == false) { foreach (var field in FC.Keys) { if (field.StartsWith("Entity.") && !field.Contains("[")) { string name = field.Replace("Entity.", ""); if (name != "UpdateTime" && name != "UpdateBy") { try { DC.UpdateProperty(Entity, name); } catch (Exception) { } } } } } else { DC.UpdateEntity(Entity); } DC.SaveChanges(); //删除不需要的附件 if (DeletedFileIds != null) { foreach (var item in DeletedFileIds) { FileAttachmentVM ofa = new FileAttachmentVM(); ofa.CopyContext(this); ofa.SetEntityById(item); ofa.DoDelete(); } } }