示例#1
0
        public ActionResult DeleteMultiple(List <int> ids)
        {
            PlantInfoService.DeleteMultiple(ids);
            var jsondata = new { count = ids.Count(), Status.code };

            return(Json(jsondata, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public async Task TestGetPlantInfoAsync()
        {
            var plantInfoService = new PlantInfoService(_mockPlantInfoRepository.Object, _mockPlantLocationRepository.Object, _mockPlantInfoIndex.Object);
            var plantInfo        = await plantInfoService.GetPlantInfoAsync(1, FakeUsers.GetPublic().AsModel());

            plantInfo.Should().NotBeNull("it exists");
        }
示例#3
0
        public ActionResult DeleteSingle(int id)
        {
            bool delflag  = PlantInfoService.DeleteSingle(id);
            var  jsondata = new { delflag, Status.code };

            return(Json(jsondata, JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public async Task TestAddOrUpdatePlantInfoAsync()
        {
            var plantInfoService = new PlantInfoService(_mockPlantInfoRepository.Object, _mockPlantLocationRepository.Object, _mockPlantInfoIndex.Object);
            var plantInfo        = FakePlantInfos.Get().First().AsModel();

            var plantInfoResult = await plantInfoService.AddOrUpdatePlantInfoAsync(plantInfo);

            plantInfoResult.Should().NotBeNull("it exists");
        }
示例#5
0
        public ActionResult Update(PlantInfo PlantInfo)
        {
            //同一个上下文不能缓存两个同一个主键的对象
            PlantInfo oldUser = PlantInfoService.GetEntities(u => u.Id == PlantInfo.Id).FirstOrDefault();
            //查出来一个旧的权限实体,直接在上面修改
            //oldUser.UserName = PlantInfo.UserName;
            //oldUser.UserPwd = PlantInfo.UserPwd;
            //oldUser. = PlantInfo.Remark;
            bool updateflag = PlantInfoService.Update(oldUser);
            var  jsondata   = new { updateflag, Status.code };

            return(Json(jsondata, JsonRequestBehavior.AllowGet));
        }
示例#6
0
        public ActionResult Create(PlantInfo plantInfo)
        {
            plantInfo.SubTime = DateTime.Now;
            plantInfo.DelFlag = 1;
            if (ModelState.IsValid)
            {
                PlantInfoService.Add(plantInfo);
            }
            CacheHelper.CacheHelper.SetCache("Update_Flag", 1);
            var jsondata = new { Status.code };

            return(Json(jsondata, JsonRequestBehavior.AllowGet));
        }
示例#7
0
        public async Task TestITISPlantInfoProcessor()
        {
            var transformer = new ITISPlantInfoTransformer();
            var itisData    = ITISPlantInfoData();
            var plantInfos  = new List <PlantInfo>();

            itisData.ForEach(i => plantInfos.AddRange(transformer.Transform(new List <TaxonomicUnit> {
                i
            })));

            var originRepository        = RepositoryMocks.GetStandardMockOriginRepository(new List <Stores.Origin>());
            var locationRepository      = RepositoryMocks.GetStandardMockLocationRepository(new List <Stores.Location>());
            var lifeformRepository      = RepositoryMocks.GetStandardMockLifeformRepository(new List <Stores.Lifeform>());
            var plantInfoRepository     = RepositoryMocks.GetStandardMockPlantInfoRepository(new List <Stores.PlantInfo>());
            var plantLocationRepository = RepositoryMocks.GetStandardMockPlantLocationRepository(new List <Stores.PlantLocation>());
            var synonymRepository       = RepositoryMocks.GetStandardMockSynonymRepository();
            var taxonRepository         = RepositoryMocks.GetStandardMockTaxonRepository(new List <Stores.Taxon>());
            var plantSynonymRepository  = new Mock <IRepository <Stores.PlantSynonym> >();
            var plantInfoIndex          = SearchMocks.GetStandardMockPlantInfoIndex();
            var lifeformIndex           = SearchMocks.GetStandardMockLifeformIndex();

            var locationService  = new LocationService(locationRepository.Object);
            var originService    = new OriginService(originRepository.Object, locationService);
            var lifeformService  = new LifeformService(lifeformRepository.Object, lifeformIndex.Object);
            var plantInfoService = new PlantInfoService(plantInfoRepository.Object, plantLocationRepository.Object, plantInfoIndex.Object);
            var synonymService   = new SynonymService(synonymRepository.Object);
            var taxonService     = new TaxonService(taxonRepository.Object, synonymService);

            var processor = new PlantInfoProcessor(lifeformService, originService, plantInfoService, taxonService, locationService);

            await processor.InitializeOrigin(transformer.Origin);

            await processor.InitializeLifeforms();

            await processor.InitializeTaxons();

            var result = await processor.Process(plantInfos);

            result.Count(p => p.ScientificName == "Glandularia quadrangulata").Should().Be(1);
            result.Count(p => p.Taxon.Subfamily == null).Should().Be(5);
            result.Count(p => p.Taxon.Species == "cremersii").Should().Be(1);
            result.Count(p => p.Taxon.Form == "viridifolia").Should().Be(1);
            result.Count(p => p.Taxon.Subspecies == "purpurea").Should().Be(1);
            result.Count(p => p.Taxon.Variety == "graminea").Should().Be(1);
            result.Where(p => p.Locations != null).SelectMany(p => p.Locations).Count().Should().Be(3);
            result.Where(p => p.Locations != null).SelectMany(p => p.Locations).Count(l => l.Status == LocationStatus.Native).Should().Be(3);
            result.Select(p => p.Origin).DistinctBy(o => o.OriginId).Count().Should().Be(5);
        }
示例#8
0
        public async Task TestFindPlantInfosAsync()
        {
            var plantInfoService = new PlantInfoService(_mockPlantInfoRepository.Object, _mockPlantLocationRepository.Object, _mockPlantInfoIndex.Object);

            var plantInfoResult = await plantInfoService.FindPlantInfos(new PlantInfoFindParams
            {
                SearchText    = "Liatris spicata",
                Skip          = 0,
                Take          = 10,
                SortBy        = "",
                SortDirection = SortDirection.None
            },
                                                                        FakeUsers.GetPublic().AsModel());

            plantInfoResult.Results.Should().NotBeNull("it exists");
            plantInfoResult.Count.Should().Be(2);
            plantInfoResult.Results.Should().HaveCount(2);
        }
示例#9
0
        public ActionResult AddImage(int pid)
        {
            HttpPostedFileBase file       = Request.Files[0];
            string             imgUrl     = SaveFile(file);
            PlantInfo          plantInfo  = PlantInfoService.GetEntities(p => p.Id == pid).FirstOrDefault();
            PlantImage         plantImage = new PlantImage()
            {
                Url         = imgUrl,
                DelFlag     = 1,
                SubTime     = DateTime.Now,
                PlantInfoId = pid
            };

            PlantImageService.Add(plantImage);
            var jsondata = new { code = 200 };

            return(Json(jsondata, JsonRequestBehavior.AllowGet));
        }
示例#10
0
        public ActionResult GetPlant(int id)
        {
            if (CacheHelper.CacheHelper.GetString("R_" + id) != null)
            {
                int           newhot  = GetPlantHot(id);
                var           data    = CacheHelper.CacheHelper.GetString("R_" + id);
                var           imgdata = PlantImageService.GetEntities(i => i.PlantInfoId == id);
                List <string> imglist = new List <string>();
                foreach (PlantImage item in imgdata)
                {
                    imglist.Add(item.Url);
                }
                var jsondata = new { code = 200, data, newhot, imglist };
                return(Json(jsondata, JsonRequestBehavior.AllowGet));
            }
            else
            {
                int newhot = GetPlantHot(id);
                var data   = PlantInfoService.GetEntities(u => u.Id == id);

                var qdata = data.Select(a => new
                {
                    a.PlantName,
                    a.DelFlag,
                    a.SubTime,
                    a.Id,
                    a.PlantDetail,
                    a.JingDu,
                    a.WeiDu,
                    a.Xiaoqu
                });
                CacheHelper.CacheHelper.SetCache("R_" + id, qdata);
                var           imgdata = PlantImageService.GetEntities(i => i.PlantInfoId == id);
                List <string> imglist = new List <string>();
                foreach (PlantImage item in imgdata)
                {
                    imglist.Add(item.Url);
                }
                var jsondata = new { code = 200, qdata, newhot, imglist };
                return(Json(jsondata, JsonRequestBehavior.AllowGet));
            }
        }
示例#11
0
        public ActionResult GetPlantByPage()
        {
            int pageSize  = int.Parse(Request["limit"] ?? "10");
            int pageIndex = int.Parse(Request["page"] ?? "1");
            //条件
            Expression <Func <PlantInfo, bool> > WhereLambda = u => u.DelFlag == 1;
            //排序条件
            Expression <Func <PlantInfo, DateTime> > OrderbyLambda = u => u.SubTime;
            var olddata = PlantInfoService.GetEntitiesByPage(pageSize, pageIndex, out int count, WhereLambda, OrderbyLambda, false);
            var data    = olddata.Select(a => new
            {
                a.PlantName,
                a.DelFlag,
                a.SubTime,
                a.Id,
                a.PlantDetail,
                a.JingDu,
                a.WeiDu,
                a.Xiaoqu
            });
            var jsondata = new { Status.code, count, data };

            return(Json(jsondata, JsonRequestBehavior.AllowGet));
        }