public bool Build(int buildingId)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                var building = buildingRepository.GetById(buildingId, b => b.Village, b => b.BuildingType);
                if (building == null)
                {
                    throw new NullReferenceException("Building Service - Build(...) building cant be null");
                }

                string[] splitted = building.BuildingType.Cost.Split(null);

                //zisti ci je dost sur
                Resource[] resources = new Resource[splitted.Count() / 2];

                for (int i = 0; i < splitted.Count() / 2; ++i)
                {
                    resourceListQuery.Filter = new ResourceFilter {
                        VillageId = building.Village.ID, ResourceType = splitted[2 * i]
                    };
                    resources[i] = resourceRepository.GetById(resourceListQuery.Execute().SingleOrDefault().ID, r => r.ResourceType, r => r.Village);

                    if (resources[i] == null)
                    {
                        throw new NullReferenceException("Building Service - Build(...) resource cant be null"); //zle costs v building
                    }

                    if (resources[i].Amount < Int32.Parse(splitted[2 * i + 1]))
                    {
                        return(false); //skonci fciu ak neni dost niektorej sur
                    }
                }

                building.Built = true;

                for (int i = 0; i < splitted.Count() / 2; ++i)
                {
                    resources[i].Amount -= Int32.Parse(splitted[2 * i + 1]);
                    resourceRepository.Update(resources[i]);
                }

                buildingRepository.Update(building);
                uow.Commit();
                return(true);
            }
        }
Beispiel #2
0
 public IActionResult UpdateBuilding([FromBody] Building Building)
 {
     if (Building == null)
     {
         return(BadRequest());
     }
     BuildingDB.Update(Building);
     return(Ok(Building));
 }
Beispiel #3
0
        public IActionResult Edit(Building building)
        {
            if (!ModelState.IsValid)
            {
                return(View(building));
            }

            _buildingRespository.Update(building);
            return(RedirectToAction(nameof(Index)));
        }
 public async Task <Building> Update(Building entity)
 {
     return(await _buildingRepository.Update(entity));
 }
Beispiel #5
0
 public void UpdateBuilding(Condtion condt)
 {
     buildingRepository.Update(condt);
 }