Exemplo n.º 1
0
        public ActionResult Edit(Models.StudentStudyType.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    if (db.Table <Student.Entity.tbStudentStudyType>().Where(d => d.StudyTypeName == vm.StudyTypeEdit.StudyTypeName && d.Id != vm.StudyTypeEdit.Id).Any())
                    {
                        error.AddError("该学习方式已存在!");
                    }
                    else
                    {
                        if (vm.StudyTypeEdit.Id == 0)
                        {
                            var tb = new Student.Entity.tbStudentStudyType();
                            tb.No = vm.StudyTypeEdit.No == null?db.Table <Student.Entity.tbStudentStudyType>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.StudyTypeEdit.No;

                            tb.StudyTypeName = vm.StudyTypeEdit.StudyTypeName;
                            db.Set <Student.Entity.tbStudentStudyType>().Add(tb);

                            if (db.SaveChanges() > 0)
                            {
                                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加了学习方式");
                            }
                        }
                        else
                        {
                            var tb = (from p in db.Table <Student.Entity.tbStudentStudyType>()
                                      where p.Id == vm.StudyTypeEdit.Id
                                      select p).FirstOrDefault();

                            if (tb != null)
                            {
                                tb.No = vm.StudyTypeEdit.No == null?db.Table <Student.Entity.tbStudentStudyType>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.StudyTypeEdit.No;

                                tb.StudyTypeName = vm.StudyTypeEdit.StudyTypeName;

                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改了学习方式");
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }
                    }
                }

                return(Code.MvcHelper.Post(error));
            }
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id = 0)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.StudentStudyType.Edit();

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

                return(View(vm));
            }
        }