Esempio n. 1
0
        public bool Edit([FromBody] Models.Blood.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    if (db.Table <Dict.Entity.tbDictBlood>().Where(d => d.BloodName == vm.tbDictBlood.BloodName && d.Id != vm.tbDictBlood.Id).Any())
                    {
                        error.AddError("该血型已存在!");
                    }
                    else
                    {
                        if (vm.tbDictBlood.Id == 0)
                        {
                            var tb = new Dict.Entity.tbDictBlood();
                            tb.No = vm.tbDictBlood.No == null?db.Table <Dict.Entity.tbDictBlood>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.tbDictBlood.No;

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

                                tb.BloodName = vm.tbDictBlood.BloodName;
                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改了血型");
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }
                    }
                }

                return(true);
            }
        }
Esempio n. 2
0
        public ActionResult Edit(int id = 0)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.Blood.Edit();

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

                return(View(vm));
            }
        }