public ActionResult EditAttr(long?id) { var entObj = new AttrModel();//初始化基础数据 if (id != null && id != 0) { entObj = _AttrAppService.GetAttr(id.Value); } entObj.AttrTypeList = _AttrTypeAppService.AttrTypeList(); return(View(entObj)); }
/// <summary> /// 更新和新增属性 /// </summary> /// <param name="input"></param> /// <returns></returns> public AttrModel InsertOrUpdateAttr(AttrModel input) { if (_AttrCase.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name)) { throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!"); } //var entObj =input.MapTo<Attr>(); var entObj = _AttrCase.GetAll().FirstOrDefault(x => x.Id == input.Id) ?? new Attr(); entObj = Fun.ClassToCopy(input, entObj, (new string[] { "Id" }).ToList()); //var entObj= AutoMapper.Mapper.Map<Attr>(input); var id = _AttrCase.InsertOrUpdateAndGetId(entObj); return(entObj.MapTo <AttrModel>()); }