Beispiel #1
0
 public bool Update(Town entity)
 {
     if (entity != null)
     {
         _townRepository.Update(entity);
         return(true);
     }
     return(false);
 }
        public void Handle(PlayerCreatedEvent domainEvent)
        {
            var town = _townRepository.GetSmallestTown();

            town.AddCitizen();
            _townRepository.Update(town);

            domainEvent.Player.SetTown(town.Id);
            _playerRepository.Add(domainEvent.Player);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Town town)
        {
            if (id != town.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                await _townRepository.Update(town);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(town));
        }
Beispiel #4
0
 public ActionResult Edit(TownDTO entity)
 {
     try
     {
         Town c = townRepository.GetById(entity.TownID);
         c.Name   = entity.Name;
         c.CityID = entity.CityID;
         townRepository.Update(c);
         townRepository.Save();
         return(Json(entity, JsonRequestBehavior.DenyGet));
     }
     catch (Exception e)
     {
         return(Json(false, JsonRequestBehavior.DenyGet));
     }
 }
        public void Handle(BuildingPurchasedEvent domainEvent)
        {
            // The building has now owner, so it is being sold by the town
            if (String.IsNullOrEmpty(domainEvent.Building.OwnerId))
            {
                var town = _townRepository.Get(domainEvent.Building.TownId);
                town.IncreaseAccountBalance((int)domainEvent.Building.Price);
                _townRepository.Update(town);
            }
            // The building has an owner who should be paid for the sale
            else
            {
                var previousOwner = _playerRepository.Get(domainEvent.Building.OwnerId);
                previousOwner.EarnMoney((int)domainEvent.Building.Price);
                _playerRepository.UpdateStats(previousOwner);
            }

            domainEvent.PurchasingPlayer.SpendMoney((int)domainEvent.Building.Price);
            domainEvent.Building.ChangeOwnership(domainEvent.PurchasingPlayer.Id);

            _playerRepository.UpdateStats(domainEvent.PurchasingPlayer);
            _townBuildingRepository.Update(domainEvent.Building);
        }
Beispiel #6
0
 /// <summary>
 /// Method whose purpose is to update an existing
 /// town in the database.
 /// </summary>
 /// <param name="town">
 /// Existing TownModel object.
 /// </param>
 /// <returns>
 /// Returns true if the query is successfully executed
 /// otherwise returns false.
 /// </returns>
 public bool Update(TownModel town)
 {
     return(_townRepository.Update(town) > 0 ? true : false);
 }