public DbEntities.Subjects.SubjectSection AddOrUpdateSection(DbEntities.Subjects.SubjectSection sec , DbEntities.AccessPermission.Restriction restriction) { try { using (var actresHelper = new DbHelper.ActAndRes()) using (var scope = new TransactionScope()) { var ent = Context.SubjectSection.Find(sec.Id); if (ent == null) { var res = actresHelper.AddOrUpdateRestriction(0, restriction); sec.RestrictionId = res.Id; ent = Context.SubjectSection.Add(sec); } else { ent.Name = sec.Name; ent.Summary = sec.Summary; ent.ShowSummary = sec.ShowSummary; var res = actresHelper.AddOrUpdateRestriction(0, restriction); if ((ent.RestrictionId ?? 0) == 0) { ent.RestrictionId = res.Id; } } Context.SaveChanges(); scope.Complete(); return(ent); } } catch (Exception) { return(null); } }