/// <summary> /// DTO添加数据 /// </summary> /// <param name="inputentity"></param> /// <returns></returns> public bool DTOAdd(HouseInfoInputDTO inputentity) { HouseInfo dataModel = Mapper.Map <HouseInfoInputDTO, HouseInfo>(inputentity); dataModel.State = true; if (houseInfoDAL.AddAndSaveChange(dataModel) > 0) { return(true); } else { return(false); } }
/// <summary> /// 数据更新 /// </summary> /// <param name="HouseInfoJson">前端返回的JSON数据</param> /// <returns></returns> public string HouseInfoUpdate(string HouseInfoJson) { int outID; //Json转实体类 HouseInfoInputDTO houseInfo = JsonConvert.DeserializeObject <HouseInfoInputDTO>(HouseInfoJson); if (HouseInfoService.DTOUpdate(houseInfo, out outID) > 0) { return("ok"); } else { return("no"); } }
/// <summary> /// 添加房屋信息 /// </summary> /// <param name="HouseInfoJson">前端返回的json数据</param> /// <returns></returns> public string HouseInfoAdd(string HouseInfoJson) { //添加数据 //Json转实体类 HouseInfoInputDTO houseInfo = JsonConvert.DeserializeObject <HouseInfoInputDTO>(HouseInfoJson); if (HouseInfoService.DTOAdd(houseInfo)) { return("ok"); } else { return("no"); } }
/// <summary> /// 更新数据 /// </summary> /// <param name="inputEntity"></param> /// <returns></returns> public int DTOUpdate(HouseInfoInputDTO inputEntity, out int outID) { //先查房屋信息 AsNoTracking() 不追踪 outID = 0; HouseInfo checkmodel = houseInfoDAL.LoadEntities(u => u.HousID == inputEntity.HousID).AsNoTracking().FirstOrDefault(); if (checkmodel != null) { //AutoMap转换 HouseInfo dataModel = Mapper.Map <HouseInfoInputDTO, HouseInfo>(inputEntity); //修改数据 dataModel.UserID = checkmodel.UserID; dataModel.State = checkmodel.State; dataModel.ID = checkmodel.ID; //把ID赋值,让EF知道应该修改哪条数据 outID = dataModel.ID; //给ID赋值 return(houseInfoDAL.EditAndSaveChange(dataModel)); } else { return(0); } }