public ActionResult Edit(SectionViewModel viewmodel) { IList<Section> list = new List<Section>(); Section section = null; string[] arrSection = Request.Params["SectionName"].Split(','); string[] arrSectionId = Request.Params["SectionId"].Split(','); for (int i = 0; i < arrSection.Length; i++) { section = new Section(); section.EzineId = viewmodel.EzineId; section.Id = viewmodel.SectionId; section.Id = int.Parse(arrSectionId[i]); section.Name = arrSection[i].ToString(); list.Add(section); } var result = sectionRepository.EditSection(list); if (result) { return RedirectToAction("Index", "Ezine"); } else { return View(); } }
/// <summary> /// 保存每个杂志的多个章节 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Save(Section model) { string[] arrName = model.Name.TrimEnd(',').Split(','); foreach (var item in arrName) { var entity = new Section(); entity.EzineId = model.EzineId; entity.Name = item.ToString(); db.Sections.Add(entity); } return db.SaveChanges() > 0; }
/// <summary> /// 添加目录 /// </summary> /// <returns></returns> public JsonResult Save(Section model) { var result = sectionRepository.Save(model); return Json(result); }