Exemple #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));
        }
        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));
            }
        }