Exemple #1
0
        public void TextDapperContext()
        {
            DbEntityMap.InitMapCfgs();
            IDapperContext dapperContext = new DapperContext(new NameValueCollection()
            {
                ["aa.dataSource.AaCenter.connectionString"] = "Data Source =.; Initial Catalog = AaCenter;User ID = sa; Password = lee2018;",
                ["aa.dataSource.AaCenter.provider"]         = "SqlServer"
            });
            IUserInfoRepository _userInforepository = new UserInfoRepository();
            IVillageRepository  villageRepository   = new VillageRepository();

            villageRepository.Insert(new Village {
                Id          = Guid.NewGuid(),
                VillageName = "aa",
                GmtCreate   = DateTime.Now,
                GmtModified = DateTime.Now
            });


            var model = villageRepository.Get(new Guid("6D880321-DB17-4B32-9F0A-CE9F3F25AA01"));

            model.VillageName = "bbb";
            villageRepository.Update(model);

            //var obj = _userInforepository.Insert(new UserInfo()
            //{
            //    RealName = "111",
            //    UserName = "******",
            //    GmtCreate=DateTime.Now,
            //    LastLoginDate=DateTime.Now,
            //    GmtModified=DateTime.Now
            //});
            var users    = _userInforepository.QueryAll();
            var userList = _userInforepository.From(sql =>
                                                    sql.Select()
                                                    .Where(p => p.RealName.Contains("成"))
                                                    .OrderBy(x => x.SysNo)
                                                    .Page(1, 20)
                                                    );

            var count = userList.ToList().Count();

            //动态where
            Expression <Func <UserInfo, bool> > expression = p => p.RealName == "成天";

            var where = DynamicWhereExpression.Init <UserInfo>();

            where = where.And(x => x.RealName == "成天");
            var dynamicUsers = _userInforepository.From(sql =>
                                                        sql.Select()
                                                        .Where(where)
                                                        .OrderBy(x => x.SysNo)
                                                        .Page(1, 20)
                                                        );
            var count2 = dynamicUsers.ToList().Count();
        }
Exemple #2
0
        //vytvori village, resources, buildings, products, units pre village
        //pre kazdy typ budovy budovu, pre kazdy typ res res atd

        public void CreateVillage(int playerID)
        {
            var village = new Village();

            using (var uow = UnitOfWorkProvider.Create())
            {
                var player = playerRepository.GetById(playerID, p => p.Villages, p => p.Account);
                player.NumOfVillages++;

                village.Player           = player;
                village.Huts             = 1;
                village.AvailableWorkers = 4;
                if (player.Villages.Count() == 0)
                {
                    village.Number = 1;
                }
                else
                {
                    village.Number = player.Villages.Last().Number + 1;
                }
                villageRepository.Insert(village);
                playerRepository.Update(player);
                uow.Commit();
            }

            using (var uow = UnitOfWorkProvider.Create())
            {
                var v = villageRepository.GetById(village.ID);

                var        resourceTypesCount = resourceTypeListQuery.GetTotalRowCount();
                Resource[] resources          = new Resource[resourceTypesCount];

                //takto, alebo i = 0  inicializovat, i++ inicializovat a for od 2 //opakovanie kodu, ci efektivita?
                for (int i = 0; i < resourceTypesCount; ++i)
                {
                    resources[i] = new Resource();
                    resources[i].ResourceType = resourceTypeRepository.GetById(i + 1);

                    if (i == 0)
                    {
                        resources[i].Amount = 90;
                    }

                    if (i == 1)
                    {
                        resources[i].Amount = 50;
                    }

                    resources[i].Village = v;
                    resourceRepository.Insert(resources[i]);
                }

                var        buildingTypesCount = buildingTypeListQuery.GetTotalRowCount();
                var        buildingTypes      = buildingTypeRepository.GetByIds(Enumerable.Range(1, buildingTypesCount).ToArray()); // 2. Sposob na priradovanie type
                Building[] buildings          = new Building[buildingTypesCount];

                for (int i = 0; i < buildingTypesCount; ++i)
                {
                    buildings[i] = new Building();
                    buildings[i].BuildingType = buildingTypes[i];   //2. sposob
                    buildings[i].Village      = v;
                    buildingRepository.Insert(buildings[i]);
                }


                var       productTypesCount = productTypeListQuery.GetTotalRowCount();
                Product[] products          = new Product[productTypesCount];

                for (int i = 0; i < productTypesCount; ++i)
                {
                    products[i]             = new Product();
                    products[i].ProductType = productTypeRepository.GetById(i + 1);
                    products[i].Village     = v;
                    productRepository.Insert(products[i]);
                }


                var unitTypesCount = unitTypeListQuery.Execute().Where(u => u.Role.Equals(UnitRole.Friendly)).Count();    //friendly/hostile units

                Unit[] units = new Unit[unitTypesCount];
                for (int i = 0; i < unitTypesCount; ++i)
                {
                    units[i]          = new Unit();
                    units[i].UnitType = unitTypeRepository.GetById(i + 1);
                    units[i].Village  = v;
                    unitRepository.Insert(units[i]);
                }

                var         adventureTypesCount = adventureTypeListQuery.GetTotalRowCount();
                var         adventureTypes      = adventureTypeRepository.GetByIds(Enumerable.Range(1, adventureTypesCount).ToArray()); // 2. Sposob na priradovanie type
                Adventure[] adventures          = new Adventure[adventureTypesCount];

                for (int i = 0; i < adventureTypesCount; ++i)
                {
                    adventures[i] = new Adventure();
                    adventures[i].AdventureType = adventureTypes[i];   //2. sposob
                    adventures[i].Village       = v;
                    adventureRepository.Insert(adventures[i]);
                }

                uow.Commit();
            }
        }