예제 #1
0
        public ActionResult Edit(Models.DictParty.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    if (db.Table <Dict.Entity.tbDictParty>().Where(d => d.PartyName == vm.PartyEdit.PartyName && d.Id != vm.PartyEdit.Id).Any())
                    {
                        error.AddError("该党派已存在!");
                    }
                    else
                    {
                        if (vm.PartyEdit.Id == 0)
                        {
                            var tb = new Dict.Entity.tbDictParty();
                            tb.No = vm.PartyEdit.No == null?db.Table <Dict.Entity.tbDictParty>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PartyEdit.No;

                            tb.PartyName = vm.PartyEdit.PartyName;
                            db.Set <Dict.Entity.tbDictParty>().Add(tb);
                            if (db.SaveChanges() > 0)
                            {
                                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加了党派");
                            }
                        }
                        else
                        {
                            var tb = (from p in db.Table <Dict.Entity.tbDictParty>()
                                      where p.Id == vm.PartyEdit.Id
                                      select p).FirstOrDefault();
                            if (tb != null)
                            {
                                tb.No = vm.PartyEdit.No == null?db.Table <Dict.Entity.tbDictParty>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.PartyEdit.No;

                                tb.PartyName = vm.PartyEdit.PartyName;
                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改党派");
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }
                    }
                }

                return(Code.MvcHelper.Post(error));
            }
        }
예제 #2
0
        public ActionResult Edit(int id = 0)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.DictParty.Edit();

                if (id != 0)
                {
                    var tb = (from p in db.Table <Dict.Entity.tbDictParty>()
                              where p.Id == id
                              select p).FirstOrDefault();
                    if (tb != null)
                    {
                        vm.PartyEdit = tb;
                    }
                }

                return(View(vm));
            }
        }