public void GetReservation_Id_Reservation()
        {
            var service      = new ReservationService(new ReservationRepository());
            var reservation1 = GetReservation();

            Assert.IsTrue(service.Delete(reservation1.Id));
            Assert.IsFalse(service.Delete(reservation1.Id));
        }
Beispiel #2
0
        public void DeleteShouldNotRunWithNullHost()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            ReservationService service = new ReservationService(resRepo, guestRepo, hostRepo);

            Host host = null;

            Reservation toDelete = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                ID        = 1
            };

            Reservation copy = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

            copy.SetTotal();
            copy.ID = 1;

            var result = service.Delete(toDelete);

            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.Messages[0].Contains("Host"));
        }
Beispiel #3
0
        public void DeleteShouldDelete()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            ReservationService service = new ReservationService(resRepo, guestRepo, hostRepo);

            Host host = hostRepo.ReadAll()[0];

            Reservation toDelete = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                ID        = 1
            };

            Reservation copy = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

            copy.SetTotal();
            copy.ID = 1;

            var result = service.Delete(toDelete);

            Assert.IsTrue(result.Success);
            Assert.AreEqual(0, service.ViewByHost(host).Value.Count);
            Assert.AreEqual(copy, result.Value);
        }
        public void Remove_Id_BooleanType()
        {
            var service      = new ReservationService(new ReservationRepository());
            var reservation1 = GetReservation();

            Assert.IsTrue(service.Delete(reservation1.Id));
        }
        public ActionResult <string> Delete(string id)
        {
            if (id == null || string.IsNullOrEmpty(id))
            {
                return(NotFound());
            }

            var reservation = _reservationService.Get(id);

            if (reservation == null)
            {
                return(NotFound());
            }

            var tables = reservation.TableIds.Select(tableId => _tableService.Get(tableId)).ToList();

            if (tables.Count > 0)
            {
                foreach (var table in tables)
                {
                    table.IsAvailable = true;
                    _tableService.Update(table);
                }
            }

            _reservationService.Delete(id);

            return(Ok());
        }
Beispiel #6
0
 public ActionResult Delete(string id)
 {
     if (_service.Delete(id).DeletedCount == 0)
     {
         return(NotFound());
     }
     return(Ok());
 }
Beispiel #7
0
        public void Delete_Id_Deleting()
        {
            var mock = new Mock <IReservationRepository>();

            mock.Setup(repo => repo.Delete(2)).Returns(true);
            var service = new ReservationService(mock.Object);

            Assert.IsTrue(true == service.Delete(2));
        }
        public IActionResult Reserve(ReservationModel model)
        {
            if (model.FormOption == "DELETE" && model.ReservationId != null)
            {
                _reservationService.Delete(model.ReservationId);
                TempData["message"] = new AlertMessage {
                    CssClass = "alert-success", Id = string.Empty, Title = "Reservering verwijderd", Message = "Uw Reservering is succesvol verwijderd!"
                };
                return(Reserve());
            }

            if (!ModelState.IsValid)
            {
                return(Reserve());
            }

            if (model.FormOption == null)
            {
                _reservationService.Create(new Reservation
                {
                    ArriveDate    = model.ArriveDate,
                    DepartureDate = model.DepartureDate,
                    EmailAddress  = model.EmailAddress,
                    PhoneNumber   = model.PhoneNumber,
                    UserId        = User.FindFirstValue(ClaimTypes.UserData)
                });

                TempData["message"] = new AlertMessage {
                    CssClass = "alert-success", Id = string.Empty, Title = "Reservering gemaakt", Message = "Uw Reservering is succesvol aangemaakt!"
                };
            }
            else
            {
                var reservationToUpdate = _reservationService.Get(model.ReservationId);

                // Reservation does not exists return view
                if (reservationToUpdate == null)
                {
                    return(Reserve());
                }

                reservationToUpdate.EmailAddress  = model.EmailAddress;
                reservationToUpdate.PhoneNumber   = model.PhoneNumber;
                reservationToUpdate.ArriveDate    = model.ArriveDate;
                reservationToUpdate.DepartureDate = model.DepartureDate;

                // Update reservation
                _reservationService.Update(reservationToUpdate);

                TempData["message"] = new AlertMessage {
                    CssClass = "alert-success", Id = string.Empty, Title = "Reservering bijgewerkt.", Message = "Uw reservering is succesvol bijgewerkt!"
                };
            }

            return(Reserve());
        }
        public void ReservationDeleteTest()
        {
            var id = 1;

            EFWorkUnitMock.Setup(x => x.Reservations.Delete(id));

            var reservationService = new ReservationService(EFWorkUnitMock.Object);
            reservationService.Delete(id);

            EFWorkUnitMock.Verify(x => x.Reservations.Delete(id));
        }
        private void Cancel()
        {
            ConsoleIO.DisplayLine("*** Cancel Reservation ***");

            //get host list and reservations
            //when getting list to show, query to only show future dates
            Result <List <Reservation> > reservationsResult = GetReservations();

            List <Reservation> orderedReservations = reservationsResult.Value
                                                     .Where(r => r.StartDate > DateTime.Now)
                                                     .ToList();

            ConsoleIO.DisplayStatus(reservationsResult.Success, reservationsResult.Messages);
            if (reservationsResult.Success)
            {
                ConsoleIO.DisplayReservationList(orderedReservations);
            }
            else
            {
                return;
            }

            //get id to delete
            Reservation toDelete = null;

            do
            {
                int idToDelete = ConsoleIO.PromptInt("Enter the ID of the Reservation you want to cancel");
                toDelete = reservationsResult.Value.Find(r => r.ID == idToDelete);
            } while (toDelete == null);

            //confirm deletion
            ConsoleIO.DisplayLine($"\nCancelling reservation {toDelete.ID}");
            if (!ConsoleIO.PromptYesNo())
            {
                ConsoleIO.DisplayLine("Reservation was not deleted");
                return;
            }

            //perform Delete and show result
            var result = reservationService.Delete(toDelete);

            ConsoleIO.DisplayStatus(result.Success, result.Messages);
            if (result.Success)
            {
                ConsoleIO.DisplayLine($"Reservation with ID {result.Value.ID} was deleted");
            }
        }
        public async Task <IActionResult> Delete([FromQuery] int id, [FromQuery] string name)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                await _reservationService.Delete(id, name);
            }
            catch (ArgumentNullException exception)
            {
                return(BadRequest(exception.ParamName));
            }

            return(Ok());
        }
Beispiel #12
0
        public void DeleteShouldNotRunForNotFoundID()
        {
            IReservationRepository resRepo   = new ReservationRepoDouble();
            IHostRepository        hostRepo  = new HostRepoDouble();
            IGuestRepository       guestRepo = new GuestRepoDouble();

            ReservationService service = new ReservationService(resRepo, guestRepo, hostRepo);

            Host host = hostRepo.ReadAll()[0];

            Reservation toDelete = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = host,
                ID        = 2
            };

            Reservation copy = new Reservation
            {
                StartDate = new DateTime(2022, 1, 1),
                EndDate   = new DateTime(2022, 1, 8),
                Host      = hostRepo.ReadAll()[0],
                Guest     = guestRepo.ReadAll()[0]
            };

            copy.SetTotal();
            copy.ID = 1;

            var result = service.Delete(toDelete);

            Assert.IsFalse(result.Success);
            Assert.IsNull(result.Value);
            Assert.IsTrue(result.Messages[0].Contains("ID"));
            Assert.AreEqual(1, service.ViewByHost(host).Value.Count);
            Assert.AreEqual(copy, service.ViewByHost(host).Value[0]);
        }
Beispiel #13
0
        public void Delete_Id_Deleting()
        {
            var service = new ReservationService(new ReservationRepository());

            Assert.AreEqual(true, service.Delete(GetReservation().Id));
        }