コード例 #1
0
        public ActionResult Edit(int id = 0)
        {
            var vm = new Models.MoralDataReason.Edit();

            using (var db = new XkSystem.Models.DbContext())
            {
                if (id > 0)
                {
                    var tb = (from p in db.Table <Entity.tbMoralDataReason>()
                              where p.Id == id
                              select new Dto.MoralDataReason.Edit()
                    {
                        Id = p.Id,
                        No = p.No,
                        Reason = p.Reason,
                        tbMoralItemId = p.tbMoralItem.Id
                    }).FirstOrDefault();
                    if (tb != null)
                    {
                        vm.MoralDataReasonEdit = tb;
                    }
                }
                else
                {
                    var maxNo = (from p in db.Table <Entity.tbMoralDataReason>() select p.No).DefaultIfEmpty().Max();
                    vm.MoralDataReasonEdit.No = (maxNo.HasValue?maxNo.Value:0) + 1;
                }
                vm.MoralItemList = MoralItemController.SelectListByMoralId(vm.MoralId).Select(p => new SelectListItem()
                {
                    Text = p.MoralItemName, Value = p.Id.ToString()
                }).ToList();
            }
            return(View(vm));
        }
コード例 #2
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));
            }
        }
コード例 #3
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));
            }
        }