public bool BuildHut(int villageId, int amount)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var village = villageRepository.GetById(villageId, s => s.Player);

                if (village == null)
                {
                    throw new NullReferenceException("Building service - BuildHut(...) village cant be null");
                }

                resourceListQuery.Filter = new ResourceFilter {
                    ResourceType = "Wood", VillageId = villageId
                };
                var wood = resourceRepository.GetById(resourceListQuery.Execute().SingleOrDefault().ID, r => r.ResourceType, r => r.Village);

                /*if (wood == null)
                 * {
                 *  throw new NullReferenceException("Building Service - BuildHut(...) wood cant be null");
                 * }*/

                resourceListQuery.Filter = new ResourceFilter {
                    ResourceType = "Stone", VillageId = villageId
                };
                var stone = resourceRepository.GetById(resourceListQuery.Execute().SingleOrDefault().ID, r => r.ResourceType, r => r.Village);

                /*if (stone == null)
                 * {
                 *  throw new NullReferenceException("Building Service - BuildHut(...) stone cant be null");
                 * }*/

                if ((wood.Amount < (village.Huts * 100 + 100) * amount) || (stone.Amount < (village.Huts * 60 + 60) * amount))
                {
                    return(false);
                }

                wood.Amount             -= (village.Huts * 100 + 100) * amount;
                stone.Amount            -= (village.Huts * 60 + 60) * amount;
                village.Huts            += amount;
                village.AvailableWorkers = village.AvailableWorkers += 4 * amount;
                resourceRepository.Update(wood);
                resourceRepository.Update(stone);
                villageRepository.Update(village);
                uow.Commit();
                return(true);
            }
        }
Exemple #2
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();
        }