コード例 #1
0
        public ActionResult Travel(int regionID, int?ticketQuality)
        {
            var entity = SessionHelper.CurrentEntity;

            if (entity.Citizen == null)
            {
                return(RedirectToHomeWithError("You are not a citizen!"));
            }

            if (ticketQuality == null)
            {
                return(RedirectToHomeWithError("You have not chosen a ticket!"));
            }

            var ticket = equipmentRepository
                         .GetEquipmentItem(entity.EquipmentID.Value, (int)ProductTypeEnum.MovingTicket, ticketQuality.Value);

            if (ticket == null)
            {
                return(RedirectBackWithError("You do not have ticket of this quality"));
            }

            var movingTicket = new MovingTicket(ticket);

            var startRegion = regionRepository.GetById(entity.Citizen.RegionID);
            var endRegion   = regionRepository.GetById(regionID);

            if (travelService.CanTravel(entity.Citizen, startRegion, endRegion, movingTicket).IsError)
            {
                return(RedirectBackWithError("You cannot travel here!"));
            }

            travelService.Travel(entity.EntityID, startRegion, endRegion, movingTicket);

            AddInfo(string.Format("You successfuly moved to {0}", endRegion.Name));
            return(RedirectToAction("View", new { CitizenID = entity.EntityID }));
        }