コード例 #1
0
        public ActionResult Edit(int id = 0)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm = new Models.ExamSegmentMark.Edit();
                vm.GradeList        = Basis.Controllers.GradeController.SelectList();
                vm.SubjectList      = Areas.Course.Controllers.SubjectController.SelectList();
                vm.SegmentGroupList = Areas.Exam.Controllers.ExamSegmentGroupController.SelectList();
                if (id != 0)
                {
                    var tb = (from p in db.Table <Exam.Entity.tbExamSegmentMark>().Include(d => d.tbExamSegmentGroup)
                              where p.Id == id
                              select new Dto.ExamSegmentMark.Edit
                    {
                        Id = p.Id,
                        No = p.No,
                        SegmentName = p.SegmentName,
                        GradeId = p.tbGrade.Id,
                        SubjectId = p.tbSubject.Id,
                        SegmentGroupId = p.tbExamSegmentGroup.Id,
                        MinMark = p.MinMark,
                        MaxMark = p.MaxMark,
                        IsGood = p.IsGood,
                        IsPass = p.IsPass,
                        IsNormal = p.IsNormal,
                        IsTotal = p.IsTotal,
                        Rate = p.Rate,
                        IsGenerate = p.IsGenerate
                    }).FirstOrDefault();
                    if (tb != null)
                    {
                        vm.ExamSegmentMarkEdit = tb;
                    }
                }

                return(View(vm));
            }
        }
コード例 #2
0
        public ActionResult Edit(Models.ExamSegmentMark.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();
                if (error.Count == decimal.Zero)
                {
                    if (db.Table <Exam.Entity.tbExamSegmentMark>().Where(d => d.SegmentName == vm.ExamSegmentMarkEdit.SegmentName && d.tbExamSegmentGroup.Id == vm.ExamSegmentMarkEdit.SegmentGroupId &&
                                                                         !string.IsNullOrEmpty(vm.ExamSegmentMarkEdit.SegmentName) && d.tbGrade.Id == vm.ExamSegmentMarkEdit.GradeId && d.tbSubject.Id == vm.ExamSegmentMarkEdit.SubjectId && d.Id != vm.ExamSegmentMarkEdit.Id).Any())
                    {
                        error.AddError("该分数段分组年级科目分数段已存在!");
                    }
                    else
                    {
                        if (vm.ExamSegmentMarkEdit.Id == 0)
                        {
                            var tb = new Exam.Entity.tbExamSegmentMark();
                            tb.No = vm.ExamSegmentMarkEdit.No == null?db.Table <Exam.Entity.tbExamSegmentMark>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.ExamSegmentMarkEdit.No;

                            tb.SegmentName        = vm.ExamSegmentMarkEdit.SegmentName;
                            tb.tbExamSegmentGroup = db.Set <Entity.tbExamSegmentGroup>().Find(vm.ExamSegmentMarkEdit.SegmentGroupId);
                            tb.tbSubject          = db.Set <Course.Entity.tbSubject>().Find(vm.ExamSegmentMarkEdit.SubjectId);
                            tb.tbGrade            = db.Set <Basis.Entity.tbGrade>().Find(vm.ExamSegmentMarkEdit.GradeId);
                            tb.MinMark            = vm.ExamSegmentMarkEdit.MinMark;
                            tb.MaxMark            = vm.ExamSegmentMarkEdit.MaxMark;
                            tb.IsGood             = vm.ExamSegmentMarkEdit.IsGood;
                            tb.IsPass             = vm.ExamSegmentMarkEdit.IsPass;
                            tb.IsNormal           = vm.ExamSegmentMarkEdit.IsNormal;
                            tb.IsTotal            = vm.ExamSegmentMarkEdit.IsTotal;
                            tb.Rate       = vm.ExamSegmentMarkEdit.Rate;
                            tb.IsGenerate = vm.ExamSegmentMarkEdit.IsGenerate;
                            db.Set <Exam.Entity.tbExamSegmentMark>().Add(tb);
                            if (db.SaveChanges() > 0)
                            {
                                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加分数段");
                            }
                        }
                        else
                        {
                            var tb = (from p in db.Table <Exam.Entity.tbExamSegmentMark>().Include(d => d.tbSubject).Include(d => d.tbExamSegmentGroup)
                                      where p.Id == vm.ExamSegmentMarkEdit.Id
                                      select p).FirstOrDefault();
                            if (tb != null)
                            {
                                tb.No = vm.ExamSegmentMarkEdit.No == null?db.Table <Exam.Entity.tbExamSegmentMark>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.ExamSegmentMarkEdit.No;

                                tb.SegmentName        = vm.ExamSegmentMarkEdit.SegmentName;
                                tb.tbExamSegmentGroup = db.Set <Entity.tbExamSegmentGroup>().Find(vm.ExamSegmentMarkEdit.SegmentGroupId);
                                tb.tbSubject          = db.Set <Course.Entity.tbSubject>().Find(vm.ExamSegmentMarkEdit.SubjectId);
                                tb.tbGrade            = db.Set <Basis.Entity.tbGrade>().Find(vm.ExamSegmentMarkEdit.GradeId);
                                tb.MinMark            = vm.ExamSegmentMarkEdit.MinMark;
                                tb.MaxMark            = vm.ExamSegmentMarkEdit.MaxMark;
                                tb.IsGood             = vm.ExamSegmentMarkEdit.IsGood;
                                tb.IsPass             = vm.ExamSegmentMarkEdit.IsPass;
                                tb.IsNormal           = vm.ExamSegmentMarkEdit.IsNormal;
                                tb.IsTotal            = vm.ExamSegmentMarkEdit.IsTotal;
                                tb.Rate       = vm.ExamSegmentMarkEdit.Rate;
                                tb.IsGenerate = vm.ExamSegmentMarkEdit.IsGenerate;
                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改分数段");
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }
                    }
                }

                return(Code.MvcHelper.Post(error, Url.Action("List")));
            }
        }