Ejemplo n.º 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));
        }
Ejemplo n.º 2
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));
            }
        }