Ejemplo n.º 1
0
        public ActionResult Edit(Models.StudentHonorType.Edit vm)
        {
            var error = new List <string>();

            using (var db = new XkSystem.Models.DbContext())
            {
                if (vm.StudentHonorTypeEdit.Id != 0)
                {
                    var tb = db.Set <Student.Entity.tbStudentHonorType>().Find(vm.StudentHonorTypeEdit.Id);
                    tb.No = vm.StudentHonorTypeEdit.No > 0 ? (int)vm.StudentHonorTypeEdit.No : db.Table <Student.Entity.tbStudentHonorType>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1;
                    tb.StudentHonorTypeName = vm.StudentHonorTypeEdit.StudentHonorTypeName;
                }
                else
                {
                    var tb = new Student.Entity.tbStudentHonorType()
                    {
                        No = vm.StudentHonorTypeEdit.No > 0 ? (int)vm.StudentHonorTypeEdit.No : db.Table <Student.Entity.tbStudentHonorType>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1,
                        StudentHonorTypeName = vm.StudentHonorTypeEdit.StudentHonorTypeName
                    };
                    db.Set <Student.Entity.tbStudentHonorType>().Add(tb);
                }

                if (db.SaveChanges() > 0)
                {
                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加/修改学生荣誉类型");
                }
            }

            return(Code.MvcHelper.Post(error));
        }
Ejemplo n.º 2
0
        public static List <Student.Entity.tbStudentHonorType> BuildList(XkSystem.Models.DbContext db, List <Dto.StudentHonorType.Edit> editList)
        {
            List <Student.Entity.tbStudentHonorType> list = new List <Student.Entity.tbStudentHonorType>();

            foreach (var v in editList)
            {
                var honorType = new Student.Entity.tbStudentHonorType()
                {
                    No = v.No > 0 ? (int)v.No : 0,
                    StudentHonorTypeName = v.StudentHonorTypeName
                };

                list.Add(honorType);
            }

            return(list);
        }