public ActionResult ZhangADD(RuleDetailS te) { try { if (ef.RuleDetails.Any(x => x.BookID == ef.TextBooks.FirstOrDefault(a => a.BookName == te.BookIDName && a.Shan == false).BookID&& x.QuestionCount == te.QuestionCount && x.QuestionLevel == te.QuestionLevel && x.Shan == false && x.RuleID == ef.PaperRules.FirstOrDefault(b => b.RuleName == te.RuleIDName && b.Shan == false).RuleID)) { return(Content("已经存在了,请重新添加")); } else { RuleDetail ta = new RuleDetail() { BookID = ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookIDName).BookID, RuleID = ef.PaperRules.FirstOrDefault(x => x.RuleName == te.RuleIDName).RuleID, QuestionCount = te.QuestionCount, QuestionLevel = te.QuestionLevel }; ef.Entry(ta).State = EntityState.Added; if (ef.SaveChanges() > 0) { return(Content("添加成功")); } else { return(Content("添加失败")); } } } catch (Exception ex) { return(Content(ex.ToString())); } }
public ActionResult Update(RuleDetailS te) { RuleDetail ta = new RuleDetail() { BookID = ef.TextBooks.FirstOrDefault(x => x.BookName == te.BookIDName && x.Shan == false).BookID, DetailID = te.DetailID, QuestionCount = te.QuestionCount, QuestionLevel = te.QuestionLevel, RuleID = ef.PaperRules.FirstOrDefault(x => x.RuleName == te.RuleIDName && x.Shan == false).RuleID, }; ef.Entry(ta).State = EntityState.Modified; if (ef.SaveChanges() > 0) { return(Content("成功")); } else { return(Content("失败")); } }