示例#1
0
        public async void TestPost()
        {
            using (var client = server.CreateClient().AcceptJson())
            {
                var step        = 1;
                var service     = new RegionService();
                var countBefore = service.GetAll().Count();
                var item        = service.GetAll().FirstOrDefault();
                if (item == null)
                {
                    var newItem = new Region()
                    {
                        Id   = 0,
                        Name = string.Format("Region {0}", countBefore)
                    };

                    service.Add(item);
                    item = service.GetAll().FirstOrDefault();

                    step = 2;
                }

                var response = await client.PostAsJsonAsync("/api/Regions", item);

                var result = await response.Content.ReadAsJsonAsync <Region>();

                var countAfter = service.GetAll().Count();

                Assert.Equal(countBefore, countAfter - step);
                Assert.Equal((int)response.StatusCode, 201);
            }
        }
示例#2
0
        public async void TestPut()
        {
            using (var client = server.CreateClient().AcceptJson())
            {
                var service = new RegionService();
                var item    = service.GetAll().FirstOrDefault();

                if (item == null)
                {
                    this.TestPost();
                    item = service.GetAll().FirstOrDefault();
                }

                var    itemId = item.Id;
                string unique = (Guid.NewGuid()).ToString();

                item.Name = unique;

                var response = await client.PutAsJsonAsync(string.Format("/api/Regions/{0}", itemId), item);

                var result = await response.Content.ReadAsJsonAsync <Region>();

                item = service.GetById(itemId);

                Assert.True(item.Name.Equals(unique, StringComparison.OrdinalIgnoreCase));
                Assert.Equal((int)response.StatusCode, 200);
            }
        }
示例#3
0
        public ActionResult Add()
        {
            long adminUserId = (long)Session["LoginUserId"];
            long?cityId      = AdminUserService.GetById(adminUserId).CityId;

            if (cityId == null)
            {
                return(View("Error", (object)"总部人员不能管理房源"));
            }
            var regions            = RegionService.GetAll(cityId.Value);
            var roomTypes          = IdNameService.GetAll("户型");
            var statuses           = IdNameService.GetAll("房屋状态");
            var decorationStatuses = IdNameService.GetAll("装修状态");
            var types               = IdNameService.GetAll("房屋类别");
            var attachments         = AttachmentService.GetAll();
            HouseAddViewModel model = new HouseAddViewModel()
            {
                Regions         = regions,
                RoomTypes       = roomTypes,
                Statuses        = statuses,
                DecorateStatues = decorationStatuses,
                Types           = types,
                Attachments     = attachments
            };

            return(View(model));
        }
示例#4
0
        public ActionResult Edit(long id)
        {
            long adminUserId = (long)Session["LoginUserId"];
            long?cityId      = AdminUserService.GetById(adminUserId).CityId;

            if (cityId == null)
            {
                return(View("Error", (object)"总部人员不能管理房源"));
            }
            var house              = HouseService.GetById(id);
            var regions            = RegionService.GetAll(cityId.Value);
            var roomTypes          = IdNameService.GetAll("户型");
            var statuses           = IdNameService.GetAll("房屋状态");
            var decorationStatuses = IdNameService.GetAll("装修状态");
            var types              = IdNameService.GetAll("房屋类别");
            var attachments        = AttachmentService.GetAll();
            var model              = new HouseEditViewModel();

            model.Attachments     = attachments;
            model.DecorateStatues = decorationStatuses;
            model.House           = house;
            model.Regions         = regions;
            model.RoomTypes       = roomTypes;
            model.Statuses        = statuses;
            model.Types           = types;
            return(View(model));
        }
示例#5
0
        public ActionResult Index()
        {
            IRegionService svc   = new RegionService();
            var            model = svc.GetAll();

            return(View("~/Views/Master/Region/Index.cshtml", model));
        }
示例#6
0
        public ActionResult Edit(long Id)
        {
            long userId = (long)AdminHelper.GetUserId(HttpContext);
            var  user   = AdminUserService.GetById(userId);

            if (user.CityId == null)
            {
                //TODO如果“总部不能***”的操作很多,也可以定义成一个AuthorizeFilter
                //最好用FilterAttribute的方式标注,这样对其他的不涉及这个问题的地方效率高
                //立即实现
                return(View("ERROR", (object)"总部不能进行房源管理"));
            }
            var regions             = RegionService.GetAll((long)user.CityId);
            var roomTypes           = IdNameService.GetAll("户型");
            var status              = IdNameService.GetAll("房屋状态");
            var decorateStatus      = IdNameService.GetAll("装修状态");
            var types               = IdNameService.GetAll("出租类别");
            var attachments         = AttachmentService.GetAll();
            var house               = HouseService.GetById(Id);
            HouseEditGetModel model = new HouseEditGetModel();

            model.Attachments    = attachments;
            model.DecorateStatus = decorateStatus;
            model.Regions        = regions;
            model.RoomTypes      = roomTypes;
            model.Status         = status;
            model.Types          = types;
            model.House          = house;
            return(View(model));
        }
示例#7
0
        public ActionResult Search(HouseSearchOptionModel houseSearchOption)
        {
            long    cityId = FrontHelper.GetCityId(this.HttpContext);
            CityDTO city   = CityService.GetById(cityId);

            RegionDTO[] regions = RegionService.GetAll(cityId);
            int         monthRentStart, monthRentEnd;

            ParseMonthRent(houseSearchOption.MonthRent, out monthRentStart, out monthRentEnd);
            HouseSearchOptions houseSearchOptions = new HouseSearchOptions
            {
                CityId         = cityId,
                RegionId       = houseSearchOption.RegionId,
                KeyWords       = houseSearchOption.KeyWords,
                TypeId         = houseSearchOption.TypeId,
                MonthRentStart = monthRentStart,
                MonthRentEnd   = monthRentEnd
            };
            var houses = HouseService.Search(houseSearchOptions);

            HouseSearchViewModel houseSearchView = new HouseSearchViewModel
            {
                City    = city,
                Regions = regions,
                Houses  = houses
            };

            return(View(houseSearchView));
        }
示例#8
0
        public ActionResult Edit(long id)
        {
            long?cityId = AdminHelper.GetCityId(this.HttpContext);

            if (cityId == null)
            {
                return(View("~/Views/Shared/Error.cshtml", (object)"总部人员无法管理房源!"));
            }
            var house   = HouseService.GetById(id);
            var regions = RegionService.GetAll(cityId.Value);
            //var communitities = CommunitityService.
            var roomTypes      = IdNameService.GetByTypeName("户型");
            var status         = IdNameService.GetByTypeName("房屋状态");
            var decorateStatus = IdNameService.GetByTypeName("装修状态");
            var types          = IdNameService.GetByTypeName("房屋类别");
            HouseEditViewModel houseEditView = new HouseEditViewModel();

            houseEditView.House          = house;
            houseEditView.Status         = status;
            houseEditView.DecorateStatus = decorateStatus;
            houseEditView.Regions        = regions;
            houseEditView.RoomTypes      = roomTypes;
            houseEditView.Types          = types;
            return(View(houseEditView));
        }
示例#9
0
        public void TestDelete()
        {
            this.TestAdd();

            ConfigurationHelper.Ensure();
            var service = new RegionService();

            var countBefore = service.GetAll().Count();

            var maxId = service.GetAll().Max(i => i.Id);

            service.Delete(maxId);

            var countAfter = service.GetAll().Count();

            Assert.Equal(countBefore, countAfter + 1);
        }
示例#10
0
        public async void TestDelete()
        {
            using (var client = server.CreateClient().AcceptJson())
            {
                var service     = new RegionService();
                var maxId       = service.GetAll().Max(i => i.Id);
                var countBefore = service.GetAll().Count();

                var response = await client.DeleteAsync(string.Format("/api/Regions/{0}", maxId));

                var result = await response.Content.ReadAsJsonAsync <Region>();

                var countAfter = service.GetAll().Count();

                Assert.Equal(countBefore, countAfter + 1);
                Assert.Equal((int)response.StatusCode, 200);
            }
        }
示例#11
0
        public ActionResult Search2(long typeId, string keyWords, string monthRent, string oderByType, long?regionId)
        {
            //获取当前用户城市ID
            var cityId = FrontHelper.GetCityId(HttpContext);
            //获取城市下所有区域
            var regions = RegionService.GetAll(cityId);

            return(View(regions));
        }
示例#12
0
        protected override async Task OnInitializedAsync()
        {
            Regions = (await RegionService.GetAll()).Select(region => region.Id);
            if (Id != 0)
            {
                CountryModel = await CountryService.Get(Id.ToString());

                RegionId = CountryModel.Region?.Id ?? 0;
            }
        }
示例#13
0
        public void TestAdd()
        {
            ConfigurationHelper.Ensure();

            var service = new RegionService();

            var countBefore = service.GetAll().Count();

            var newItem = new Region()
            {
                Id   = 0,
                Name = string.Format("Region {0}", countBefore)
            };

            service.Add(newItem);

            var countAfter = service.GetAll().Count();

            Assert.Equal(countBefore, countAfter - 1);
        }
        public ActionResult ListData(int page, int limit)
        {
            var count = RegionService.GetAll();
            var data  = count.Skip((page - 1) * limit).Take(limit);

            return(Json(new AjaxResult <RegionDTO>
            {
                code = 0,
                data = data,
                count = count.Count(),
                msg = "查询成功"
            }));
        }
示例#15
0
        public void Test2()
        {
            RegionService regionSvc = new RegionService();
            var           region    = regionSvc.GetById(1);

            Assert.AreEqual(region.CityName, "北京");
            Assert.AreEqual(region.Name, "海淀区");
            Assert.AreEqual(regionSvc.GetAll(1).Length, 2);

            CommunityService comSvc = new CommunityService();

            Assert.AreEqual(comSvc.GetByRegionId(1).Length, 2);
        }
示例#16
0
        public ActionResult Search(long typeId, string keyWords, string monthRent, string oderByType, long?regionId)
        {
            //获取当前用户城市ID
            var cityId = FrontHelper.GetCityId(HttpContext);
            //获取城市下所有区域
            var regions = RegionService.GetAll(cityId);
            HouseSearchViewModel viewModel = new HouseSearchViewModel();

            viewModel.Regions = regions;
            HouseSearchOptions searchOptions = new HouseSearchOptions();

            searchOptions.TypeId       = typeId;
            searchOptions.Keywords     = keyWords;
            searchOptions.PageSize     = 10;
            searchOptions.RegionId     = regionId;
            searchOptions.CityId       = cityId;
            searchOptions.CurrentIndex = 1;

            switch (oderByType)
            {
            case "MonthRentDesc":
                searchOptions.OrderByType = HouseSearchOrderByType.MonthRentDesc;
                break;

            case "MonthRentAsc":
                searchOptions.OrderByType = HouseSearchOrderByType.MonthRentAsc;
                break;

            case "AreaAsc":
                searchOptions.OrderByType = HouseSearchOrderByType.AreaAsc;
                break;

            case "AreaDesc":
                searchOptions.OrderByType = HouseSearchOrderByType.AreaDesc;
                break;
            }
            //解析月租部分
            int?startMonthRent;
            int?endMonthRent;

            ParseMonthRent(monthRent, out startMonthRent, out endMonthRent);

            searchOptions.StartMonthRent = startMonthRent;
            searchOptions.EndMonthRent   = endMonthRent;

            var houseSearchResult = HouseService.Search(searchOptions);

            viewModel.Houses = houseSearchResult.result;
            return(View(viewModel));
        }
示例#17
0
        public void TestUpdate()
        {
            ConfigurationHelper.Ensure();

            var service = new RegionService();

            var item = service.GetAll().FirstOrDefault();

            if (item == null)
            {
                this.TestAdd();
                item = service.GetAll().FirstOrDefault();
            }

            var    itemId = item.Id;
            string unique = (Guid.NewGuid()).ToString();

            item.Name = unique;
            service.Update(item);

            item = service.GetById(itemId);
            Assert.True(item.Name.Equals(unique, StringComparison.OrdinalIgnoreCase));
        }
示例#18
0
        public async void TestGetAll()
        {
            using (var client = server.CreateClient().AcceptJson())
            {
                var response = await client.GetAsync("/api/Regions");

                var result = await response.Content.ReadAsJsonAsync <List <Region> >();

                var service = new RegionService();
                var count   = service.GetAll().Count();

                Assert.Equal(result.Count, count);
            }
        }
示例#19
0
        public void Test2()
        {
            CityService cityService = new CityService();
            string      cityName    = DateTime.Now.ToFileTimeUtc().ToString();
            long        cityId      = cityService.AddNew(cityName);

            RegionService regionSvc  = new RegionService();
            string        regionName = DateTime.Now.ToFileTimeUtc().ToString();
            long          regionId   = regionSvc.Add(regionName, cityId);
            var           region     = regionSvc.GetById(regionId);

            Assert.AreEqual(region.CityName, cityName);
            Assert.AreEqual(region.Name, regionName);
            Assert.AreEqual(regionSvc.GetAll(cityId).Length, 1);
        }
示例#20
0
        // POST api/regions
        public IHttpActionResult Get()
        {
            var regionService = new RegionService();
            var response      = new ResponseViewModel <IEnumerable <RegionViewModel> >()
            {
                Status = new Status()
                {
                    Type    = "Success",
                    Message = ""
                },
                Data = regionService.GetAll()
            };

            return(Ok(response));
        }
示例#21
0
        public ActionResult Edit(long id)
        {
            var data   = CommunityService.GetById(id);
            var userId = AdminHelper.AdminUserId(HttpContext);
            var cityId = AdminUserService.GetById(userId.Value).CityId;

            if (cityId == null)
            {
                return(View("Error", (object)"总部不能编辑地区"));
            }
            CommunityEditModel model = new CommunityEditModel()
            {
                Community = data,
                Regions   = RegionService.GetAll()
            };

            return(View(model));
        }
示例#22
0
        public ActionResult List(int pageIndex = 1)
        {
            long?cityId = AdminHelper.GetCityId(this.HttpContext);

            if (cityId == null)
            {
                return(View("~/Views/Shared/Error.cshtml", (object)"总部人员无法管理区域"));
            }

            var regions = RegionService.GetAll(cityId.Value);
            RegionListViewModel regionListView = new RegionListViewModel();

            regionListView.Regions    = regions;
            regionListView.CityId     = cityId.Value;
            regionListView.PageIndex  = pageIndex;
            regionListView.PageCount  = 10;
            regionListView.TotalCount = regions.LongCount();
            return(View(regionListView));
        }
示例#23
0
        public ActionResult Download(CUSTOMREGION model)
        {
            try
            {
                XLWorkbook xlWorkBook  = new XLWorkbook();
                var        xlWorkSheet = xlWorkBook.Worksheets.Add("Master Region");// xlWorkSheet;

                xlWorkSheet.Cell(1, 1).Value = "RegionId";
                xlWorkSheet.Cell(1, 2).Value = "RegionName";
                xlWorkSheet.Cell(1, 3).Value = "IsActive";

                IRegionService svc  = new RegionService();
                var            Data = svc.GetAll();
                int            Row  = 2;
                if (Data.Count > 0)
                {
                    for (int i = 0; i < Data.Count; i++)
                    {
                        xlWorkSheet.Cell(Row + i, 1).Value = Data[i].REGIONID;
                        xlWorkSheet.Cell(Row + i, 2).Value = Data[i].REGIONNAME;
                        xlWorkSheet.Cell(Row + i, 3).Value = Data[i].STATUS;
                    }
                    xlWorkSheet.Columns().AdjustToContents();
                    var path = Server.MapPath("..") + "\\Master-Region.xlsx";
                    xlWorkBook.SaveAs(path);
                    xlWorkBook.Dispose();
                    return(File(path, "application/vnd.ms-excel", "Master-Region.xlsx"));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                general.AddLogError("CompanyCode Download", ex.Message, ex.StackTrace);
                return(View("~/Views/Master/CompanyCode/Index.cshtml", model));
            }
        }
示例#24
0
        public List <Region> Get()
        {
            var response = _regionService.GetAll();

            return(response);
        }
示例#25
0
 protected override async Task OnInitializedAsync()
 {
     Regions = await RegionService.GetAll();
 }