예제 #1
0
        public long AddNew(HouseAddNewDTO house)
        {
            HouseEntity entity = new HouseEntity();

            entity.Address          = house.Address;
            entity.Area             = house.Area;
            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;
            using (MyDbContext dbc = new MyDbContext())
            {
                CommonService <AttachmentEntity> cs = new CommonService <AttachmentEntity>(dbc);
                var ams = cs.GetAll().Where(a => house.AttachmentIds.Contains(a.Id));
                foreach (var am in ams)
                {
                    entity.Attachments.Add(am);
                }
                dbc.Houses.Add(entity);
                dbc.SaveChanges();
                return(entity.Id);
            }
        }
예제 #2
0
        public ActionResult Add(HouseAddNewDTO house)
        {
            long userId = (long)AdminHelper.GetUserId(HttpContext);
            var  user   = AdminUserService.GetById(userId);

            if (user.CityId == null)
            {
                //TODO如果“总部不能***”的操作很多,也可以定义成一个AuthorizeFilter
                //最好用FilterAttribute的方式标注,这样对其他的不涉及这个问题的地方效率高
                //立即实现
                return(View("ERROR", (object)"总部不能进行房源管理"));
            }
            var houseId = HouseService.AddNew(house);

            if (houseId > 0)
            {
                //生成房源查看的html文件
                CreateStaticPages(houseId);
                return(Json(new AjaxResult()
                {
                    Status = "ok"
                }));
            }

            return(Json(new AjaxResult()
            {
                Status = "error", ErrorMsg = "添加失败"
            }));
        }
예제 #3
0
        public long AddNew(HouseAddNewDTO house)
        {
            HouseEntity houseEntity = new HouseEntity();

            houseEntity.Address = house.Address;
            houseEntity.Area    = house.Area;
            using (ZSZDbContext ctx = new ZSZDbContext())
            {
                BaseService <AttachmentEntity> attBS = new BaseService <AttachmentEntity>(ctx);
                var atts = attBS.GetAll().Where(u => house.AttachmentIds.Contains(u.Id));
                foreach (var att in atts)
                {
                    houseEntity.Attachments.Add(att);
                }
                houseEntity.CheckInDateTime  = house.CheckInDateTime;
                houseEntity.CommunityId      = house.CommunityId;
                houseEntity.DecorateStatusId = house.DecorateStatusId;
                houseEntity.Description      = house.Description;
                houseEntity.Direction        = house.Direction;
                houseEntity.FloorIndex       = house.FloorIndex;
                houseEntity.TotalFloorCount  = house.TotalFloorCount;
                //houseEntity.HousePics 新增后再单独添加
                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.TotalFloorCount  = house.TotalFloorCount;
                houseEntity.TypeId           = house.TypeId;
                ctx.Houses.Add(houseEntity);
                ctx.SaveChanges();
                return(houseEntity.Id);
            }
        }
예제 #4
0
        public ActionResult Add(HouseAddModel model)
        {
            long? userId = AdminHelper.GetUserId(HttpContext);
            long? cityId = userService.GetById(userId.Value).CityId;
            if (cityId == null)
            {
                return View("Error", (object)"总部不能进行房源管理");
            }

            HouseAddNewDTO dto = new HouseAddNewDTO();
            dto.Address = model.address;
            dto.Area = model.area;
            dto.AttachmentIds = model.attachmentIds;
            dto.CheckInDateTime = model.checkInDateTime;
            dto.CommunityId = model.CommunityId;
            dto.DecorateStatusId = model.DecorateStatusId;
            dto.Description = model.description;
            dto.Direction = model.direction;
            dto.FloorIndex = model.floorIndex;
            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.AddNew(dto);
            return Json(new AjaxResult { Status="ok"});
        }
예제 #5
0
        public long AddNew(HouseAddNewDTO house)
        {
            using (RhDbContext ctx = new RhDbContext())
            {
                HouseEntity houseEntity = new HouseEntity();
                CommonService <AttachmentEntity> attCs = new CommonService <AttachmentEntity>(ctx);
                //拿到传进来的DTO的attachmentIds为主键的房屋配套设施
                var atts = attCs.GetAll().Where(a => house.AttachmentIds.Contains(a.Id));
                foreach (var att in atts)
                {
                    houseEntity.Attachments.Add(att);
                }

                houseEntity.Address          = house.Address;
                houseEntity.Area             = house.Area;
                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.TotalFloorCount  = house.TotalFloorCount;
                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;
                ctx.Houses.Add(houseEntity);
                ctx.SaveChanges();
                return(houseEntity.Id);
            }
        }
예제 #6
0
        public ActionResult Add(HouseAddPostModel model)
        {
            long adminUserId = (long)Session["LoginUserId"];
            long?cityId      = AdminUserService.GetById(adminUserId).CityId;

            if (cityId == null)
            {
                return(View("Error", (object)"总部人员不能管理房源"));
            }
            var houseDTO = new HouseAddNewDTO();

            houseDTO.Address          = model.HouseAddress;
            houseDTO.AttachmentIds    = model.AttachmentIds;
            houseDTO.CheckInDateTime  = model.CheckInDate;
            houseDTO.CommunityId      = model.CommunityId;
            houseDTO.DecorateStatusId = model.DecorateStatusId;
            houseDTO.Description      = model.Description;
            houseDTO.Direction        = model.Direction;
            houseDTO.FloorIndex       = model.FloorIndex;
            houseDTO.TotalFloorCount  = model.TotalIndex;
            houseDTO.LookableDateTime = model.LookableDatetime;
            houseDTO.MonthRent        = model.MonthRent;
            houseDTO.OwnerName        = model.OwnerName;
            houseDTO.OwnerPhoneNum    = model.OwnerPhoneNum;
            houseDTO.RoomTypeId       = model.RoomTypeId;
            houseDTO.StatusId         = model.StatusId;
            houseDTO.TotalFloorCount  = model.TotalIndex;
            houseDTO.TypeId           = model.TypeId;
            houseDTO.Area             = model.HouseArea;
            HouseService.AddNew(houseDTO);
            return(Json(new AjaxResult()
            {
                Status = "ok"
            }));
        }
예제 #7
0
        public long AddNew(HouseAddNewDTO house)
        {
            HouseEntity entity = new HouseEntity();

            entity.Address = house.Address;
            entity.Area    = house.Area;
            using (WarmHomeContext db = new WarmHomeContext())
            {
                BaseService <AttachmentEntity> service = new BaseService <AttachmentEntity>(db);
                var atts = service.GetAll().Where(e => house.AttachmentIds.Contains(e.Id));
                foreach (var att in atts)
                {
                    entity.Attachments.Add(att);
                }
                entity.CheckInDateTime  = house.CheckInDateTime;
                entity.CommunityId      = house.CommunityId;
                entity.DecorateStatusId = house.DecorateStatusId;
                entity.Description      = house.Description;
                entity.Direction        = house.Direction;
                entity.FloorIndex       = house.FloorIndex;
                //houseEntity.HousePics 新增后再单独添加
                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;
                db.Houses.Add(entity);
                db.SaveChanges();
                return(entity.Id);
            }
        }
예제 #8
0
        public async Task TestIndex()
        {
            HouseAddNewDTO newDto = new HouseAddNewDTO();

            newDto.Address          = "八号楼";
            newDto.Area             = 80; //房屋面积
            newDto.AttachmentIds    = new long[] { 1, 2 };
            newDto.CheckInDateTime  = DateTime.Now;
            newDto.CommunityId      = 2;
            newDto.DecorateStatusId = 8;
            newDto.Description      = "房东好人";
            newDto.Direction        = "朝南";
            newDto.FloorIndex       = 9;
            newDto.LookableDateTime = DateTime.Now;
            newDto.MonthRent        = 4000;
            newDto.OwnerName        = "何老师";
            newDto.RoomTypeId       = 11;
            newDto.OwnerPhoneNum    = "18580922452";
            newDto.StatusId         = 14;
            newDto.TypeId           = 17;
            newDto.TotalFloorCount  = 32;
            long houseId = HouseSvc.AddNew(newDto);

            var  house  = HouseSvc.GetById(houseId);
            bool result = await ESearchHelper.IndexAsync("house", houseId.ToString(), house);

            Assert.IsTrue(result);
        }
예제 #9
0
        public ActionResult AddHouse(HouseAddModel model)
        {
            long?id     = AdminHelper.AdminUserId(HttpContext);
            long?cityId = AdminUserService.GetById(id.Value).CityId;

            if (cityId == null)
            {
                return(View("ERROR", "总部不能进行房源管理"));
            }
            try
            {
                HouseAddNewDTO dto = new HouseAddNewDTO();
                dto.Address          = model.address;
                dto.Area             = model.area;
                dto.AttachmentIds    = model.attachmentIds;
                dto.CheckInDateTime  = model.checkInDateTime;
                dto.CommunityId      = model.CommunityId;
                dto.DecorateStatusId = model.DecorateStatusId;
                dto.Description      = model.description;
                dto.Direction        = model.direction;
                dto.FloorIndex       = model.floorIndex;
                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;

                long houseId = HouseService.AddNew(dto);
                return(Json(new AjaxResult <object>
                {
                    code = 0,
                    msg = "添加成功"
                }));
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("添加房源失败:{0}", ex.Message);
                return(Json(new AjaxResult <string>
                {
                    code = 1,
                    msg = ex.Message
                }));
            }
        }
예제 #10
0
        //加上[ValidateInput(false)]用ueditor无效是因为要在web.config中加上配置<system.web><httpRuntime requestValidationMode = "2.0" /></ system.web >
        //requestValidationMode = "2.0",这个版本的[ValidateInput(false)]才不会校验是否含有html标签
        public ActionResult Add(HouseAddNewDTO model)
        {
            long id = houseService.AddNew(model);

            if (id > 0)
            {
                return(Json(new AjaxResult {
                    Status = "ok"
                }));
            }
            else
            {
                return(Json(new AjaxResult {
                    Status = "error", ErrorMsg = "添加失败"
                }));
            }
        }
예제 #11
0
        public void TestHouseApp1()
        {
            HouseAddNewDTO newDto = new HouseAddNewDTO();

            newDto.Address          = "8号楼";
            newDto.Area             = 80;
            newDto.AttachmentIds    = new long[] { 1, 2 };
            newDto.CheckInDateTime  = DateTime.Now;
            newDto.CommunityId      = 1;
            newDto.DecorateStatusId = 1;
            newDto.Description      = "房东好人";
            newDto.Direction        = "朝南";
            newDto.FloorIndex       = 9;
            newDto.TotalFloorCount  = 16;
            newDto.LookableDateTime = DateTime.Now;
            newDto.MonthRent        = 6200;
            newDto.OwnerName        = "刘老师";
            newDto.OwnerPhoneNum    = "18918918189";
            newDto.RoomTypeId       = 4;
            newDto.StatusId         = 8;
            newDto.TypeId           = 11;

            long houseId = houseSvc.AddNew(newDto);
            var  h       = houseSvc.GetById(houseId);

            Assert.AreEqual(h.Address, newDto.Address);
            CollectionAssert.AreEqual(h.AttachmentIds,
                                      newDto.AttachmentIds);
            Assert.AreEqual(h.CityName, "北京");
            Assert.AreEqual(h.DecorateStatusName, "精装修");

            long pic1 = houseSvc.AddNewHousePic(new HousePicDTO
            {
                HouseId = houseId, ThumbUrl = "suo.jpg", Url = "url.jpg"
            });
            long pic2 = houseSvc.AddNewHousePic(new HousePicDTO
            {
                HouseId = houseId, ThumbUrl = "aa.jpg", Url = "33.jpg"
            });

            CollectionAssert.AreEqual(houseSvc.GetPics(houseId).Select(p => p.Id).ToArray(),
                                      new long[] { pic1, pic2 });
        }
예제 #12
0
        public void HouseTest()
        {
            HouseAddNewDTO newDto = new HouseAddNewDTO();

            newDto.Address          = "八号楼";
            newDto.Area             = 80; //房屋面积
            newDto.AttachmentIds    = new long[] { 1, 2 };
            newDto.CheckInDateTime  = DateTime.Now;
            newDto.CommunityId      = 2;
            newDto.DecorateStatusId = 8;
            newDto.Description      = "房东好人";
            newDto.Direction        = "朝南";
            newDto.FloorIndex       = 9;
            newDto.LookableDateTime = DateTime.Now;
            newDto.MonthRent        = 6000;
            newDto.OwnerName        = "何老师";
            newDto.RoomTypeId       = 11;
            newDto.OwnerPhoneNum    = "18580922452";
            newDto.StatusId         = 14;
            newDto.TypeId           = 17;
            newDto.TotalFloorCount  = 32;
            long houseId = HouseSvc.AddNew(newDto);

            var house = HouseSvc.GetById(houseId);

            Assert.AreEqual(house.Address, newDto.Address);
            CollectionAssert.AreEqual(house.AttachmentIds, newDto.AttachmentIds);
            Assert.AreEqual(house.CityName, "北京");
            Assert.AreEqual(house.DecorateStatusName, "精装修");

            long pic1 = HouseSvc.AddNewHousePic(new HousePicDTO()
            {
                HouseId = houseId, ThumbUrl = "suoUrl1.jpg", Url = "Url1.jpg"
            });
            long pic2 = HouseSvc.AddNewHousePic(new HousePicDTO()
            {
                HouseId = houseId, ThumbUrl = "suoUrl2.jpg", Url = "Url2.jpg"
            });

            CollectionAssert.AreEqual(HouseSvc.GetPics(houseId).Select(p => p.Id).ToArray(), new long[] { pic1, pic2 });
        }
예제 #13
0
        public ActionResult Add(HouseAddModel model)
        {
            long?userId = AdminHelper.GetUserId(HttpContext);       //获得登录用户Id
            long?cityId = userService.GetById(userId.Value).CityId; //得到该用户所在的城市

            if (cityId == null)
            {
                return(View("Error", (object)"总部不能进行房源管理"));
            }
            HouseAddNewDTO dto = new HouseAddNewDTO();

            dto.Address          = model.Address;
            dto.Area             = model.Area;
            dto.AttachmentIds    = model.AttachmentIds;
            dto.CheckInDateTime  = model.CheckInDateTime;
            dto.CommunityId      = model.CommunityId;
            dto.DecorateStatusId = model.DecorateStatusId;
            dto.Description      = model.Description;
            dto.Direction        = model.Direction;
            dto.FloorIndex       = model.FloorIndex;
            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.TotalFloorCount;
            dto.TypeId           = model.TypeId;
            long houseId = houseService.AddNew(dto);

            //根据新增的房源houseId,生成静态页面
            CreateStaticPage(houseId);
            return(Json(new AjaxResult {
                Status = "ok", ErrorMsg = "添加房源失败"
            }));
        }