private void AddGuest(object sender, RoutedEventArgs e)
        {
            try
            {
                var townName = this.Town.Text.ToString();
                var student  = RoomService.GetStudentByRoomAndName(
                    Rooms.SelectedItem.ToString(), Student.SelectedItem.ToString());

                Guest guest = new Guest
                {
                    FirstName      = this.FirstName.Text ?? "",
                    MiddleName     = this.MiddleName.Text ?? "",
                    LastName       = this.LastName.Text ?? "",
                    StudentVisited = student,
                    Town           = TownService.GetTownByName(townName)
                };
                GuestService.AddGuest(guest);
                MessageBox.Show($"Added guest {this.FirstName.Text} {this.LastName.Text} to {student.FullName}", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                this.Content = new AddGuestUserControl();
            }
            catch (Exception)
            {
                MessageBox.Show($"You need to fill all fields", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void GetTownByNameShouldThrowExceptionWithInvalidTown()
        {
            Mock <DbSet <Town> >    mockSet;
            Mock <DbSet <Country> > mockSetCountries;

            SeedDataBase(out mockSet, out mockSetCountries);

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Towns).Returns(mockSet.Object);
            mockContext.Setup(x => x.Countries).Returns(mockSetCountries.Object);

            var service = new TownService(mockContext.Object);

            Assert.Throws <ArgumentException>(() => service.GetTownByName("Bulgaria", "Vidin"));
        }
        public void GetTownByNameShouldReturnTown()
        {
            Mock <DbSet <Town> >    mockSet;
            Mock <DbSet <Country> > mockSetCountries;

            SeedDataBase(out mockSet, out mockSetCountries);

            var mockContext = new Mock <TravelSimulatorContext>();

            mockContext.Setup(c => c.Towns).Returns(mockSet.Object);
            mockContext.Setup(x => x.Countries).Returns(mockSetCountries.Object);

            var service = new TownService(mockContext.Object);
            var town    = service.GetTownByName("Bulgaria", "Sofia");

            Assert.AreEqual("Sofia", town.TownName);
        }
Esempio n. 4
0
        private void AddStudent(object sender, RoutedEventArgs e)
        {
            if (this.FirstName.Text.Length < 3 || this.MiddleName.Text.Length < 3 ||
                this.LastName.Text.Length < 3 || decimal.Parse(this.Obligations.Text) < 0)
            {
                MessageBox.Show($"No empty fields allowed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                try
                {
                    Room       room       = RoomService.getRoomInCampusByNumber(this.Rooms.SelectedItem.ToString(), campus.Id);
                    University university = GeneralService.GetUniversityByName(University.SelectedItem.ToString());
                    Town       town       = TownService.GetTownByName(this.Town.SelectedItem.ToString());
                    Student    student    = new Student
                    {
                        FirstName    = this.FirstName.Text,
                        MiddleName   = this.MiddleName.Text,
                        LastName     = this.LastName.Text,
                        CampusId     = campus.Id,
                        IsActive     = true,
                        Obligations  = decimal.Parse(Obligations.Text),
                        UniversityId = university.Id,
                        RoomId       = room.Id,
                        TownId       = town.Id
                    };
                    StudentService.AddStudent(student);
                    MessageBox.Show("Added student successfully", "Information", MessageBoxButton.OK, MessageBoxImage.Information);

                    this.Content = new AddStudentUserControl();
                }
                catch (Exception)
                {
                    MessageBox.Show($"Invalid data", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        public void SeedTableVouchers()
        {
            Town     town      = townService.GetTownByName("Bulgaria", "Sunny Beach");
            Hotel    hotel     = hotelService.FindHotelByName("Jasmine", town);
            Tourist  tourist   = touristService.GetTouristById(1);
            DateTime startDate = new DateTime(2019, 07, 10);
            DateTime endDate   = new DateTime(2019, 07, 17);

            voucherService.CreateVoucher(tourist, hotel, 7, 0, 10, startDate, endDate);
            //voucherService.DeleteVoucher(tourist, hotel);

            Tourist  tourist2   = touristService.GetTouristById(2);
            DateTime startDate2 = new DateTime(2019, 08, 01);
            DateTime endDate2   = new DateTime(2019, 08, 15);

            voucherService.CreateVoucher(tourist2, hotel, 15, 0, 20, startDate2, endDate2);
            //voucherService.DeleteVoucher(tourist2, hotel);

            Tourist  tourist3   = touristService.GetTouristById(3);
            DateTime startDate3 = new DateTime(2019, 06, 21);
            DateTime endDate3   = new DateTime(2019, 06, 26);

            voucherService.CreateVoucher(tourist3, hotel, 5, 0, 7, startDate3, endDate3);
            //voucherService.DeleteVoucher(tourist3, hotel);

            Town     town2      = townService.GetTownByName("Bulgaria", "Bansko");
            Hotel    hotel2     = hotelService.FindHotelByName("Campanella", town2);
            Tourist  tourist4   = touristService.GetTouristById(4);
            DateTime startDate4 = new DateTime(2019, 10, 17);
            DateTime endDate4   = new DateTime(2019, 10, 29);

            voucherService.CreateVoucher(tourist4, hotel2, 12, 0, 15, startDate4, endDate4);
            //voucherService.DeleteVoucher(tourist4, hotel2);

            Tourist  tourist5   = touristService.GetTouristById(5);
            DateTime startDate5 = new DateTime(2019, 12, 01);
            DateTime endDate5   = new DateTime(2019, 12, 10);

            voucherService.CreateVoucher(tourist5, hotel2, 10, 0, 10, startDate5, endDate5);
            //voucherService.DeleteVoucher(tourist5, hotel2);

            Hotel    hotel3     = hotelService.FindHotelByName("Majestic", town);
            Tourist  tourist6   = touristService.GetTouristById(6);
            DateTime startDate6 = new DateTime(2019, 06, 19);
            DateTime endDate6   = new DateTime(2019, 06, 29);

            voucherService.CreateVoucher(tourist6, hotel3, 10, 0, 15, startDate6, endDate6);
            //voucherService.DeleteVoucher(tourist6, hotel3);

            Tourist  tourist7   = touristService.GetTouristById(7);
            DateTime startDate7 = new DateTime(2019, 08, 03);
            DateTime endDate7   = new DateTime(2019, 08, 13);

            voucherService.CreateVoucher(tourist7, hotel3, 10, 0, 10, startDate7, endDate7);
            //voucherService.DeleteVoucher(tourist7, hotel3);

            Town     town3      = townService.GetTownByName("Bulgaria", "Borovets");
            Hotel    hotel4     = hotelService.FindHotelByName("Samokov", town3);
            Tourist  tourist9   = touristService.GetTouristById(9);
            DateTime startDate9 = new DateTime(2019, 10, 17);
            DateTime endDate9   = new DateTime(2019, 10, 29);

            voucherService.CreateVoucher(tourist9, hotel4, 12, 0, 15, startDate9, endDate9);
            //voucherService.DeleteVoucher(tourist9, hotel4);

            Tourist tourist8 = touristService.GetTouristById(8);

            voucherService.CreateVoucher(tourist8, hotel, 10, 0, 15, startDate6, endDate6);
            //voucherService.DeleteVoucher(tourist8, hotel);

            Tourist  tourist10   = touristService.GetTouristById(10);
            DateTime startDate10 = new DateTime(2019, 11, 17);
            DateTime endDate10   = new DateTime(2019, 11, 29);

            voucherService.CreateVoucher(tourist10, hotel4, 12, 0, 15, startDate10, endDate10);
            //voucherService.DeleteVoucher(tourist10, hotel4);

            Tourist tourist11 = touristService.GetTouristById(11);

            voucherService.CreateVoucher(tourist11, hotel, 7, 0, 10, startDate, endDate);
            //voucherService.DeleteVoucher(tourist11, hotel);

            Tourist tourist12 = touristService.GetTouristById(12);

            voucherService.CreateVoucher(tourist12, hotel3, 7, 0, 10, startDate, endDate);
            //voucherService.DeleteVoucher(tourist12, hotel3);

            Tourist tourist13 = touristService.GetTouristById(13);

            voucherService.CreateVoucher(tourist13, hotel3, 7, 0, 10, startDate, endDate);
            //voucherService.DeleteVoucher(tourist13, hotel3);

            Tourist tourist14 = touristService.GetTouristById(14);

            voucherService.CreateVoucher(tourist14, hotel, 10, 0, 15, startDate6, endDate6);
            //voucherService.DeleteVoucher(tourist14, hotel);

            Tourist tourist15 = touristService.GetTouristById(15);

            voucherService.CreateVoucher(tourist15, hotel, 10, 0, 15, startDate6, endDate6);
            //voucherService.DeleteVoucher(tourist15, hotel);
        }
Esempio n. 6
0
        /// <inheritdoc />
        /// <summary>
        ///     Executes the command.
        /// </summary>
        /// <param name="caster">The caster.</param>
        /// <param name="args">The arguments.</param>
        protected override void ExecuteCommand(ICharacterSpawn caster, string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            string target = args.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(target))
            {
                return;
            }

            target = target.Trim().ToLower();
            IVector3 targetPosition;

            switch (target)
            {
            case "xyz":
            {
                string position = args.Skip(1).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(position))
                {
                    return;
                }

                string[] xyz = position.Split(',');
                targetPosition = new Vector3(int.Parse(xyz[0].Trim()), int.Parse(xyz[1].Trim()), int.Parse(xyz[2].Trim()));
                break;
            }

            case "temple":
            {
                targetPosition = caster.Town.TemplePosition;
                break;
            }

            case "town":
            {
                string townName = args.Skip(1).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(townName))
                {
                    return;
                }

                ITown town = _townService.GetTownByName(townName.Trim().ToLower());
                targetPosition = town.TemplePosition;
                break;
            }

            case "creature":
            {
                string creatureName = args.Skip(1).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(creatureName))
                {
                    return;
                }

                IEnumerable <ICreatureSpawn> creatureSpawns = _creatureSpawnService.GetCreatureSpawnsByName(creatureName.Trim().ToLower());
                ICreatureSpawn firstMatch = creatureSpawns.FirstOrDefault();
                if (firstMatch == null)
                {
                    caster.Connection.SendTextMessage(TextMessageType.StatusSmall, "A creature with this name does not exist.");
                    return;
                }

                targetPosition = firstMatch.Tile.Position;
                break;
            }

            case "up":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y, currentPosition.Z - 1);
                break;
            }

            case "down":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y, currentPosition.Z + 1);
                break;
            }

            case "north":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y - 1, currentPosition.Z);
                break;
            }

            case "south":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X, currentPosition.Y + 1, currentPosition.Z);
                break;
            }

            case "east":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X + 1, currentPosition.Y, currentPosition.Z);
                break;
            }

            case "west":
            {
                IVector3 currentPosition = caster.Tile.Position;
                targetPosition = new Vector3(currentPosition.X - 1, currentPosition.Y, currentPosition.Z);
                break;
            }

            default: { throw new ArgumentOutOfRangeException(nameof(target), target, null); }
            }

            caster.Connection.MoveCreature(caster, targetPosition);
            caster.Connection.SendEffect(targetPosition, Effect.Teleport);
        }