public FunctionResult <AppFunction> Create(AppFunction info) { var r = new FunctionResult <AppFunction>(); int id = AppFunctionDal.Add(info); if (id > 0) { r.Data = info; r.Data.AppFuntionId = id; } return(r); }
public FunctionListResult <AppService> Add(List <AppService> data) { var r = new FunctionListResult <AppService>(); if (data != null) { data.ForEach(ap => { ap.AppServiceId = AppServiceDal.Add(ap); if (ap.AppFunctions != null) { ap.AppFunctions.ForEach(af => { af.AppFuntionId = AppFunctionDal.Add(af); }); } }); r.Data = data; } return(r); }
public FunctionOpenResult <bool> Update(int appInstanceId, int appId) { Rel_AppInstance_AppService raas = Rel_AppInstance_AppServiceDal.GetByAppInstanceId(appInstanceId); List <AppService> data = (raas != null)?JsonHelper.Deserialize <List <AppService> >(raas.AppService):null; var r = new FunctionOpenResult <bool>(); r.Data = false; if (data != null) { Rel_AppInstance_AppServiceDal.UpdateAppInstanceId(new Rel_AppInstance_AppService() { AppInstanceId = appInstanceId, AppService = JsonHelper.Serlaize <List <AppService> >(data) }); List <AppService> source = GetAppServiceByAppId(appId); data.ForEach(ap => { var sap = source.Find(t => t.Name == ap.Name); if (sap != null) { if (ap.AppFunctions != null) { ap.AppFunctions.ForEach(af => { if (!(sap.AppFunctions.RemoveAll(t => t.FunctionName == af.FunctionName) > 0))//将已经保存的数据消除,如果消除数量为0表示此数据需要保存 { AppFunctionDal.Add(af); } }); if (sap.AppFunctions.Count > 0)//表示有实例未拥有的数据存在,需要打上无匹配的标识 { sap.AppFunctions.ForEach(af => { AppFunctionDal.SigningNoMatching(af.AppFuntionId); }); sap.AppFunctions.Clear(); } } } else {//数据中未找到的的AppService进行插入 int appServiceId = AppServiceDal.Add(ap); if (appServiceId > 0) { if (ap.AppFunctions != null) { ap.AppFunctions.ForEach(af => { AppFunctionDal.Add(af); }); } } } }); var sapList = source.FindAll(ap => ap.AppFunctions.Count > 0);//找出无匹配的AppService,并且打上无匹配标识 if (sapList != null) { sapList.ForEach(ap => { AppServiceDal.SigningNoMatching(ap.AppServiceId); AppFunctionDal.SigningNoMatchingByAppServiceId(ap.AppServiceId); }); } r.Data = true; } return(r); }