内部异常消息:发生引用完整性约束冲突:定义引用约束的属性值在关系中的主体对象和依赖对象之间不一致。
dynamic obj = "";
if (model.LoadResultCount!=0)
{
obj = new LoadManagementResultsCountUserSetting();
obj.ResultsCount = Convert.ToInt16(model.LoadResultCount);
obj.Id = Convert.ToInt16(model.LoadResultCountId);
//var loadManagementResultCount = ApplicationService.GetSettings<LoadManagementResultsCountUserSetting>(f => f.Id == model.LoadResultCountId).FirstOrDefault();
//ApplicationService.Remove(loadManagementResultCount);
SaveResultCountUserSettings(obj, model);
}
if (model.PlanningResultCount!=0)
{
obj = new PlanningManagementResultsCountUserSetting();
obj.ResultsCount = Convert.ToInt16(model.PlanningResultCount);
obj.Id = Convert.ToInt16(model.PlanningResultCountId);
//var planningManagementResultCount = ApplicationService.GetSettings<PlanningManagementResultsCountUserSetting>().Where(f => f.Id == model.PlanningResultCountId).FirstOrDefault();
//ApplicationService.Remove(planningManagementResultCount);
SaveResultCountUserSettings(obj, model);
}
private void SaveResultCountUserSettings(dynamic obj, ResultCountViewModel model)
{
obj.IsEnabled = true;
obj.IsPrimary = model.IsPrimary;
obj.StartDate = DateTime.UtcNow;
obj.ModifiedDate = DateTime.UtcNow;
obj.ModifiedBy = AuthenticatedUser;
ApplicationService.Save(obj);
}
public void Save(BaseLogixSetting setting)
{
if (setting != null)
{
if (setting.Id > 0)
SettingsRepository.Attach(setting);
else
SettingsRepository.Add(setting);
Commit();
}
}