Example #1
0
        public ActionResult EditSubitem(long?id)
        {
            var entObj = new SubitemModel();//初始化基础数据

            if (id != null && id != 0)
            {
                entObj = _SubitemAppService.GetSubitem(id.Value);
            }
            entObj.SubitemTypeList = _SubitemTypeAppService.SubitemTypeList();
            //List<SelectListItem> objList = new List<SelectListItem>();
            //objList.Add(new SelectListItem { Text = "--请选择--", Value = "" });
            //var typeList = _SubitemTypeAppService.SubitemTypeList();
            //if(typeList!=null&&typeList.Count>0)
            //{
            //    objList.InsertRange(1, typeList);
            //}
            //entObj.SubitemTypeList = objList;
            return(View(entObj));
        }
Example #2
0
        /// <summary>
        /// 更新和新增打分项
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public SubitemModel InsertOrUpdateSubitem(SubitemModel input)
        {
            if (_SubitemCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name))
            {
                throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!");
            }
            //var entObj =input.MapTo<Subitem>();
            var entObj = _SubitemCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new Subitem();

            entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList());
            //var entObj= AutoMapper.Mapper.Map<Subitem>(input);
            var resObj = _SubitemCase.InsertOrUpdate(entObj);

            if (resObj == null)
            {
                throw new UserFriendlyException("新增或更新失败!");
            }
            else
            {
                return(resObj.MapTo <SubitemModel>());
            }
        }