public long AddNew(HouseDTO house) { using (MyDbContext ctx = new MyDbContext()) { HouseEntity entity = new HouseEntity(); entity.CommunityId = house.CommunityId; entity.RoomTypeId = house.RoomTypeId; entity.Address = house.Address; entity.StatusId = house.StatusId; entity.MonthRent = house.MonthRent; entity.Area = house.Area; entity.DecorateStatusId = house.DecorateStatusId; entity.TotalFloorCount = house.TotalFloorCount; entity.FloorIndex = house.FloorIndex; entity.TypeId = house.TypeId; entity.Direction = house.Direction; entity.LookableDateTime = house.LookableDateTime; entity.CheckInDateTime = house.CheckInDateTime; entity.OwnerName = house.OwnerName; entity.OwnerPhoneNum = house.OwnerPhoneNum; BaseService <AttachmentEntity> attBS = new BaseService <AttachmentEntity>(ctx); var atts = attBS.GetAll().Where(e => house.AttachementIds.Contains(e.Id)); foreach (var att in atts) { entity.Attachments.Add(att); } ctx.Houses.Add(entity); ctx.SaveChanges(); return(entity.Id); } }
private HouseDTO ToDTO(HouseEntity house) { HouseDTO houseDto = new HouseDTO(); houseDto.Address = house.Address; houseDto.Area = house.Area; houseDto.BuiltYear = house.CommunitityEntity.BuiltYear; houseDto.CheckInDateTime = house.CheckInDateTime; houseDto.CommunityId = house.CommunityId; houseDto.CommunityName = house.CommunitityEntity.Name; houseDto.CommunityLocation = house.CommunitityEntity.Location; houseDto.DecorateStatusId = house.DecorateStatusId; houseDto.DecorateStatusName = house.DecorateStatus.Name; houseDto.Description = house.Description; houseDto.Direction = house.Direction; houseDto.FloorIndex = house.FloorIndex; houseDto.LookableDateTime = house.LookableDateTime; houseDto.MonthRent = house.MonthRent; houseDto.OwnerName = house.OwnerName; houseDto.OwnerPhoneNum = house.OwnerPhoneNum; houseDto.RoomTypeId = house.RoomTypeId; houseDto.RoomTypeName = house.RoomType.Name; houseDto.StatusId = house.StatusId; houseDto.StatusName = house.Status.Name; houseDto.TotalFloatCount = house.TotalFloatCount; houseDto.Traffic = house.CommunitityEntity.Traffic; houseDto.TypeId = house.TypeId; houseDto.TypeName = house.Type.Name; houseDto.RegionId = house.CommunitityEntity.RegionId; houseDto.RegionName = house.CommunitityEntity.RegionEntity.Name; houseDto.Id = house.Id; houseDto.CreateDateTime = house.CreateDateTime; return(houseDto); }
public HouseDTO GetHouseById(int p_id) { HouseDTO house; string sql = "SELECT * FROM Houses WHERE HouseId = @id"; using (SqlConnection sqlCon = new SqlConnection(_connectionString)) { sqlCon.Open(); using (SqlCommand sqlCmd = new SqlCommand(sql, sqlCon)) { sqlCmd.Parameters.Add("@id", SqlDbType.Int).Value = p_id; SqlDataReader rdr = sqlCmd.ExecuteReader(); if (rdr.Read()) { int id = rdr.GetInt32(0); string name = rdr.GetString(1); int nOfU = rdr.GetInt32(2); house = new HouseDTO(id, name, nOfU); } else { house = new HouseDTO(); } }; sqlCon.Close(); }; return(house); }
public IActionResult SearchStationsHouse(HouseDTO house) { List <PollingStation> pollingStations = _context.PollingStation.Where(ps => ps.HouseId == house.IdHouse).ToList().GroupBy(p => p.Name).Select(grp => grp.First()).ToList(); if (pollingStations.Any()) { int[] stationsId = pollingStations.Select(p => p.StationId ?? 0).ToArray(); if (stationsId.Any()) { List <Station> stations = _context.Station.Where(s => stationsId.Contains(s.IdStation)).ToList(); List <StationDTO> stationDTOs = stations.Select(s => new StationDTO { IdStation = s.IdStation, Name = s.Name }).ToList(); return(Ok(stationDTOs)); } else { return(NoContent()); } } else { return(NoContent()); } }
public void Update(HouseDTO house) { using (RhDbContext ctx = new RhDbContext()) { CommonService <HouseEntity> cs = new CommonService <HouseEntity>(ctx); HouseEntity houseEntity = cs.GetById(house.Id); houseEntity.Address = house.Address; houseEntity.Area = house.Area; houseEntity.Attachments.Clear(); //先删掉再添加 var atts = ctx.Attachments.Where(a => a.IsDeleted == false && house.AttachmentIds.Contains(a.Id)); foreach (var att in atts) { houseEntity.Attachments.Add(att); } houseEntity.CommunityId = house.CommunityId; houseEntity.CheckInDateTime = house.CheckInDateTime; houseEntity.Description = house.Description; houseEntity.DecorateStatusId = house.DecorateStatusId; //单元测试不充分呀。。这里写错了,后面才发现 houseEntity.Direction = house.Direction; houseEntity.FloorIndex = house.FloorIndex; houseEntity.LookableDateTime = house.LookableDateTime; houseEntity.MonthRent = house.MonthRent; houseEntity.OwnerName = house.OwnerName; houseEntity.OwnerPhoneNum = house.OwnerPhoneNum; houseEntity.RoomTypeId = house.RoomTypeId; houseEntity.StatusId = house.StatusId; houseEntity.TypeId = house.TypeId; houseEntity.TotalFloorCount = house.TotalFloorCount; ctx.SaveChanges(); } }
public void Update(HouseDTO house) { using (ZSZDbContext ctx = new ZSZDbContext()) { BaseService <HouseEntity> bs = new BaseService <HouseEntity>(ctx); HouseEntity entity = bs.GetById(house.Id); entity.Address = house.Address; entity.Area = house.Area; //2,3,4 entity.Attachments.Clear();//先删再加 var atts = ctx.Attachments.Where(a => a.IsDeleted == false && house.AttachmentIds.Contains(a.Id)); foreach (AttachmentEntity att in atts) { entity.Attachments.Add(att); } //3,4,5 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.MonthRent = 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; ctx.SaveChanges(); } }
private void CreateStaticPage(long houseId) { HouseIndexViewModel houseIndexView = null; HouseDTO house = HouseService.GetById(houseId); if (house == null) { return; } var housePics = HousePicService.GetPics(houseId); var attachments = AttachmentService.GetAttachment(houseId); houseIndexView = new HouseIndexViewModel { House = house, HousePics = housePics, Attachments = attachments }; this.ControllerContext.Controller.ViewData.Model = houseIndexView; string html = WebCommonHelper.RendViewToString( this.ControllerContext, "~/views/House/StaticIndex.cshtml", ""); System.IO.File.AppendAllText(String.Format(@"D:\PersonalWorkSpace\github\ZSZ\ZSZ.FrontWeb\{0}.html", houseId), html); }
private void btnSearch_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); try { HouseDTO obj = new HouseDTO(); obj.ID = -1; obj.FeeMonth = string.IsNullOrWhiteSpace(txtFeeMonth.Text) ? -1 : Convert.ToInt32(txtFeeMonth.Text); obj.RoomNumber = string.IsNullOrWhiteSpace(txtRoomNumber.Text) ? -1 : Convert.ToInt32(txtRoomNumber.Text); obj.IDEmployee = Convert.ToInt64((cboEmployee.SelectedItem as clsComboItem).Value); obj.IDHouseholder = Convert.ToInt64((cboHouseholder.SelectedItem as clsComboItem).Value); obj.IDHouseType = Convert.ToInt64((cboHouseType.SelectedItem as clsComboItem).Value); obj.IDLocation = Convert.ToInt64((cboLocation.SelectedItem as clsComboItem).Value); ds = HouseDAO.House_Search(obj); if (ds != null && ds.Tables.Count > 0) { dgvHouse.DataSource = ds.Tables[0].Copy(); } else { clsMessages.ShowWarning("Không tìm thấy"); } } catch (Exception ex) { clsMessages.ShowErrorException(ex); } finally { ds.Dispose(); } }
public async Task <string> Create(HouseDTO house) { dbContext.Add(house); await dbContext.SaveChangesAsync(); return(house.Id); }
private HouseEntity ToEntity(HouseDTO houseDto) { HouseEntity house = new HouseEntity(); house.Address = houseDto.Address; house.Area = houseDto.Area; house.CheckInDateTime = houseDto.CheckInDateTime; house.CommunityId = houseDto.CommunityId; //house.CommunityName = houseDto.CommunitityEntity.Name; house.DecorateStatusId = houseDto.DecorateStatusId; //house.DecorateStatusName = houseDto.DecorateStatus.Name; house.Description = houseDto.Description; house.Direction = houseDto.Direction; house.FloorIndex = houseDto.FloorIndex; house.LookableDateTime = houseDto.LookableDateTime; house.MonthRent = houseDto.MonthRent; house.OwnerName = houseDto.OwnerName; house.OwnerPhoneNum = houseDto.OwnerPhoneNum; house.RoomTypeId = houseDto.RoomTypeId; //house.RoomTypeName = houseDto.RoomType.Name; house.StatusId = houseDto.StatusId; //house.StatusName = houseDto.Status.Name; house.TotalFloatCount = houseDto.TotalFloatCount; house.TypeId = houseDto.TypeId; //house.TypeName = houseDto.Type.Name; //house.Id = houseDto.Id; //house.CreateDateTime = houseDto.CreateDateTime; return(house); }
public RequestMessageFormat <HouseDTO> GetById(int id) { RequestMessageFormat <HouseDTO> response = new RequestMessageFormat <HouseDTO>(); try { House house = this.HouseRepository.FindById(id); HouseDTO houseDTO = this.AutoMapperConfigurations.HouseToHouseDTO(house); if (house == null) { response.Data = null; response.Success = false; response.Message = "House Not Found"; return(response); } else { response.Data = houseDTO; response.Success = true; response.Message = "Data fetched successfully"; return(response); } } catch (Exception) { response.Data = null; response.Success = false; response.Message = "Database Error please try again"; return(response); } }
public ActionResult Edit(HouseEditModel model) { HouseDTO dto = new HouseDTO(); dto.Address = model.address; dto.Area = model.area; dto.AttachmentIds = model.attachmentIds; dto.CheckInDateTime = model.checkInDateTime; //有没有感觉强硬用一些不适合的DTO,有一些没用的属性时候的迷茫? dto.CommunityId = model.CommunityId; dto.DecorateStatusId = model.DecorateStatusId; dto.Description = model.description; dto.Direction = model.direction; dto.FloorIndex = model.floorIndex; dto.Id = model.Id; dto.LookableDateTime = model.lookableDateTime; dto.MonthRent = model.monthRent; dto.OwnerName = model.ownerName; dto.OwnerPhoneNum = model.ownerPhoneNum; dto.RoomTypeId = model.RoomTypeId; dto.StatusId = model.StatusId; dto.TotalFloorCount = model.totalFloor; dto.TypeId = model.TypeId; houseService.Update(dto); CreateStaticPage(model.Id);//编辑房源的时候重新生成静态页面 return(Json(new AjaxResult { Status = "ok" })); }
public ActionResult Add(HouseAddNewModel houseAdd) { HouseDTO house = new HouseDTO(); house.Address = houseAdd.Address; house.Area = houseAdd.Area; house.MonthRent = houseAdd.MonthRent; house.CheckInDateTime = houseAdd.CheckInDateTime; house.CommunityId = houseAdd.CommunityId; house.DecorateStatusId = houseAdd.DecorateStatusId; house.Description = houseAdd.Description; house.Direction = houseAdd.Direction; house.FloorIndex = houseAdd.FloorIndex; house.LookableDateTime = houseAdd.LookableDateTime; house.OwnerName = houseAdd.OwnerName; house.OwnerPhoneNum = houseAdd.OwnerPhoneNum; house.RegionId = houseAdd.RegionId; house.RoomTypeId = houseAdd.RoomTypeId; house.StatusId = houseAdd.StatusId; house.TotalFloatCount = houseAdd.TotalFloatCount; house.TypeId = houseAdd.TypeId; long houseId = HouseService.AddNewHouse(house); CreateStaticPage(houseId); return(Json(new AjaxResult { Status = "ok" })); }
public HouseDTO DeleteHouse(HouseDTO u) { var house = db.Houses.Find(u.CensusHouseNumber); house = db.Houses.Remove(house); db.SaveChanges(); return(HouseMapper.EntitytoDTOHouse(house)); }
public HouseDTO AddUpdateHouse(HouseDTO u) { var newHouse = HouseMapper.DTOtoEntityHouse(u); db.Houses.AddOrUpdate(newHouse); db.SaveChanges(); return(HouseMapper.EntitytoDTOHouse(newHouse)); }
public int PostHouse(HouseDTO house) { House newHouse = mapper.Map <House>(house); db.Houses.Add(newHouse); db.SaveChanges(); return(newHouse.id); }
private bool CheckEmptyData(HouseDTO houseDTO) { if (string.IsNullOrWhiteSpace(houseDTO.BuildingNumber) || string.IsNullOrWhiteSpace(houseDTO.City) || string.IsNullOrWhiteSpace(houseDTO.HeadName) || string.IsNullOrWhiteSpace(houseDTO.State) || string.IsNullOrWhiteSpace(houseDTO.StreetName)) { return(true); } return(false); }
/// <summary> /// Saves a new house or updates an already existing house. /// </summary> /// <param name="house">House to be saved or updated.</param> /// <param name="houseId">HouseId of the house creating or updating</param> /// <returns>houseId</returns> public long SaveHouse(HouseDTO houseDTO, string userId) { long houseId = 0; if (houseDTO.HouseId == 0) { var house = new House() { Number = houseDTO.Number, Amount = houseDTO.Amount, EstateId = houseDTO.EstateId, CreatedOn = DateTime.Now, Timestamp = DateTime.Now, CreatedBy = userId, Deleted = false, }; var houseExists = this.houseExistsInGivenEstate(houseDTO.EstateId, houseDTO.Number); if (!houseExists) { this.UnitOfWork.Get<House>().AddNew(house); this.UnitOfWork.SaveChanges(); houseId = house.HouseId; return houseId; } else { return houseId; } } else { var result = this.UnitOfWork.Get<House>().AsQueryable() .FirstOrDefault(e => e.HouseId == houseDTO.HouseId); if (result != null) { result.Number = houseDTO.Number; result.UpdatedBy = userId; result.Amount = houseDTO.Amount; result.EstateId = houseDTO.EstateId; result.Timestamp = DateTime.Now; result.Deleted = houseDTO.Deleted; result.DeletedBy = houseDTO.DeletedBy; result.DeletedOn = houseDTO.DeletedOn; this.UnitOfWork.Get<House>().Update(result); this.UnitOfWork.SaveChanges(); } return houseDTO.HouseId; } return houseId; }
public HouseDTO Create(HouseDTO houseDTO) { if (CheckValidityOfData(houseDTO)) { House house = houseRepository.Create(mapper.HouseDTOToHouseMapper(houseDTO)); return((house != null) ? mapper.HouseToHouseDTOMapper(house) : null); } return(null); }
public HouseModel(HouseDTO house) { ID = house.ID; Name = house.Name; NumberOfUnits = house.NumberOfUnits; foreach (CharacterDTO ch in house.Housers) { Housers.Add(new CharacterModel(ch)); } }
// POST api/<controller> public int Post([FromBody] HouseDTO house) { if (ModelState.IsValid) { return(serviceCall.ServicePostHouse(house)); } else { return(0); } }
public long AddNewHouse(HouseDTO houseDto) { HouseEntity houseEntity = ToEntity(houseDto); using (ZSZDbContext ctx = new ZSZDbContext()) { ctx.Houses.Add(houseEntity); ctx.SaveChanges(); return(houseEntity.Id); } }
/// <summary> /// Create a new house entry /// </summary> /// <param name="houseToCreate">Object of the house entity to be created</param> /// <returns>boolean</returns> public bool CreateHouseListing(HouseDTO houseToCreate) { try { db.Houses.Add(mapper.Map <HouseEntity>(houseToCreate)); db.SaveChanges(); return(true); } catch (Exception ex) { throw new DALException("Unable to Create House Listing" + ex.Message); } }
bool CheckValidityOfData(HouseDTO houseDTO) { if (string.IsNullOrWhiteSpace(houseDTO.ApartmentNumber) || string.IsNullOrWhiteSpace(houseDTO.HeadName) || string.IsNullOrWhiteSpace((houseDTO.NumberOfRooms).ToString()) || string.IsNullOrWhiteSpace(houseDTO.State) || string.IsNullOrWhiteSpace(houseDTO.StreetName) || string.IsNullOrWhiteSpace(houseDTO.OwnershipStatus.ToString())) { return(false); } else { return(true); } }
// PUT: api/Houses/{id} public IHttpActionResult Put(int id, [FromBody] HouseDTO value) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } ThronesTournamentManager m = new ThronesTournamentManager(); m.UpdateHouse(value.Transform()); return(Ok()); }
// POST: api/Houses public IHttpActionResult Post([FromBody] HouseDTO value) { if (!ModelState.IsValid) { return(BadRequest("Invalid data")); } ThronesTournamentManager m = new ThronesTournamentManager(); m.AddHouse(value.Transform()); return(Ok()); }
public IHttpActionResult GetHouseById(int id) { HouseDTO house = GameManager.Instance.GetHouseById(id); if (house.Id == -1) { return(NotFound()); } else { return(Ok(house)); } }
public IActionResult SearchPollingStationsHouse(HouseDTO house) { var pollingStations = _context.PollingStation.Where(ps => ps.HouseId == house.IdHouse); if (pollingStations.Any()) { List <PollingStationDTO> pollingStationsDTO = pollingStations.Select(p => new PollingStationDTO { IdPollingStation = p.IdPollingStation, Name = p.Name }).ToList(); return(Ok(pollingStationsDTO)); } return(NoContent()); }
public static DataSet House_InsUpd(HouseDTO _House) { DataSet ds = new DataSet(); try { ds = clsDatabaseExecute.ExecuteDatasetSP("House_InsUpd", _House.ID, _House.RoomNumber, _House.FeeMonth, _House.IDHouseholder, _House.IDEmployee, _House.IDHouseType, _House.IDLocation); } catch (Exception ex) { clsMessages.ShowErrorException(ex); } return(ds); }
/// <summary> /// Create a new house entry /// </summary> /// <param name="houseToCreate">Object of the house entity to be created</param> /// <returns>boolean</returns> public bool CreateHouseListing(HouseDTO houseToCreate) { try { return(houseDAL.CreateHouseListing(houseToCreate)); } catch (DALException dalEx) { System.Console.WriteLine("Unable to find User...!" + dalEx.Message); return(false); } catch (Exception ex) { throw new BusinessException(ex.Message); } }