public IEnumerable <BuildingDTO> ListBuildingsByVillage(int villageId)
 {
     using (UnitOfWorkProvider.Create())
     {
         buildingListQuery.Filter = new BuildingFilter {
             VillageId = villageId
         };
         return(buildingListQuery.Execute() ?? new List <BuildingDTO>());          //??
     }
 }
Ejemplo n.º 2
0
        public void AddResources(TimeSpan timeSpan, int villageId)    //budova si pamata resource
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                buildingListQuery.Filter = new BuildingFilter {
                    VillageId = villageId, WorkersAssigned = true
                };
                IEnumerable <BuildingDTO> buildings = buildingListQuery.Execute();

                Resource[] resources = new Resource[buildings.Count()];

                for (int i = 0; i < buildings.Count(); ++i)
                {
                    resourceListQuery.Filter = new ResourceFilter {
                        VillageId = villageId, ResourceType = buildings.ElementAt(i).ResourceType
                    };
                    resources[i] = resourceRepository.GetById(resourceListQuery.Execute().SingleOrDefault().ID, r => r.ResourceType, r => r.Village);
                    if (resources == null)
                    {
                        throw new NullReferenceException("Resource Service - AddResources(...) resource cant be null");
                    }
                    resources[i].Amount += buildings.ElementAt(i).WorkersAssigned *buildings.ElementAt(i).ProductionPerWorker *timeSpan.Seconds;
                    resourceRepository.Update(resources[i]);
                    uow.Commit();
                }
            }
        }
Ejemplo n.º 3
0
 public IEnumerable <ProductDTO> ListProductsByVillage(int villageId)
 {
     using (UnitOfWorkProvider.Create())
     {
         productListQuery.Filter = new ProductFilter {
             VillageId = villageId
         };
         var products = productListQuery.Execute() ?? new List <ProductDTO>();
         for (int i = 0; i < products.Count; ++i)
         {
             buildingListQuery.Filter = new BuildingFilter {
                 VillageId = villageId, BuildingType = products[i].BuildingType
             };
             if (!buildingListQuery.Execute().SingleOrDefault().Built)//odstrani tie, ktorych vyrobna budova este neexistuje
             {
                 products.Remove(products[i]);
                 --i;
             }
         }
         return(products);
     }
 }