Ejemplo n.º 1
0
        public static string InsertDefault(XkSystem.Models.DbContext db, int electiveId)
        {
            var tb = new Entity.tbElectiveGroup();

            tb.No                = 1;
            tb.tbElective        = db.Set <Entity.tbElective>().Find(electiveId);
            tb.ElectiveGroupName = "默认分组";
            tb.MaxElective       = 99;
            tb.MinElective       = 0;
            db.Set <Entity.tbElectiveGroup>().Add(tb);

            if (db.SaveChanges() > 0)
            {
                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加了选课分组");
            }

            return(string.Empty);
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Models.ElectiveGroup.Edit vm)
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var error = new List <string>();

                if (vm.ElectiveGroupEdit.MaxElective < vm.ElectiveGroupEdit.MinElective)
                {
                    error.AddError("最大选课数和最小选课数设置错误,无法比较大小!");
                }

                if (error.Count == decimal.Zero)
                {
                    if (db.Table <Entity.tbElectiveGroup>().Where(d => d.ElectiveGroupName == vm.ElectiveGroupEdit.ElectiveGroupName && d.tbElective.Id == vm.ElectiveId && d.Id != vm.ElectiveGroupEdit.Id).Any())
                    {
                        error.AddError("该选课组已存在!");
                    }
                    else
                    {
                        if (vm.ElectiveGroupEdit.Id == 0)
                        {
                            var tb = new Entity.tbElectiveGroup();
                            tb.No = vm.ElectiveGroupEdit.No == null?db.Table <Entity.tbElectiveGroup>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.ElectiveGroupEdit.No;

                            tb.tbElective        = db.Set <Entity.tbElective>().Find(vm.ElectiveId);
                            tb.ElectiveGroupName = vm.ElectiveGroupEdit.ElectiveGroupName;
                            tb.MaxElective       = vm.ElectiveGroupEdit.MaxElective;
                            tb.MinElective       = vm.ElectiveGroupEdit.MinElective;
                            db.Set <Entity.tbElectiveGroup>().Add(tb);

                            if (db.SaveChanges() > 0)
                            {
                                XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("添加了选课时组");
                            }
                        }
                        else
                        {
                            var tb = (from p in db.Table <Entity.tbElectiveGroup>()
                                      where p.Id == vm.ElectiveGroupEdit.Id
                                      select p).FirstOrDefault();

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

                                tb.ElectiveGroupName = vm.ElectiveGroupEdit.ElectiveGroupName;
                                tb.MaxElective       = vm.ElectiveGroupEdit.MaxElective;
                                tb.MinElective       = vm.ElectiveGroupEdit.MinElective;

                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改了选课时组");
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }
                    }
                }

                return(Code.MvcHelper.Post(error));
            }
        }