public void GivenThatHouseHasOneAncestralWeapon_WhenAccessingAdapterAncestralWeapons_ThenAdapterAncestralWeaponsAreTheSame() { var entity = new HouseEntity { AncestralWeapons = new[] { "Old Sword" } }; var adapter = new HouseEntityAdapter(entity); Assert.AreEqual(entity.AncestralWeapons.Length, adapter.AncestralWeapons.Count); }
public HouseDto MapToDto(HouseEntity houseEntity) { return(new HouseDto() { Id = houseEntity.Id, ZipCode = houseEntity.ZipCode, City = houseEntity.City, Street = houseEntity.Street }); }
public void GivenThatHouseHasDiedOutData_WhenAccessingAdapterDiedOut_ThenAdapterDiedOutIsSame() { var entity = new HouseEntity { DiedOut = "Year one" }; var adapter = new HouseEntityAdapter(entity); Assert.AreEqual(entity.DiedOut, adapter.DiedOut); }
public long AddNewHouse(HouseDTO houseDto) { HouseEntity houseEntity = ToEntity(houseDto); using (ZSZDbContext ctx = new ZSZDbContext()) { ctx.Houses.Add(houseEntity); ctx.SaveChanges(); return(houseEntity.Id); } }
public IActionResult GetSingle(int id) { HouseEntity houseEntityFromRepo = _houseRepository.GetSingle(id); if (houseEntityFromRepo == null) { return(NotFound()); } return(Ok(Mapper.Map <HouseDto>(houseEntityFromRepo))); }
public IActionResult GetSingle(int id) { HouseEntity houseEntity = _houseRepository.GetSingle(id); if (houseEntity == null) { return(NotFound()); } return(Ok(_houseMapper.MapToDto(houseEntity))); }
public HouseEntity Update(HouseEntity toUpdate) { HouseEntity single = GetSingle(toUpdate.Id); if (single == null) { return(null); } _houses[single.Id] = toUpdate; return(toUpdate); }
public void GivenThatHouseHasOneCadetBranch_WhenAccessingAdapterCadetBranches_ThenAdapterHasOneCadetBranch() { var entity = new HouseEntity { CadetBranches = new List <HouseEntity> { new HouseEntity() } }; var adapter = new HouseEntityAdapter(entity); Assert.AreEqual(entity.CadetBranches.Count, adapter.CadetBranches.Count); }
public ViewHouseEntity() { HouseEntity = new HouseEntity(); _statistics = new List <StatisticsHTs>(); StatPlotModel = new PlotModel { Title = "Статистика", Axes = { new DateTimeAxis { Position = AxisPosition.Bottom, StringFormat = "HH:mm" } } }; }
public void GivenThatHouseHasOneSwornMember_WhenAccessingAdapterSwornMembers_ThenAdapterHasOneSwornMember() { var entity = new HouseEntity { SwornMembers = new List <CharacterEntity> { new CharacterEntity() } }; var adapter = new HouseEntityAdapter(entity); Assert.AreEqual(entity.SwornMembers.Count, adapter.SwornMembers.Count); }
public GetHouseResultEntity Post(GetHousesRequestModel req) { Logger.LogDebug("GetHouses Request:" + JsonHelper.SerializeObject(req), "GetHousesController", "Post"); GetHouseResultEntity ret = new GetHouseResultEntity() { Code = 0, ErrMsg = "" }; try { var _houseList = _houseBLL.GetModels(x => x.HouseEstateID == req.HouseEstateID).OrderBy(x => x.ID).ToList(); var _tmpGroup = _houseList.Where(x => x.HouseGroup.Name.Contains(req.SearchStr)); var _tmpBlock = _houseList.Where(x => x.Block.Contains(req.SearchStr)); var _tmpBuilding = _houseList.Where(x => x.Building.ToString().Contains(req.SearchStr)); var _tmpHouseList = _tmpGroup.Union(_tmpBlock).Union(_tmpBuilding); var _endHouseList = _tmpHouseList.Skip((req.PageIndex - 1) * req.PageSize).Take(req.PageSize); var _retHouseList = new List <HouseEntity>(); foreach (var _hs in _endHouseList) { var _retHouse = new HouseEntity() { HouseID = _hs.ID, SerialNumber = _hs.SerialNumber, Group = _hs.HouseGroup.Name, Block = _hs.Block, Building = _hs.Building, Unit = _hs.Unit, RoomNumber = _hs.RoomNumber, Toward = _hs.Toward, RoomType = _hs.RoomType.Name, EstimateBuiltUpArea = _hs.EstimateBuiltUpArea, EstimateLivingArea = _hs.EstimateLivingArea, AreaUnitPrice = _hs.AreaUnitPrice, TotalPrice = _hs.TotalPrice, SubscriberID = _hs.SubscriberID, SubscriberName = _hs.SubscriberID == null ? "" : _hs.Subscriber.Name }; _retHouseList.Add(_retHouse); } ret.HouseList = _retHouseList; ret.RecordCount = _tmpHouseList.Count(); } catch (Exception ex) { Logger.LogException("搜索房源信息时发生异常!", "GetHousesController", "Post", ex); ret.Code = 999; ret.ErrMsg = ex.Message; } return(ret); }
public IActionResult Delete(int id) { HouseEntity houseEntityToDelete = _houseRepository.GetSingle(id); if (houseEntityToDelete == null) { return(NotFound()); } _houseRepository.Delete(id); return(NoContent()); }
public void GivenThatHouseHasHeir_WhenAccessingAdapterHeir_ThenAdapterHeirHasData() { var entity = new HouseEntity { Heir = new CharacterEntity { Name = "heirName" } }; var adapter = new HouseEntityAdapter(entity); Assert.IsNotNull(adapter.Heir); Assert.AreEqual(entity.Heir.Name, adapter.Heir.Name); }
public void GivenThatHouseHasCurrentLord_WhenAccessingAdapterCurrentLord_ThenAdapterCurrentLordHasData() { var entity = new HouseEntity { CurrentLord = new CharacterEntity { Name = "currentLordName" } }; var adapter = new HouseEntityAdapter(entity); Assert.IsNotNull(adapter.CurrentLord); Assert.AreEqual(entity.CurrentLord.Name, adapter.CurrentLord.Name); }
public IHttpActionResult Delete(int id) { HouseEntity houseEntityToDelete = _houseRepository.GetSingle(id); if (houseEntityToDelete == null) { return(NotFound()); } _houseRepository.Delete(id); return(StatusCode(HttpStatusCode.NoContent)); }
public void GivenThatHouseHasOverlord_WhenAccessingAdapterOverlord_ThenAdapterOverlordHasData() { var entity = new HouseEntity { Overlord = new HouseEntity { Name = "overlordName" } }; var adapter = new HouseEntityAdapter(entity); Assert.IsNotNull(adapter.Overlord); Assert.AreEqual(entity.Overlord.Name, adapter.Overlord.Name); }
public AttachmentDTO[] GetAttachment(long houseId) { using (ZSZDbContext ctx = new ZSZDbContext()) { CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx); HouseEntity house = cs.GetById(houseId); if (house == null) { throw new ArgumentException("房子不存在" + houseId); } return(house.AttachmentEntities.ToList().Select(a => ToDTO(a)).ToArray()); } }
public void GivenThatHouseHasFounder_WhenAccessingAdapterFounder_ThenAdapterFounderHasData() { var entity = new HouseEntity { Founder = new CharacterEntity() { Name = "founderName" } }; var adapter = new HouseEntityAdapter(entity); Assert.IsNotNull(adapter.Founder); Assert.AreEqual(entity.Founder.Name, adapter.Founder.Name); }
public void UpdateHouse(HouseDTO houseDto) { HouseEntity houseEntity = ToEntity(houseDto); using (ZSZDbContext ctx = new ZSZDbContext()) { var house = ctx.Houses.SingleOrDefault(h => h.Id == houseDto.Id); if (house == null) { throw new ArgumentException("房子信息不存在" + houseDto.Id); } house = houseEntity; ctx.SaveChanges(); } }
public HousePicDTO[] GetPics(long houseId) { using (RhDbContext ctx = new RhDbContext()) { CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx); HouseEntity house = cs.GetById(houseId); //妈的这里忘了判断pic是否deleted的情况 return(house.HousePics.Where(p => p.IsDeleted == false).Select(p => new HousePicDTO { HouseId = p.HouseId, Url = p.Url, ThumbUrl = p.ThumbUrl, Id = p.Id, CreateDateTime = p.CreateDateTime }).ToArray()); } }
public GetHouseResultEntity Post(GetAllHouseInfoRequestModel req) { Logger.LogDebug("GetAllHouseInfo Request:" + JsonHelper.SerializeObject(req), "GetAllHouseInfoController", "Post"); GetHouseResultEntity ret = new GetHouseResultEntity() { Code = 0, ErrMsg = "" }; try { var _houseList = _houseBLL.GetModelsByPage(req.PageSize, req.PageIndex, true, x => x.ID, x => x.HouseEstateID == req.HouseEstateID); var _retHouseList = new List <HouseEntity>(); foreach (var _hs in _houseList) { var _retHouse = new HouseEntity() { HouseID = _hs.ID, SerialNumber = _hs.SerialNumber, Group = _hs.HouseGroup.Name, Block = _hs.Block, Building = _hs.Building, Unit = _hs.Unit, RoomNumber = _hs.RoomNumber, Toward = _hs.Toward, RoomType = _hs.RoomType.Name, EstimateBuiltUpArea = _hs.EstimateBuiltUpArea, EstimateLivingArea = _hs.EstimateLivingArea, AreaUnitPrice = _hs.AreaUnitPrice, TotalPrice = _hs.TotalPrice, SubscriberID = _hs.SubscriberID, //SubscriberName = _hs.SubscriberID == null ? "" : _hs.Subscriber.Name }; _retHouseList.Add(_retHouse); } ret.HouseList = _retHouseList; ret.RecordCount = _houseBLL.GetModels(x => x.HouseEstateID == req.HouseEstateID).Count(); } catch (Exception ex) { Logger.LogException("按楼盘ID获取房源信息时发生异常!", "GetAllHouseInfoController", "Post", ex); ret.Code = 999; ret.ErrMsg = ex.Message; } return(ret); }
private HouseDTO ToDTO(HouseEntity entity) { HouseDTO dto = new HouseDTO(); dto.Address = entity.Address; dto.Area = entity.Area; dto.AttachmentIds = entity.Attachments.Select(a => a.Id).ToArray(); //从HouseEntity中的Attachenments查找到id,转为数组 dto.CheckInDateTime = entity.CheckinDateTime; dto.CityId = entity.Communitie.Region.CityId; dto.CityName = entity.Communitie.Region.City.Name; dto.CommunityBuiltYear = entity.Communitie.BuiltYear; dto.CommunityId = entity.CommunityId; dto.CommunityLocation = entity.Communitie.Location; dto.CommunityName = entity.Communitie.Name; dto.CommunityTraffic = entity.Communitie.Traffic; dto.CreateDateTime = entity.CreateDateTime; dto.DecorateStatusId = entity.DecorateStatusId; dto.DecorateStatusName = entity.DecorateStatus.Name; dto.Description = entity.Description; dto.Direction = entity.Direction; //看第一张图 var firstPic = entity.HousePics.FirstOrDefault(); //先判断有没有图片 if (firstPic != null) { dto.FirstThumbUrl = firstPic.ThumbUrl; } dto.FloorIndex = entity.FloorIndex; dto.Id = entity.Id; dto.LookableDateTime = entity.LookableDateTime; dto.MonthRent = entity.MonthRent; dto.OwnerName = entity.OwnerName; dto.OwnerPhoneNum = entity.OwnerPhoneNum; dto.RegionId = entity.Communitie.RegionId; dto.RegionName = entity.Communitie.Region.Name; dto.RoomTypeId = entity.RoomTypeId; dto.RoomTypeName = entity.RoomType.Name; dto.StatusId = entity.StatusId; dto.StatusName = entity.Status.Name; dto.TotalFloorCount = entity.TotalFloorCount; dto.TypeId = entity.TypeId; dto.TypeName = entity.Type.Name; return(dto); }
public IHttpActionResult Create([FromBody] HouseDto houseDto) { if (houseDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } HouseEntity houseEntity = houseMapper.MapToEntity(houseDto); houseRepository.Add(houseEntity); return(Ok(houseEntity)); }
public IActionResult Create([FromBody] HouseDto houseDto) { if (houseDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } HouseEntity houseEntity = _houseMapper.MapToEntity(houseDto); _houseRepository.Add(houseEntity); return(CreatedAtRoute("GetSingleHouse", new { id = houseEntity.Id }, _houseMapper.MapToDto(houseEntity))); }
/// <summary> /// Retreives the house entity using CHN number /// </summary> /// <param name="chn">Census house number</param> /// <returns></returns> public HouseDTO GetHouseByCHN(long chn) { try { HouseEntity house = db.Houses.FirstOrDefault(s => s.CensusHouseNumber == chn); if (house == null) { return(null); } else { return(mapper.Map <HouseDTO>(house)); } } catch (Exception ex) { throw new DALException("Unable to Create House Listing" + ex.Message); } }
public IActionResult GetSingle(int id) { try { HouseEntity houseEntity = _houseRepository.GetSingle(id); if (houseEntity == null) { return(NotFound()); } return(Ok(_houseMapper.MapToDto(houseEntity))); } catch (Exception exception) { //logg exception or do anything with it return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
private HouseDTO ToDTO(HouseEntity house) { HouseDTO dto = new HouseDTO(); dto.Address = house.Address; dto.Area = house.Area; dto.AttachmentIds = house.Attachments.Select(a => a.Id).ToArray(); dto.CheckInDateTime = house.CheckInDateTime; dto.CityId = house.Community.Region.CityId; dto.CityName = house.Community.Region.City.Name; dto.CommunityBuiltYear = house.Community.BuiltYear; dto.CommunityId = house.CommunityId; dto.CommunityLocation = house.Community.Location; dto.CommunityName = house.Community.Name; dto.CommunityTraffic = house.Community.Traffic; dto.CreateDateTime = house.CreateDateTime; dto.DecorateStatusId = house.DecorateStatusId; dto.DecorateStatusName = house.DecorateStatus.Name; dto.Description = house.Description; dto.Direction = house.Direction; var firstPic = house.HousePics.FirstOrDefault(); if (firstPic != null) { dto.FirstThumbUrl = firstPic.ThumbUrl; } dto.FloorIndex = house.FloorIndex; dto.Id = house.Id; dto.LookableDateTime = house.LookableDateTime; dto.MonthRent = house.MouthRent; dto.OwnerName = house.OwnerName; dto.OwnerPhoneNum = house.OwnerPhoneNum; dto.RegionId = house.Community.RegionId; dto.RegionName = house.Community.Region.Name; dto.RoomTypeId = house.RoomTypeId; dto.RoomTypeName = house.RoomType.Name; dto.StatusId = house.StatusId; dto.StatusName = house.Status.Name; dto.TotalFloorCount = house.TotalFloorCount; dto.TypeId = house.TypeId; dto.TypeName = house.Type.Name; return(dto); }
public List <HouseEntity> GetAll() { try { CondominiumManagementSystemDBEntities entity = new CondominiumManagementSystemDBEntities(); List <HouseEntity> houseEntities = new List <HouseEntity>(); List <tblHouse> houses = entity.tblHouses.ToList(); foreach (tblHouse house in houses) { HouseEntity houseEntity = new HouseEntity(); houseEntity.ID = house.ID; houseEntity.RegionID = house.RegionID; houseEntity.SubCityID = house.SubCityID; houseEntity.WoredaID = house.WoredaID; houseEntity.BlockNumber = house.BlockNumber; houseEntity.FloorNumber = house.FloorNumber; houseEntity.GovernmentTransferedDate = house.GovernmentTransferedDate; houseEntity.HouseNumber = house.HouseNumber; houseEntity.SiteName = house.SiteName; houseEntity.RegionEntity = new RegionEntity(); houseEntity.RegionEntity.ID = house.tblRegion.ID; houseEntity.RegionEntity.TItle = house.tblRegion.TItle; houseEntity.SubCityEntity = new SubCityEntity(); houseEntity.SubCityEntity.ID = house.tblSubCity.ID; houseEntity.SubCityEntity.TItle = house.tblSubCity.TItle; houseEntity.WoredaEntity = new WoredaEntity(); houseEntity.WoredaEntity.ID = house.tblWoreda.ID; houseEntity.WoredaEntity.TItle = house.tblWoreda.TItle; houseEntities.Add(houseEntity); } return(houseEntities); } catch (Exception) { return(null); } }
public IActionResult Delete(int id) { try { HouseEntity houseEntityToDelete = _houseRepository.GetSingle(id); if (houseEntityToDelete == null) { return(NotFound()); } _houseRepository.Delete(id); return(NoContent()); } catch (Exception exception) { //logg exception or do anything with it return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public IActionResult Patch(int id, [FromBody] JsonPatchDocument <HouseDto> housePatchDocument) { try { if (housePatchDocument == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } HouseEntity houseEntity = _houseRepository.GetSingle(id); if (houseEntity == null) { return(NotFound()); } HouseDto existingHouse = _houseMapper.MapToDto(houseEntity); housePatchDocument.ApplyTo(existingHouse, ModelState); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _houseRepository.Update(_houseMapper.MapToEntity(existingHouse)); return(Ok(existingHouse)); } catch (Exception exception) { //logg exception or do anything with it return(StatusCode((int)HttpStatusCode.InternalServerError)); } }