public void Cannot_Save_Invalid_editSportsHall()
        {
            //Arrange
            Mock <ISportHalRepository> mock = new Mock <ISportHalRepository>();


            AdminController controller = new AdminController(mock.Object);
            SportsHall      sportsHall = new SportsHall
            {
                Length = 100,
                Width  = 50,
                NumberOfDressingSpace = 20,
                NumberOfShowers       = 10,
            };

            controller.ModelState.AddModelError("error", "error");

            //Act
            IActionResult result = controller.EditSportsHall(sportsHall);


            //Assert
            mock.Verify(m => m.SaveSportsHall(It.IsAny <SportsHall>()), Times.Never());
            Assert.IsType <ViewResult>(result);
        }
        public void Can_Save_Edit_SportsHall()
        {
            //Arrange
            Mock <ISportHalRepository> mock = new Mock <ISportHalRepository>();


            AdminController controller = new AdminController(mock.Object);

            SportsHall sportsHall = new SportsHall
            {
                Length = 100,
                Width  = 50,
                NumberOfDressingSpace = 20,
                NumberOfShowers       = 10,
            };

            //Act
            IActionResult result = controller.EditSportsHall(sportsHall);


            //Assert
            mock.Verify(m => m.SaveSportsHall(sportsHall));
            Assert.IsType <RedirectToActionResult>(result);
            Assert.Equal("SportsHall", (result as RedirectToActionResult).ActionName);
        }
Example #3
0
 public void SaveSportsHallAPI(SportsHall SportsHall)
 {
     foreach (SportsHall dbEntry in context.SportsHall)
     {
         if (SportsHall.Length != 0)
         {
             dbEntry.Length = SportsHall.Length;
         }
         if (SportsHall.NumberOfDressingSpace != 0)
         {
             dbEntry.NumberOfDressingSpace = SportsHall.NumberOfDressingSpace;
         }
         if (SportsHall.NumberOfShowers != 0)
         {
             dbEntry.NumberOfShowers = SportsHall.NumberOfShowers;
         }
         if (SportsHall.Width != 0)
         {
             dbEntry.Width = SportsHall.Width;
         }
         if (SportsHall.Price != 0)
         {
             dbEntry.Price = SportsHall.Price;
         }
         if (SportsHall.OpenTime != null)
         {
             dbEntry.OpenTime = SportsHall.OpenTime;
         }
         if (SportsHall.CloseTime != null)
         {
             dbEntry.CloseTime = SportsHall.CloseTime;
         }
     }
     context.SaveChanges();
 }
Example #4
0
        protected override void ExecuteInsertVenueCommand(string[] commandWords)
        {
            IVenue venue;

            switch (commandWords[2])
            {
            case "opera":
                venue = new OperaHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
                this.Venues.Add(venue);
                break;

            case "sports_hall":
                venue = new SportsHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
                this.Venues.Add(venue);
                break;

            case "concert_hall":
                venue = new ConcertHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
                this.Venues.Add(venue);
                break;

            default:
                base.ExecuteInsertVenueCommand(commandWords);
                break;
            }
        }
Example #5
0
        public ViewResult EditSportsHall(EditSportsHallFormViewModel viewModel, int SelectedProprietor)
        {
            SportsHall aHall = sportsHallRepository.Halls.FirstOrDefault(x => x.ID == viewModel.Hall.ID);

            Proprietor aProprietor = proprietorRepository.Proprietors.Where(x => x.ID == SelectedProprietor).FirstOrDefault();

            aHall.Proprietor  = aProprietor;
            aHall.Name        = viewModel.Hall.Name;
            aHall.Description = viewModel.Hall.Description;
            aHall.Phone       = viewModel.Hall.Phone;
            aHall.City        = viewModel.Hall.City;
            aHall.StreetName  = viewModel.Hall.StreetName;
            aHall.HouseNumber = viewModel.Hall.HouseNumber;
            aHall.Zip         = viewModel.Hall.Zip;

            if (ModelState.IsValid)
            {
                sportsHallRepository.EditSportsHall(aHall);
                return(View("SportsHallList", sportsHallRepository.Halls));
            }
            else
            {
                return(View("SportsHallList", sportsHallRepository.Halls));
            }
        }
Example #6
0
 public void UpdateSportsHall(SportsHall sportsHall, UpdateSportsHallCommand command)
 {
     sportsHall.City     = command.City;
     sportsHall.Streat   = command.Streat;
     sportsHall.Number   = command.Number;
     sportsHall.Phone    = command.Phone;
     sportsHall.Email    = command.Email;
     sportsHall.PostCode = command.PostCode;
 }
Example #7
0
 public IActionResult Post([FromBody] SportsHall Hall)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     repository.SaveSportsHall(Hall);
     return(CreatedAtAction(nameof(Get),
                            new { id = Hall.ID }, Hall));
 }
        public IActionResult DeleteSportsHall(int SportsHallID)
        {
            SportsHall deletedSportsHall = repository.DeleteSportsHall(SportsHallID);

            if (deletedSportsHall != null)
            {
                //TempData["message"] = $"{deletedSportsHall.SportsHallID} was deleted";
            }
            return(RedirectToAction("SportsHall"));
        }
Example #9
0
        public ViewResult EditHallRooms(int sportsHallId)
        {
            SportsHall             aHall         = sportsHallRepository.Halls.FirstOrDefault(h => h.ID == sportsHallId);
            EditHallRoomsViewModel roomViewModel = new EditHallRoomsViewModel()
            {
                SportsHallId = sportsHallId,
                Rooms        = aHall.Rooms.ToList()
            };

            return(View("EditHallRooms", roomViewModel));
        }
Example #10
0
        public ViewResult EditHallFacilities(int sportsHallId)
        {
            SportsHall Hall = sportsHallRepository.Halls.FirstOrDefault(h => h.ID == sportsHallId);
            EditHallFacilitiesViewModel viewModel = new EditHallFacilitiesViewModel()
            {
                SportsHallId = sportsHallId,
                Facilities   = Hall.SportsHallFacilities.ToList(),
            };

            return(View("EditHallFacilities", viewModel));
        }
        public SportsHall DeleteHall(int ID)
        {
            SportsHall DbEntry = context.Halls
                                 .FirstOrDefault(h => h.ID == ID);

            if (DbEntry != null)
            {
                context.Halls.Remove(DbEntry);
                context.SaveChanges();
            }
            return(DbEntry);
        }
Example #12
0
        public SportsHall DeleteSportsHall(int SportsHallID)
        {
            SportsHall dbEntry = context.SportsHall.FirstOrDefault(p => p.SportsHallID == SportsHallID);

            if (dbEntry != null)
            {
                context.SportsHall.Remove(dbEntry);
                context.SaveChanges();
            }

            return(dbEntry);
        }
 public IActionResult EditSportsHall(SportsHall sportsHall)
 {
     if (ModelState.IsValid)
     {
         repository.SaveSportsHall(sportsHall);
         return(RedirectToAction("SportsHall"));
     }
     else
     {
         // there is something wrong with the data values
         return(View(sportsHall));
     }
 }
        public IActionResult Put(int id, [FromBody] SportsHall sportsHall)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            sportsHall.SportsHallID = id;

            repository.SaveSportsHall(sportsHall);
            return(CreatedAtAction(nameof(Get),
                                   new { id = sportsHall.SportsHallID }, sportsHall));
        }
        public IEnumerable <SportsHall> GetSportsHallsByFilter(SportsHallType sportsHallType, int minArea, int maxArea, decimal minRate, decimal maxRate)
        {
            var sportsHalls = new List <SportsHall>();

            // Get data from database.
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = CommandType.Text;
                    command.CommandText = _getHallsByFilter;

                    command.Parameters.AddWithValue("@areaMin", minArea);
                    command.Parameters.AddWithValue("@areaMax", maxArea);
                    command.Parameters.AddWithValue("@rateMin", minRate);
                    command.Parameters.AddWithValue("@rateMax", maxRate);

                    if (sportsHallType != null)
                    {
                        command.Parameters.AddWithValue("@hallTypeId", sportsHallType.Id);
                        command.CommandText += "AND c.ClassTypeId = @hallTypeId";
                    }

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var sportsHall = new SportsHall()
                            {
                                Id   = (int)reader["Id"],
                                Type = new SportsHallType()
                                {
                                    Id   = (int)reader["TypeId"],
                                    Name = (string)reader["TypeName"]
                                },
                                Area = (int)reader["Area"],
                                Rate = (decimal)reader["Rate"]
                            };
                            sportsHalls.Add(sportsHall);
                        }
                    }
                }
            }

            return(sportsHalls);
        }
        public void Cannot_edit_Noneexistent_Can_Edit_SportsHall()
        {
            //Arrange
            Mock <ISportHalRepository> mock = new Mock <ISportHalRepository>();

            mock = getMock();

            AdminController controller = new AdminController(mock.Object);

            //Act
            SportsHall result = GetViewModel <SportsHall>(controller.EditSportHallView(10));

            //Assert
            Assert.Null(result);
        }
        public SportsHall DeleteHallActivity(int hallId, int activityId)
        {
            SportsHall parent = context.Halls.Include(p => p.SportsHallActivities)
                                .SingleOrDefault(x => x.ID == hallId);

            foreach (var act in parent.SportsHallActivities.ToList())
            {
                if (act.ActivityID == activityId)
                {
                    context.SportsHallsActivity.Remove(act);
                    context.SaveChanges();
                }
            }
            return(parent);
        }
Example #18
0
        public IActionResult Put(int id, [FromBody] SportsHall Hall)
        {
            if (Hall == null || id != Hall.ID)
            {
                return(BadRequest());
            }
            var hall = repository.Halls.SingleOrDefault(x => x.ID == id);

            if (hall == null)
            {
                return(NotFound());
            }
            repository.EditSportsHall(Hall);
            return(CreatedAtAction(nameof(Get),
                                   new { id = Hall.ID }, Hall));
        }
Example #19
0
        public ViewResult EditHallFacilities(EditHallFacilitiesViewModel viewModel)
        {
            SportsHall aHall = sportsHallRepository.Halls.FirstOrDefault(h => h.ID == viewModel.SportsHallId);

            aHall.SportsHallFacilities = viewModel.Facilities;

            if (ModelState.IsValid)
            {
                sportsHallRepository.EditSportsHall(aHall);
                return(View("SportsHallList", sportsHallRepository.Halls));
            }
            else
            {
                return(View("SportsHallList", sportsHallRepository.Halls));
            }
        }
        public async Task <ViewResult> CreateBooking(int SelectedActivity, int CurrentSportsHall, int SelectedRoom, Booking booking)
        {
            SportsHall Hall = sportshallRepository.Halls.Where(s => s.ID == CurrentSportsHall).FirstOrDefault();

            booking.Hall      = Hall;
            booking.Room      = Hall.Rooms.Where(r => r.ID == SelectedRoom).FirstOrDefault();
            booking.Activity  = activityRepository.Activities.Where(a => a.ID == SelectedActivity).FirstOrDefault();
            booking.StartTime = booking.Date + booking.StartTime.TimeOfDay;
            booking.EndTime   = booking.Date + booking.EndTime.TimeOfDay;
            booking.UserId    = await GetCurrentUserId();

            booking.Approved = 0;

            TimeSpan Time = (booking.EndTime.TimeOfDay - booking.StartTime.TimeOfDay);

            booking.RemainingCapacity = GetRemainingCapacity(booking) - booking.Activity.RequiredCapacity;

            if (ModelState.IsValid && !(Time.TotalMinutes <= 30) && (GetRemainingCapacity(booking) >= booking.Activity.RequiredCapacity))
            {
                bookingRepository.SaveBooking(booking);
                return(View("Index"));
            }
            else
            {
                if (Time.TotalMinutes <= 30)
                {
                    ModelState.AddModelError("Error", "Je moet minimaal 30 minuten reserveren");
                }
                if (GetRemainingCapacity(booking) < booking.Activity.RequiredCapacity)
                {
                    ModelState.AddModelError("Error", "De gekozen zaal is vol op dit tijdstip");
                }
                //Deze check is nu overbodig omdat er ook tijd in capaciteit check zit.
                //if(!CheckTimeSlot(booking))
                //{
                //    ModelState.AddModelError("Error", "Deze tijd is al gereserveerd");
                //}
                return(View(new BookingViewModel
                {
                    Hall = booking.Hall
                }));
            }
        }
        public void EditSportsHall(SportsHall hall)
        {
            SportsHall exists = context.Halls.FirstOrDefault(x => x.ID == hall.ID);

            if (exists != null)
            {
                //context.Entry(exists).CurrentValues.SetValues(hall);

                foreach (var time in exists.Times)
                {
                    var originalTime = context.Times.SingleOrDefault(t => t.ID == time.ID);
                    if (originalTime != null)
                    {
                        originalTime.TimeClose = time.TimeClose;
                        originalTime.TimeOpen  = time.TimeOpen;
                    }
                }
                context.Halls.Update(exists);
            }
            context.SaveChanges();
        }
        public void Can_Edit_SportsHall()
        {
            //Arrange
            Mock <ISportHalRepository> mock = new Mock <ISportHalRepository>();

            mock = getMock();

            AdminController controller = new AdminController(mock.Object);



            //Act

            SportsHall s1 = GetViewModel <SportsHall>(controller.EditSportHallView(1));

            //Assert
            Assert.Equal(100, s1.Length);
            Assert.Equal(50, s1.Width);
            Assert.Equal(10, s1.NumberOfDressingSpace);
            Assert.Equal(5, s1.NumberOfShowers);
        }
        public IEnumerable <SportsHall> GetFreeSportsHalls()
        {
            var halls = new List <SportsHall>();

            // Get data from database.
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                using (SqlCommand command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandType = CommandType.Text;
                    command.CommandText = "SELECT * FROM vFreeSportsHalls";

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var sportsHall = new SportsHall()
                            {
                                Id   = (int)reader["Id"],
                                Type = new SportsHallType()
                                {
                                    Id   = (int)reader["TypeId"],
                                    Name = (string)reader["TypeName"]
                                },
                                Area = (int)reader["Area"],
                                Rate = (decimal)reader["Rate"],
                            };

                            halls.Add(sportsHall);
                        }
                    }
                }
            }

            return(halls);
        }
Example #24
0
 public void SaveSportsHall(SportsHall SportsHall)
 {
     if (SportsHall.SportsHallID == 0)
     {
         context.SportsHall.Add(SportsHall);
     }
     else
     {
         SportsHall dbEntry = context.SportsHall.FirstOrDefault(p => p.SportsHallID == SportsHall.SportsHallID);
         if (dbEntry != null)
         {
             dbEntry.Length = SportsHall.Length;
             dbEntry.NumberOfDressingSpace = SportsHall.NumberOfDressingSpace;
             dbEntry.NumberOfShowers       = SportsHall.NumberOfShowers;
             dbEntry.Width     = SportsHall.Width;
             dbEntry.Price     = SportsHall.Price;
             dbEntry.OpenTime  = SportsHall.OpenTime;
             dbEntry.CloseTime = SportsHall.CloseTime;
         }
     }
     context.SaveChanges();
 }
 protected override void ExecuteInsertVenueCommand(string[] commandWords)
 {
     IVenue venue;
     switch (commandWords[2])
     {
         case "opera":
             venue = new OperaHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
             this.Venues.Add(venue);
             break;
         case "sports_hall":
             venue = new SportsHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
             this.Venues.Add(venue);
             break;
         case "concert_hall":
             venue = new ConcertHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
             this.Venues.Add(venue);
             break;
         default:
             base.ExecuteInsertVenueCommand(commandWords);
             break;
     }
 }
 public IActionResult Put([FromBody] SportsHall sportsHall)
 {
     repository.SaveSportsHallAPI(sportsHall);
     return(Ok(repository.SportsHallOnly));
 }
Example #27
0
        public ViewResult DeleteHallActivity(int hallId, int activityId)
        {
            SportsHall deletedHallActivity = sportsHallRepository.DeleteHallActivity(hallId, activityId);

            return(View("SportsHallList"));
        }
Example #28
0
        public ViewResult DeleteSportsHall(int hallId)
        {
            SportsHall deletedHall = sportsHallRepository.DeleteHall(hallId);

            return(View("SportsHallList"));
        }
 public void SaveSportsHall(SportsHall hall)
 {
     context.Add(hall);
     context.SaveChanges();
 }
 public SportsHall IsRegistered(SportsHall hall)
 {
     return(context.Halls.Find(hall.ID));
 }
        public ViewResult Hall(int ID)
        {
            SportsHall Hall = repository.Halls.Where(x => x.ID == ID).FirstOrDefault();

            return(View("Hall", Hall));
        }
        protected override void ExecuteInsertVenueCommand(string[] commandWords)
        {
            string name = commandWords[3];
            string location = commandWords[4];
            int numberOfSeats = int.Parse(commandWords[5]);

            switch (commandWords[2])
            {
                case "opera":
                    var opera = new Opera(name, location, numberOfSeats);
                    this.Venues.Add(opera);
                    break;
                case "sports_hall":
                    var sportsHall = new SportsHall(name, location, numberOfSeats);
                    this.Venues.Add(sportsHall);
                    break;
                case "concert_hall":
                    var concertHall = new ConcertHall(name, location, numberOfSeats);
                    this.Venues.Add(concertHall);
                    break;
                default:
                    base.ExecuteInsertVenueCommand(commandWords);
                    break;
            }
        }
 protected override void ExecuteInsertVenueCommand(string[] commandWords)
 {
     switch (commandWords[2])
     {
         case "cinema":
             var cinema = new Cinema(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
             this.Venues.Add(cinema);
             break;
         case "opera":
             var opera = new OperaHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
             this.Venues.Add(opera);
             break;
         case "sports_hall":
             var sportsHall = new SportsHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
             this.Venues.Add(sportsHall);
             break;
         case "concert_hall":
             var concertHall = new ConcertHall(commandWords[3], commandWords[4], int.Parse(commandWords[5]));
             this.Venues.Add(concertHall);
             break;
         default:
             break;
     }
 }