public FranchisingInfo Save() { if (this.Id != null) { Franchising.Update(this); return(this); } return(Franchising.Insert(this)); }
public APIReturn _Edit([FromQuery] uint Id, [FromForm] string Title, [FromForm] uint[] mn_Factory, [FromForm] uint[] mn_Rentsublet, [FromForm] uint[] mn_Shop) { FranchisingInfo item = Franchising.GetItem(Id); if (item == null) { return(APIReturn.记录不存在_或者没有权限); } item.Title = Title; int affrows = Franchising.Update(item); //关联 Factory if (mn_Factory.Length == 0) { item.UnflagFactoryALL(); } else { List <uint> mn_Factory_list = mn_Factory.ToList(); foreach (var Obj_factory in item.Obj_factorys) { int idx = mn_Factory_list.FindIndex(a => a == Obj_factory.Id); if (idx == -1) { item.UnflagFactory(Obj_factory.Id); } else { mn_Factory_list.RemoveAt(idx); } } mn_Factory_list.ForEach(a => item.FlagFactory(a)); } //关联 Rentsublet if (mn_Rentsublet.Length == 0) { item.UnflagRentsubletALL(); } else { List <uint> mn_Rentsublet_list = mn_Rentsublet.ToList(); foreach (var Obj_rentsublet in item.Obj_rentsublets) { int idx = mn_Rentsublet_list.FindIndex(a => a == Obj_rentsublet.Id); if (idx == -1) { item.UnflagRentsublet(Obj_rentsublet.Id); } else { mn_Rentsublet_list.RemoveAt(idx); } } mn_Rentsublet_list.ForEach(a => item.FlagRentsublet(a)); } //关联 Shop if (mn_Shop.Length == 0) { item.UnflagShopALL(); } else { List <uint> mn_Shop_list = mn_Shop.ToList(); foreach (var Obj_shop in item.Obj_shops) { int idx = mn_Shop_list.FindIndex(a => a == Obj_shop.Id); if (idx == -1) { item.UnflagShop(Obj_shop.Id); } else { mn_Shop_list.RemoveAt(idx); } } mn_Shop_list.ForEach(a => item.FlagShop(a)); } if (affrows > 0) { return(APIReturn.成功.SetMessage($"更新成功,影响行数:{affrows}")); } return(APIReturn.失败); }