public ActionResult Edit(Models.DictMarriage.Edit vm) { var error = new List <string>(); if (error.Count == decimal.Zero) { using (var db = new XkSystem.Models.DbContext()) { if (vm.DataEdit.Id > 0) { var tb = db.Set <Dict.Entity.tbDictMarriage>().Find(vm.DataEdit.Id); tb.MarriageName = vm.DataEdit.MarriageName; tb.No = vm.DataEdit.No == null?db.Table <Dict.Entity.tbDictMarriage>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.DataEdit.No; } else { var tb = new Dict.Entity.tbDictMarriage() { MarriageName = vm.DataEdit.MarriageName, No = vm.DataEdit.No == null?db.Table <Dict.Entity.tbDictMarriage>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.DataEdit.No }; db.Set <Dict.Entity.tbDictMarriage>().Add(tb); } if (db.SaveChanges() > 0) { XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("新增/修改了婚姻状态"); } } } return(Code.MvcHelper.Post(error)); }
public ActionResult Edit(int id = 0) { var vm = new Models.DictMarriage.Edit(); if (id > 0) { using (var db = new XkSystem.Models.DbContext()) { vm.DataEdit = (from p in db.Table <Dict.Entity.tbDictMarriage>() where p.Id == id select p).FirstOrDefault(); } } return(View(vm)); }