Exemple #1
0
 private void SaveData()
 {
     foreach (ReservationDto reservation in Reservationen)
     {
         if (reservation.ReservationNr == default(int))
         {
             Service.InsertReservation(reservation);
         }
         else
         {
             ReservationDto original = reservationenOriginal.Where(ao => ao.ReservationNr == reservation.ReservationNr).FirstOrDefault();
             Service.UpdateReservation(reservation, original);
         }
     }
     Load();
 }
        public void InsertReservationWithInvalidDateRangeTest()
        {
            DateTime von = new DateTime(2018, 1, 20);
            DateTime bis = new DateTime(2018, 1, 19);

            ReservationDto reservation = new ReservationDto
            {
                ReservationsNr = 200,
                Von            = von,
                Bis            = bis,
                Auto           = Target.GetAuto(1),
                Kunde          = Target.GetKunde(1)
            };

            Target.AddReservation(reservation);
        }
        public async Task <IActionResult> Put(int id, [FromBody] ReservationDto reservation)
        {
            if (reservation == null || reservation.ID != id)
            {
                return(BadRequest());
            }

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

            await reservationService.Update(id, reservation);

            return(NoContent());
        }
Exemple #4
0
        public void DeleteReservation(ReservationDto reservation)
        {
            WriteActualMethod();
            var reservationEntity = DtoConverter.ConvertToEntity(reservation);

            try
            {
                reservationManager.Delete(reservationEntity);
            }
            catch (OptimisticConcurrencyException <Reservation> )
            {
                throw new FaultException <DataManipulationFault>(new DataManipulationFault {
                    Message = "Die Reservation wird momentan bearbeitet."
                });
            }
        }
Exemple #5
0
 public ReservationDto UpdateReservation(ReservationDto reservationDto)
 {
     try
     {
         Reservation reservation = reservationDto.ConvertToEntity();
         return(autoReservationBusinessComponent.UpdateReservation(reservation).ConvertToDto());
     } catch (LocalOptimisticConcurrencyException <Reservation> ex)
     {
         OptimisticConcurrencyFaultContract ocfc = new OptimisticConcurrencyFaultContract
         {
             Operation = "UpdateReservation",
             Message   = ex.Message
         };
         throw new FaultException <OptimisticConcurrencyFaultContract>(ocfc);
     }
 }
        public async Task <IActionResult> Post([FromBody] ReservationDto reservation)
        {
            if (reservation == null)
            {
                return(BadRequest());
            }

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

            await reservationService.Insert(reservation);

            return(Ok());
        }
        public async Task UpdateReservationWithAutoNotAvailableTest()
        {
            // arrange
            ReservationRequest existingRequest = new ReservationRequest {
                Id = 1
            };
            ReservationDto existingDto = _target.Get(existingRequest);

            ReservationDto reservationInvalid = new ReservationDto {
                Auto = existingDto.Auto, Kunde = existingDto.Kunde, Von = existingDto.Von, Bis = existingDto.Bis
            };


            // assert
            Assert.Throws <RpcException>(() => _target.Insert(reservationInvalid));
        }
Exemple #8
0
 public void UpdateReservation(ReservationDto original, ReservationDto modified)
 {
     WriteActualMethod();
     try
     {
         _businessComponent.UpdateReservation(original.ConvertToEntity(), modified.ConvertToEntity());
     }
     catch (LocalOptimisticConcurrencyException <Reservation> e)
     {
         var fault = new LocalOptimisticConcurrencyFault()
         {
             Message = e.Message
         };
         throw new FaultException <LocalOptimisticConcurrencyFault>(fault);
     }
 }
Exemple #9
0
        public Property InvalidDate(string date)
        {
            Action prop = () =>
            {
                var dto = new ReservationDto
                {
                    Date = date
                };

                var actual = Validator.Validate(dto);

                Assert.NotEmpty(actual);
            };

            return(prop.When(!DateTime.TryParse(date, out _)));
        }
        public async Task UpdateReservationWithInvalidDateRangeTest()
        {
            // arrange
            ReservationRequest existingRequest = new ReservationRequest {
                Id = 1
            };
            ReservationDto existingDto = _target.Get(existingRequest);
            Timestamp      von         = existingDto.Bis;
            Timestamp      bis         = existingDto.Von;

            existingDto.Von = von;
            existingDto.Bis = bis;

            // assert
            Assert.Throws <RpcException>(() => _target.Update(existingDto));
        }
Exemple #11
0
        public async Task CreateReservation(ReservationDto reservationDto)
        {
            var reservation = new Reservation
            {
                UserId         = reservationDto.UserId,
                AddressId      = reservationDto.AddressId,
                VehicleModelId = reservationDto.VehicleModelId,
                PickUpTime     = reservationDto.PickUpTime,
                DropOffTime    = reservationDto.DropOffTime,
                Price          = reservationDto.Price,
                State          = Reservation.ReservationStates.Undecieded
            };

            _dbContext.Reservations.Add(reservation);
            await _dbContext.SaveChangesAsync();
        }
        public async Task UpdateReservationWithInvalidDateRangeTest()
        {
            // arrange
            ReservationDto reservationUpdate = _target.Get(new ReservationRequest {
                Id = 3
            });

            reservationUpdate.Von = Timestamp.FromDateTime(new DateTime(2020, 10, 04, 12, 00, 00, DateTimeKind.Utc));
            reservationUpdate.Bis = Timestamp.FromDateTime(new DateTime(2020, 10, 05, 11, 59, 59, DateTimeKind.Utc));

            // act - assert
            RpcException exception = Assert.Throws <RpcException>(() => _target.Update(reservationUpdate));

            Assert.Equal(StatusCode.FailedPrecondition, exception.StatusCode);
            Assert.Equal("Status(StatusCode=FailedPrecondition, Detail=\"From-To must be at least 24 hours apart\")", exception.Message);
        }
        public void UpdateReservation(ReservationDto reservation)
        {
            WriteActualMethod();
            IAutoReservationResultCallback cb = _createCallbackChannel();

            try
            {
                cb.SendReservation(reservationManager.Update(reservation.ConvertToEntity()).ConvertToDto());
            }
            catch (Exception ex)
            {
                cb.SendFault(new CommunicationFault {
                    Exception = ex.Message
                });
            }
        }
        public void UpdateReservation(ReservationDto modified, ReservationDto original)
        {
            try
            {
                WriteActualMethod();
                BusinessComponent.UpdateReservation(modified.ConvertToEntity(), original.ConvertToEntity());
            }
            catch (LocalOptimisticConcurrencyException <Reservation> ex)
            {
                var enThrow = new OptimisticConcurrencyException <ReservationDto> {
                    Entity = ex.Entity.ConvertToDto()
                };

                throw new FaultException <OptimisticConcurrencyException <ReservationDto> >(enThrow);
            }
        }
        public async Task UpdateReservationTest()
        {
            // arrange
            ReservationRequest toUpdate = new ReservationRequest {
                Id = 1
            };
            ReservationDto reservation = _target.Get(toUpdate);
            DateTime       bis         = reservation.Bis.ToDateTime();

            // act
            reservation.Bis = bis.AddDays(1).ToTimestamp();
            _target.Update(reservation);

            // assert
            Assert.Equal(bis.AddDays(1).ToTimestamp(), _target.Get(toUpdate).Bis);
        }
Exemple #16
0
 private void ReservationSelectedListBox_OnMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     try
     {
         ReservationDto selectedRes = GetSelectedReservation();
         loadIntoReservationForm(selectedRes);
     }
     catch (FieldAccessException ex)
     {
         MessageBox.Show(ex.Message, "Fehler", MessageBoxButton.OK);
     }
     catch (FaultException <OptimisticConcurrencyFault> ex)
     {
         MessageBox.Show(ex.Detail.Message, "Fehler", MessageBoxButton.OK);
     }
 }
Exemple #17
0
        public void InsertReservationTest()
        {
            var reservation = new ReservationDto
            {
                Bis   = new DateTime(2017, 09, 27),
                Von   = new DateTime(2017, 08, 27),
                Auto  = Target.GetAuto(1),
                Kunde = Target.GetKunde(1)
            };

            Target.AddReservation(reservation);
            var res = Target.GetReservation(4);

            Assert.AreEqual(res.Bis, reservation.Bis);
            Assert.AreEqual(res.Von, reservation.Von);
        }
Exemple #18
0
        public string UpdateReservation(int reservationId, ReservationDto resDto)
        {
            Reservation reservation = _context.Reservations.FirstOrDefault(r => r.ReservationID == reservationId);
            IQueryable <UserReservation> userReservations = _context.UserReservations.Where(r => r.ReservationID == reservationId);

            //Update reservation
            if (reservation == null)
            {
                return("Reservation with Id " + reservationId.ToString() + " not found to update");
            }
            else
            {
                reservation.FloorID = resDto.FloorID;
                reservation.Date    = resDto.Date;

                _context.SaveChanges();

                foreach (int userId in resDto.UserIds)
                {
                    //Check if a new user is added
                    bool ifUserExist = userReservations.Any(item => item.UserID.Equals(userId));
                    if (!ifUserExist)
                    {
                        UserReservation ur = new UserReservation()
                        {
                            ReservationID = reservationId,
                            UserID        = userId,
                            Timestamp     = DateTime.Now
                        };

                        _context.UserReservations.Add(ur);
                        _context.SaveChanges();
                    }
                }
                //check if user needs to be deleted
                List <UserReservation> toBeDeleted = userReservations.Where(userRes => !resDto.UserIds.Any(mancerId => userRes.UserID == mancerId)).ToList();
                foreach (UserReservation userToDelete in toBeDeleted)
                {
                    _context.UserReservations.Remove(userToDelete);
                    _context.SaveChanges();
                }



                return("Reservation with Id " + reservationId.ToString() + " updated");
            }
        }
        // TODO: 1 - Create a channel factory for the Frequent Flyer service

        public string CreateReservation(ReservationDto request)
        {
            // Verify the flight is valid
            if (request.DepartureFlight == null)
            {
                throw new FaultException <ReservationCreationFault>(
                          new ReservationCreationFault
                {
                    Description     = "Reservation must include a departure flight",
                    ReservationDate = request.ReservationDate
                },
                          "Invalid flight info");
            }


            // Create reservation object with trips
            var reservation = new Reservation
            {
                TravelerId      = request.TravelerId,
                ReservationDate = request.ReservationDate,
                DepartureFlight = new Trip
                {
                    Class            = request.DepartureFlight.Class,
                    Status           = request.DepartureFlight.Status,
                    FlightScheduleID = request.DepartureFlight.FlightScheduleID
                }
            };

            if (request.ReturnFlight != null)
            {
                reservation.ReturnFlight = new Trip
                {
                    Class            = request.ReturnFlight.Class,
                    Status           = request.ReturnFlight.Status,
                    FlightScheduleID = request.ReturnFlight.FlightScheduleID
                };
            }

            using (IReservationRepository reservationRepository = new ReservationRepository(ConnectionName))
            {
                reservation.ConfirmationCode = ReservationUtils.GenerateConfirmationCode(reservationRepository);
                reservationRepository.Add(reservation);
                reservationRepository.Save();
                return(reservation.ConfirmationCode);
            }
        }
        private string CreateReservationOnBackendSystem(Reservation reservation)
        {
            IBookingService proxy = factory.CreateChannel();

            try
            {
                (proxy as ICommunicationObject).Open();

                TripDto departureFlight = new TripDto
                {
                    FlightScheduleID = reservation.DepartureFlight.FlightScheduleID,
                    Class            = reservation.DepartureFlight.Class,
                    Status           = reservation.DepartureFlight.Status
                };

                TripDto returnFlight = null;
                if (reservation.ReturnFlight != null)
                {
                    returnFlight = new TripDto
                    {
                        FlightScheduleID = reservation.ReturnFlight.FlightScheduleID,
                        Class            = reservation.ReturnFlight.Class,
                        Status           = reservation.ReturnFlight.Status
                    };
                }

                ReservationDto request = new ReservationDto()
                {
                    DepartureFlight = departureFlight,
                    ReturnFlight    = null,
                    ReservationDate = reservation.ReservationDate,
                    TravelerId      = reservation.TravelerId
                };

                string confirmationCode = proxy.CreateReservation(request);

                (proxy as ICommunicationObject).Close();

                return(confirmationCode);
            }
            catch (Exception)
            {
                (proxy as ICommunicationObject).Abort();
                throw;
            }
        }
        public async Task <ReservationDto> GetReservationAsync(string id)
        {
            var reservation = await _repositoryReservation.GetAll().FirstOrDefaultAsync(r => r.Id == id);

            if (reservation is null)
            {
                throw new KeyNotFoundException(ErrorResource.ReservationNotFound);
            }

            var reservationDto = new ReservationDto
            {
                CheckIn  = reservation.CheckIn,
                CheckOut = reservation.CheckOut
            };

            return(reservationDto);
        }
Exemple #22
0
        public async Task CreateReservation_WhenReservationDtoIsValid_ReturnsReservationDto()
        {
            var            client              = GetHttpClient();
            ReservationDto reservationDto      = null;
            var            reservationToCreate = new Reservation {
                RoomId = 4, StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(3)
            };
            var response = await client.PostAsJsonAsync("api/reservations", Mapper.Map <Reservation, ReservationDto>(reservationToCreate));

            if (response.IsSuccessStatusCode)
            {
                reservationDto = await response.Content.ReadAsAsync <ReservationDto>();
            }

            Assert.IsNotNull(reservationDto);
            Assert.IsInstanceOfType(reservationDto, typeof(ReservationDto), "Reservation successfully added");
        }
        public void DeleteReservation(ReservationDto reservation)
        {
            WriteActualMethod();

            try
            {
                _reservationManager.Delete(reservation.ConvertToEntity());
            }
            catch (OptimisticConcurrencyException <Reservation> ex)
            {
                throw new FaultException <AutoReservationFault>(new AutoReservationFault
                {
                    ErrorCode    = AutoReservationFault.DataHasBeenModifiedInMeantime,
                    ErrorMessage = $"Database Entity-State: {ex.MergedEntity.ConvertToDto()}"
                });
            }
        }
Exemple #24
0
        public async Task InsertReservationWithAutoNotAvailableTest()
        {
            AutoDto autoDto = await _autoClient.GetByIdAsync(new GetAutoByIdRequest { Id = 1 });

            KundeDto kundeDto = await _kundeClient.GetByIdAsync(new GetKundeByIdRequest { Id = 1 });

            ReservationDto reservationDto = new ReservationDto
            {
                Von        = new DateTime(2020, 1, 11, 0, 0, 0, DateTimeKind.Utc).ToTimestamp(),
                Bis        = new DateTime(2020, 1, 28, 0, 0, 0, DateTimeKind.Utc).ToTimestamp(),
                RowVersion = Google.Protobuf.ByteString.CopyFromUtf8(""),
                Auto       = autoDto,
                Kunde      = kundeDto
            };

            Assert.Throws <RpcException>(() => _target.Insert(reservationDto));
        }
Exemple #25
0
        public async Task CheckAvailabilityIsFalseTest()
        {
            AutoDto autoDto = await _autoClient.GetByIdAsync(new GetAutoByIdRequest { Id = 1 });

            KundeDto kundeDto = await _kundeClient.GetByIdAsync(new GetKundeByIdRequest { Id = 1 });

            ReservationDto reservationDto = new ReservationDto
            {
                Von        = new DateTime(2020, 1, 30, 0, 0, 0, DateTimeKind.Utc).ToTimestamp(),
                Bis        = new DateTime(2020, 1, 20, 0, 0, 0, DateTimeKind.Utc).ToTimestamp(),
                RowVersion = Google.Protobuf.ByteString.CopyFromUtf8(""),
                Auto       = autoDto,
                Kunde      = kundeDto
            };

            Assert.False(_target.CarAvailability(reservationDto).IsAvailable);
        }
        public void UpdateReservationWithInvalidDateRangeTest()
        {
            Target.GetReservation(1);
            CallbackSpy.WaitForAnswer();
            ReservationDto reservation = CallbackSpy.ReservationSpy.First();

            CallbackSpy.ReservationSpy.Clear();

            reservation.Von = reservation.Bis;
            Target.UpdateReservation(reservation);
            CallbackSpy.WaitForAnswer();
            string ex = CallbackSpy.ExceptionSpy;

            Assert.AreEqual("Reservation must be at 24 hours long", ex);

            CallbackSpy.ExceptionSpy = null;
        }
Exemple #27
0
        public async Task <bool> DeleteReservationAsync(ReservationDto reservation)
        {
            ValidateNull(Logger, reservation);
            var result           = true;
            var seatReservations = (await _unitOfWork.RepositoryTicket.GetSeatReservationsByReservationIdAsync(reservation.Id)).ToList();

            if (!ValidateSeatReservations(seatReservations))
            {
                return(false);
            }
            await _unitOfWork.Transaction().PerformBlock(async() =>
            {
                result = result && await DeleteAllReservationsAsync(seatReservations);
            }).Commit();

            return(result);
        }
        public async Task UpdateReservationWithAutoNotAvailableTest()
        {
            GetReservationRequest requestId = new GetReservationRequest {
                IdFilter = 2
            };
            ReservationDto toUpdate = _target.GetReservation(requestId);

            DateTime from = new DateTime(2020, 1, 19, 0, 0, 0, DateTimeKind.Utc);
            DateTime to   = new DateTime(2020, 1, 22, 0, 0, 0, DateTimeKind.Utc);

            //act
            toUpdate.From = from.ToTimestamp();
            toUpdate.To   = to.ToTimestamp();

            // assert
            Assert.Throws <RpcException>(() => _target.UpdateReservation(toUpdate));
        }
        public async Task UpdateReservationWithInvalidDateRangeTest()
        {
            GetReservationRequest requestId = new GetReservationRequest {
                IdFilter = 1
            };
            ReservationDto toUpdate = _target.GetReservation(requestId);

            DateTime from = new DateTime(2020, 12, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime to   = new DateTime(2020, 12, 3, 0, 0, 0, DateTimeKind.Utc);

            //act
            toUpdate.From = to.ToTimestamp();
            toUpdate.To   = from.ToTimestamp();

            // assert
            Assert.Throws <RpcException>(() => _target.UpdateReservation(toUpdate));
        }
Exemple #30
0
        public async Task CheckAvailabilityIsTrueTest()
        {
            var reservationToCheck = new ReservationDto
            {
                Von  = DateTime.UtcNow.ToTimestamp(),
                Bis  = DateTime.UtcNow.AddHours(1).ToTimestamp(),
                Auto = new AutoDto {
                    Id = 3
                },
                Kunde = new KundeDto {
                    Id = 4
                }
            };
            var result = await _target.CheckAvailabilityAsync(reservationToCheck);

            Assert.True(result.IsAvailable);
        }