public ActionResult Edit(HouseEditDTO model) { if (houseService.Update(model)) { return(Json(new AjaxResult { Status = "ok" })); } else { return(Json(new AjaxResult { Status = "error", ErrorMsg = "更新失败" })); } }
public bool Update(HouseEditDTO house) { using (MyDbContext dbc = new MyDbContext()) { CommonService <HouseEntity> cs = new CommonService <HouseEntity>(dbc); HouseEntity entity = cs.GetById(house.Id); if (entity == null) { return(false); } entity.Address = house.Address; entity.Area = house.Area; entity.Attachments.Clear(); var ams = dbc.Attachments.Where(a => a.IsDeleted == false && house.AttachmentIds.Contains(a.Id)); foreach (var am in ams) { entity.Attachments.Add(am); } entity.CheckInDateTime = house.CheckInDateTime; entity.CommunityId = house.CommunityId; entity.DecorateStatusId = house.DecorateStatusId; entity.Description = house.Description; entity.Direction = house.Direction; entity.FloorIndex = house.FloorIndex; entity.LookableDateTime = house.LookableDateTime; entity.MouthRent = house.MonthRent; entity.OwnerName = house.OwnerName; entity.OwnerPhoneNum = house.OwnerPhoneNum; entity.RoomTypeId = house.RoomTypeId; entity.StatusId = house.StatusId; entity.TotalFloorCount = house.TotalFloorCount; entity.TypeId = house.TypeId; dbc.SaveChanges(); return(true); } }