예제 #1
0
        public ActionResult Edit(int id = 0)
        {
            var vm = new Models.MoralItem.Edit();

            using (var db = new XkSystem.Models.DbContext())
            {
                vm.MoralType = db.Set <Moral.Entity.tbMoral>().Find(vm.MoralId).MoralType;

                if (id > 0)
                {
                    var tb = (from p in db.Table <Moral.Entity.tbMoralItem>()
                              where p.Id == id
                              select new Dto.MoralItem.Edit()
                    {
                        Id = p.Id,
                        InitScore = p.InitScore,
                        MaxScore = p.MaxScore,
                        MinScore = p.MinScore,
                        DefaultValue = p.DefaultValue,
                        MoralExpress = p.MoralExpress,
                        MoralItemName = p.MoralItemName,
                        MoralItemType = p.MoralItemType,
                        MoralItemKind = p.MoralItemKind,
                        MoralItemOperateType = p.MoralItemOperateType,
                        No = p.No,
                        MoralGroupId = p.tbMoralGroup.Id,
                        AutoCheck = p.AutoCheck
                    }).FirstOrDefault();

                    if (tb != null)
                    {
                        vm.MoralItemEdit = tb;
                        if (vm.MoralType != Code.EnumHelper.MoralType.Many)
                        {
                            vm.MoralOptionList = MoralOptionController.SelectList(vm.MoralItemEdit.Id);
                        }
                    }
                }
                else
                {
                    vm.MoralItemEdit.No                   = db.Table <Moral.Entity.tbMoralItem>().Where(p => p.tbMoralGroup.tbMoral.Id == vm.MoralId).Select(p => p.No).DefaultIfEmpty(0).Max() + 1;
                    vm.MoralItemEdit.MoralItemType        = Code.EnumHelper.MoralItemType.Select;
                    vm.MoralItemEdit.MoralItemOperateType = Code.EnumHelper.MoralItemOperateType.Score;
                }
            }
            vm.MoralGroupList    = MoralGroupController.SelectList(vm.MoralId);
            vm.MoralItemKindList = typeof(Code.EnumHelper.MoralItemKind).ToItemList();

            return(View(vm));
        }
예제 #2
0
        public ActionResult Edit(Models.Moral.Edit vm)
        {
            var moralId = 0;
            var error   = new List <string>();

            using (var db = new XkSystem.Models.DbContext())
            {
                var isExists = db.Table <Moral.Entity.tbMoral>().Count(p => p.MoralName.Equals(vm.MoralEdit.MoralName) && p.Id != vm.MoralEdit.Id) > 0;
                if (isExists)
                {
                    error.AddError("系统中已存在相同名字的德育设置记录!");
                }
                else
                {
                    if (vm.MoralEdit.ToDate <= vm.MoralEdit.FromDate)
                    {
                        error.AddError("结束时间必须大于开始时间!");
                    }
                    else
                    {
                        if (vm.MoralEdit.Id == 0)
                        {
                            Entity.tbMoral copyMoral = null;
                            if (vm.CreateWay == "复制历史" && vm.CopyMoralId == 0)
                            {
                                error.Add("请选择复制对象!");
                                return(Code.MvcHelper.Post(error));
                            }
                            else
                            {
                                copyMoral = db.Set <Entity.tbMoral>().Find(vm.CopyMoralId);
                            }
                            var tb = new Moral.Entity.tbMoral()
                            {
                                No        = vm.MoralEdit.No == null?db.Table <Moral.Entity.tbMoral>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : vm.MoralEdit.No.Value,
                                MoralName = vm.MoralEdit.MoralName,
                                tbYear    = db.Set <Basis.Entity.tbYear>().Find(vm.MoralEdit.tbYearId),
                                FromDate  = vm.MoralEdit.FromDate,
                                IsOpen    = vm.MoralEdit.IsOpen,
                                ToDate    = vm.MoralEdit.ToDate,
                                MoralType = copyMoral?.MoralType ?? vm.MoralEdit.MoralType
                            };

                            db.Set <Moral.Entity.tbMoral>().Add(tb);
                            if (db.SaveChanges() > 0)
                            {
                                Sys.Controllers.SysUserLogController.Insert("添加了德育设置!");
                                if (copyMoral == null)
                                {
                                    MoralGroupController.InsertDefault(db, tb.Id);
                                }
                            }
                            moralId = tb.Id;

                            #region  制
                            if (vm.CreateWay == "复制历史")
                            {
                                //德育班级
                                var moralClass = (from p in db.Table <Entity.tbMoralClass>().Include(p => p.tbClass) where p.tbMoral.Id == vm.CopyMoralId select p).ToList();
                                db.Set <Entity.tbMoralClass>().AddRange(moralClass.Select(p => new Entity.tbMoralClass()
                                {
                                    No      = p.No,
                                    tbClass = p.tbClass,
                                    tbMoral = tb
                                }));


                                //德育分组
                                var moralGroup = (from p in db.Table <Entity.tbMoralGroup>() where p.tbMoral.Id == vm.CopyMoralId select p).ToList();

                                //德育项目
                                var moralItem = (from p in db.Table <Entity.tbMoralItem>().Include(p => p.tbMoralGroup) where p.tbMoralGroup.tbMoral.Id == vm.CopyMoralId select p).ToList();

                                List <Entity.tbMoralOption> moralOption = new List <Entity.tbMoralOption>();
                                //德育选项
                                if (copyMoral.MoralType == Code.EnumHelper.MoralType.Once)
                                {
                                    moralOption = (from p in db.Table <Entity.tbMoralOption>() where p.tbMoralItem.tbMoralGroup.tbMoral.Id == vm.CopyMoralId select p).ToList();
                                }

                                moralGroup.ForEach(g =>
                                {
                                    var newGroup = new Entity.tbMoralGroup()
                                    {
                                        No             = g.No,
                                        MoralGroupName = g.MoralGroupName,
                                        tbMoral        = tb
                                    };
                                    db.Set <Entity.tbMoralGroup>().Add(newGroup);

                                    moralItem.Where(p => p.tbMoralGroup.Id == g.Id).ToList().ForEach(i =>
                                    {
                                        var newItem = new Entity.tbMoralItem()
                                        {
                                            No            = i.No,
                                            MinScore      = i.MinScore,
                                            MaxScore      = i.MaxScore,
                                            InitScore     = i.InitScore,
                                            DefaultValue  = i.DefaultValue,
                                            MoralExpress  = i.MoralExpress,
                                            MoralItemKind = i.MoralItemKind,
                                            MoralItemType = i.MoralItemType,
                                            MoralItemName = i.MoralItemName,
                                            tbMoralGroup  = newGroup
                                        };
                                        db.Set <Entity.tbMoralItem>().Add(newItem);

                                        //德育选项
                                        if (moralOption != null && moralOption.Any())
                                        {
                                            moralOption.Where(o => o.tbMoralItem.Id == i.Id).ToList().ForEach(o =>
                                            {
                                                var newMoralOption = new Entity.tbMoralOption()
                                                {
                                                    No = o.No,
                                                    MoralOptionName  = o.MoralOptionName,
                                                    MoralOptionValue = o.MoralOptionValue,
                                                    tbMoralItem      = newItem
                                                };
                                                db.Set <Entity.tbMoralOption>().Add(newMoralOption);
                                            });
                                        }
                                    });
                                });

                                //德育评价人员不复制,因为日期不一样
                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("复制了德育设置!");
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            var tb = (from p in db.Table <Moral.Entity.tbMoral>()
                                      where p.Id == vm.MoralEdit.Id
                                      select p).FirstOrDefault();

                            if (tb != null)
                            {
                                moralId = tb.Id;
                                tb.No   = vm.MoralEdit.No == null?db.Table <Moral.Entity.tbMoral>().Select(d => d.No).DefaultIfEmpty(0).Max() + 1 : (int)vm.MoralEdit.No;

                                tb.MoralName = vm.MoralEdit.MoralName;
                                tb.tbYear    = db.Set <Basis.Entity.tbYear>().Find(vm.MoralEdit.tbYearId);
                                tb.FromDate  = vm.MoralEdit.FromDate;
                                tb.ToDate    = vm.MoralEdit.ToDate;
                                tb.IsOpen    = vm.MoralEdit.IsOpen;
                                tb.MoralType = vm.MoralEdit.MoralType;
                                if (db.SaveChanges() > 0)
                                {
                                    XkSystem.Areas.Sys.Controllers.SysUserLogController.Insert("修改了德育设置");
                                }
                            }
                            else
                            {
                                error.AddError(Resources.LocalizedText.MsgNotFound);
                            }
                        }
                    }
                }

                if (string.IsNullOrWhiteSpace(Request["Step"].ConvertToString()))
                {
                    return(Code.MvcHelper.Post(error, Url.Action("List")));
                }
                else
                {
                    return(Code.MvcHelper.Post(error, Url.Action("List", "MoralClass", new { MoralId = moralId })));
                }
            }
        }
예제 #3
0
        public ActionResult Edit()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm    = new Models.MoralData.Edit();
                var moral = db.Set <Moral.Entity.tbMoral>().Find(vm.MoralId);
                if (moral == null)
                {
                    //moral = (from p in db.Table<Moral.Entity.tbMoral>() where DateTime.Now <= p.ToDate && DateTime.Now >= p.FromDate && p.IsOpen select p).FirstOrDefault();
                    moral = (from p in db.Table <Moral.Entity.tbMoral>() where p.IsOpen select p).FirstOrDefault();
                }
                if (moral == null)
                {
                    vm.DataIsNull = true;
                    return(View(vm));
                    //return RedirectToAction("List", "Moral");
                }
                switch (moral.MoralType)
                {
                case Code.EnumHelper.MoralType.Once:
                    return(RedirectToAction("OnceEdit", new { MoralId = vm.MoralId }));

                case Code.EnumHelper.MoralType.Days:
                    return(RedirectToAction("DayEdit", new { MoralId = vm.MoralId }));
                }

                if (vm.MoralDate == Code.DateHelper.MinDate)
                {
                    vm.MoralDate = DateTime.Now.Date;
                }
                vm.MoralId = moral.Id;

                vm.MoralClassList = MoralClassController.SelectList(vm.MoralId);

                if (vm.ClassId == 0 && vm.MoralClassList != null && vm.MoralClassList.Any())
                {
                    vm.ClassId = vm.MoralClassList[0].ClassId;
                }

                if (Code.Common.UserType != Code.EnumHelper.SysUserType.Administrator)
                {
                    //获取拥有评价权限的德育选项及班级列表
                    var classList = (from p in db.Table <Entity.tbMoralPowerClass>()
                                     where p.tbMoralPower.tbTeacher.tbSysUser.Id == Code.Common.UserId &&
                                     (p.tbMoralPower.MoralDate == vm.MoralDate || !p.tbMoralPower.MoralDate.HasValue) &&
                                     p.tbMoralPower.tbMoralItem.tbMoralGroup.tbMoral.Id == vm.MoralId
                                     select new //Models.MoralPower.Info()
                    {
                        MoralItemId = p.tbMoralPower.tbMoralItem.Id,
                        MoralItemName = p.tbMoralPower.tbMoralItem.MoralItemName,
                        ClassId = p.tbClass.Id,
                        ClassName = p.tbClass.ClassName
                    }).ToList();

                    classList.RemoveAll(p => !vm.MoralClassList.Select(t => t.ClassId).ToList().Contains(p.ClassId));

                    vm.MoralPowerClass = classList.GroupBy(p => new { p.MoralItemId, p.MoralItemName }).Select(p => new Models.MoralPower.Info()
                    {
                        MoralItemId   = p.Key.MoralItemId,
                        MoralItemName = p.Key.MoralItemName,
                        MoralClass    = new List <Dto.MoralClass.Info>()
                    }).ToList();

                    vm.MoralPowerClass.ForEach(p =>
                    {
                        p.MoralClass = classList.Where(c => c.MoralItemId == p.MoralItemId).Select(c => new Dto.MoralClass.Info()
                        {
                            ClassId   = c.ClassId,
                            ClassName = c.ClassName
                        }).ToList();
                    });
                }

                vm.MoralList = MoralController.SelectList();

                if (vm.MoralClassList == null || !vm.MoralClassList.Any())
                {
                    return(View(vm));
                }


                vm.MoralType = moral.MoralType;
                vm.FromDate  = moral.FromDate.ToString(Code.Common.StringToDate);
                vm.ToDate    = moral.ToDate.ToString(Code.Common.StringToDate);

                vm.KindId = vm.KindId ?? (int)Code.EnumHelper.MoralItemKind.Class;
                if (typeof(Code.EnumHelper.MoralItemKind).IsEnumDefined(vm.KindId))
                {
                    vm.Kind = (Code.EnumHelper.MoralItemKind)System.Enum.Parse(typeof(Code.EnumHelper.MoralItemKind), vm.KindId.ToString());
                }

                //分组列表
                vm.MoralGroupList = MoralGroupController.GetMoralGroupInfoList(vm.MoralId, vm.Kind);

                foreach (var group in vm.MoralGroupList)
                {
                    //根据分组获取德育选项
                    vm.MoralItemList.AddRange(MoralItemController.SelectList(group.Id, vm.Kind));

                    ////根据分组及评价权限获取德育选项
                    //var tb=(from p in db.Table<tbMoralPowerClass>)
                }

                vm.MoralItemIsNull = vm.MoralItemList == null || vm.MoralItemList.Count == 0;
                if (vm.MoralItemIsNull)
                {
                    return(View(vm));
                }


                var moralClassIds = vm.MoralClassList.Select(p => p.ClassId).ToList();

                vm.MoralDataList = (from p in db.Table <Moral.Entity.tbMoralData>()
                                    where
                                    p.CheckStatus == Code.EnumHelper.CheckStatus.Success &&
                                    p.tbMoralItem.tbMoralGroup.tbMoral.Id == vm.MoralId &&
                                    p.MoralDate == vm.MoralDate &&
                                    p.MoralItemOperateType == Code.EnumHelper.MoralItemOperateType.Score
                                    select new Dto.MoralData.List()
                {
                    Id = p.Id,
                    StudentId = p.tbStudent != null ? p.tbStudent.Id : 0,
                    StudentGroupId = p.tbClassGroup != null ? p.tbClassGroup.Id : 0,
                    ClassId = p.tbClass != null ? p.tbClass.Id : 0,
                    MoralItemId = p.tbMoralItem.Id,
                    DataText = p.DataText
                }).ToList();

                if (vm.ClassId > 0)
                {
                    moralClassIds = new List <int> {
                        vm.ClassId.Value
                    };
                }

                switch (vm.Kind)
                {
                case Code.EnumHelper.MoralItemKind.Student:
                    vm.StudentList = Student.Controllers.StudentController.GetStudentInfoListByClassIds(moralClassIds);
                    //vm.MoralClassListItem = MoralClassController.SelectItemList(vm.MoralId);
                    vm.MoralClassListItem = vm.MoralClassList.Select(p => new SelectListItem()
                    {
                        Text  = p.ClassName,
                        Value = p.ClassId.ToString()
                    }).ToList();
                    break;

                case Code.EnumHelper.MoralItemKind.Group:
                    //vm.MoralClassListItem = MoralClassController.SelectItemList(vm.MoralId);
                    vm.StudentGroupList   = Basis.Controllers.ClassGroupController.SelectList(moralClassIds);
                    vm.MoralClassListItem = vm.MoralClassList.Select(p => new SelectListItem()
                    {
                        Text  = p.ClassName,
                        Value = p.ClassId.ToString()
                    }).ToList();
                    break;

                case Code.EnumHelper.MoralItemKind.Class:
                    break;
                }
                return(View(vm));
            }
        }
예제 #4
0
        public ActionResult List()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm    = new Models.MoralItem.List();
                var moral = db.Table <Moral.Entity.tbMoral>().FirstOrDefault(d => d.Id == vm.MoralId);
                if (moral == null)
                {
                    moral = (from p in db.Table <Moral.Entity.tbMoral>() select p).FirstOrDefault();
                }
                if (moral == null)
                {
                    return(RedirectToAction("List", "Moral"));
                }
                vm.MoralId   = moral.Id;
                vm.MoralName = moral.MoralName;
                vm.MoralType = moral.MoralType;

                var tb = from p in db.Table <Moral.Entity.tbMoralItem>()
                         where p.tbMoralGroup.tbMoral.Id == vm.MoralId
                         select p;
                if (!string.IsNullOrWhiteSpace(vm.SearchText))
                {
                    tb = tb.Where(p => p.MoralItemName.Contains(vm.SearchText));
                }
                if (vm.MoralGroupId.HasValue && vm.MoralGroupId.Value > 0)
                {
                    tb = tb.Where(p => p.tbMoralGroup.Id == vm.MoralGroupId.Value);
                }

                if (vm.MoralKindId.HasValue && vm.MoralKindId.Value > -1)
                {
                    tb = tb.Where(p => (int)p.MoralItemKind == vm.MoralKindId);
                }

                vm.MoralItemList = (from p in tb
                                    orderby p.tbMoralGroup.Id, p.MoralItemName
                                    select new Dto.MoralItem.List()
                {
                    Id = p.Id,
                    No = p.No,
                    MoralItemName = p.MoralItemName,
                    InitScore = p.InitScore,
                    MaxScore = p.MaxScore,
                    MinScore = p.MinScore,
                    DefaultValue = p.DefaultValue,
                    MoralExpress = p.MoralExpress,
                    MoralItemKind = p.MoralItemKind,
                    MoralGroupName = p.tbMoralGroup.MoralGroupName,
                    MoralItemOperateType = p.MoralItemOperateType,
                    MoralItemType = p.MoralItemType,
                    AutoCheck = p.AutoCheck
                }).ToList();
                vm.MoralGroupList = MoralGroupController.SelectList(vm.MoralId);

                vm.MoralKindList = typeof(Code.EnumHelper.MoralItemKind).ToItemList();
                vm.MoralKindList.Insert(0, new SelectListItem()
                {
                    Text = "评价对象", Value = "-1"
                });
                return(View(vm));
            }
        }
예제 #5
0
        public ActionResult DayEdit()
        {
            using (var db = new XkSystem.Models.DbContext())
            {
                var vm    = new Models.MoralData.DayEdit();
                var moral = db.Set <Moral.Entity.tbMoral>().Find(vm.MoralId);

                if (moral == null)
                {
                    moral = (from p in db.Table <Moral.Entity.tbMoral>() where DateTime.Now <= p.ToDate && DateTime.Now >= p.FromDate select p).FirstOrDefault();
                }

                if (moral == null)
                {
                    vm.DataIsNull = true;
                    return(View(vm));
                    //return RedirectToAction("List", "Moral");
                }

                switch (moral.MoralType)
                {
                case Code.EnumHelper.MoralType.Many:
                    return(RedirectToAction("Edit", new { MoralId = vm.MoralId }));

                case Code.EnumHelper.MoralType.Once:
                    return(RedirectToAction("OnceEdit", new { MoralId = vm.MoralId }));
                }

                if (vm.MoralDate == Code.DateHelper.MinDate)
                {
                    vm.MoralDate = moral.FromDate;
                }

                vm.MoralId        = moral.Id;
                vm.MoralClassList = MoralClassController.SelectList(vm.MoralId);
                vm.MoralGroupList = MoralGroupController.GetMoralGroupInfoList(vm.MoralId);
                vm.MoralList      = MoralController.SelectList();

                vm.MoralType = moral.MoralType;

                vm.FromDate = moral.FromDate.ToString(Code.Common.StringToDate);
                vm.ToDate   = moral.ToDate.ToString(Code.Common.StringToDate);

                foreach (var group in vm.MoralGroupList)
                {
                    vm.MoralItemList.AddRange(MoralItemController.SelectList(group.Id));
                }
                foreach (var item in vm.MoralItemList)
                {
                    vm.MoralOptionList.AddRange(MoralOptionController.SelectList(item.Id));
                }
                var moralClassIds = (from p in db.Table <Moral.Entity.tbMoralClass>() where p.tbMoral.Id == vm.MoralId select p.tbClass.Id).ToList();
                vm.StudentList = Student.Controllers.StudentController.GetStudentInfoListByClassIds(moralClassIds);

                var moralItemIds = vm.MoralItemList.Select(p => p.Id);
                vm.MoralDataList = (from p in db.Table <Moral.Entity.tbMoralData>()
                                    where
                                    p.CheckStatus == Code.EnumHelper.CheckStatus.Success &&
                                    moralItemIds.Contains(p.tbMoralItem.Id) &&
                                    vm.MoralDate == p.MoralDate
                                    orderby p.No
                                    select new Dto.MoralData.OnceList()
                {
                    Id = p.Id,
                    DataText = p.DataText,
                    MoralItemId = p.tbMoralItem.Id,
                    MoralOptionId = p.tbMoralOption != null ? p.tbMoralOption.Id : 0,
                    StudentId = p.tbStudent.Id,
                    StudentName = p.tbStudent.StudentName,
                    SysUserName = p.tbSysUser.UserName
                }).ToList();


                return(View(vm));
            }
        }