public async Task <bool> Handle(CreateReservationCommand request, CancellationToken cancellationToken) { _logger.LogInformation("CreateReservationCommandHandler Called"); try { var reservation = new Models.Reservation { Id = request.Id, ResourceId = request.ResourceId, Timeslot = request.Timeslot, UserId = request.UserId }; await _reservationRepository.AddAsync(reservation); _eventBus.PublishEvent(new ReservationCreatedEvent(request.Id, request.UserId, request.ResourceId, request.Timeslot)); } catch (Exception e) { Console.WriteLine(e); throw; } return(await Task.FromResult(true)); }
public async Task <IActionResult> Create([Bind("MembershipId,CustomerId,Details,StartDate,EndDate")] Reservation reservation) { if (ModelState.IsValid) { await _reservationRepository.AddAsync(reservation); return(RedirectToAction(nameof(Index))); } ViewData["CustomerId"] = new SelectList(_reservationRepository.GetAllCustomers(), "CustomerId", "Name", reservation.CustomerId); ViewData["MembershipId"] = new SelectList(_reservationRepository.GetAllMemberships(), "MembershipId", "Title", reservation.MembershipId); return(View(reservation)); }
public async Task RegisterReservation(ReservationOnCreateDto reservationDto) { var restaurant = await _restaurantRepository.GetAsync(reservationDto.Restaurant.Id); var customer = await _customerRepository.GetAsync(reservationDto.Customer.Login); var table = restaurant.Tables.SingleOrDefault(x => x.Id == reservationDto.TableId); var reservation = new Reservation(restaurant, reservationDto.DateStart, reservationDto.DateEnd, table, customer); await _reservationRepository.AddAsync(reservation); }
public async Task AddAsync(ReservationDto obj) { var reservation = Reservation.FromDto(obj); var car = await _carService.GetByIdAsync(reservation.CarId); var carModel = await _carModelService.GetByIdAsync(car.CarModelid); var carCategory = await _carCategoryService.GetByIdAsync(carModel.CategoryId); reservation.DailyFee = carCategory.DailyFee; reservation.SetActive(); reservation.CalculateTotal(); await _repository.AddAsync(reservation); }
public async Task <AircraftReservation> AddReservation(AircraftReservation aircraftReservation) { var reservations = await _reservationRepository.ListAllAsync(); var exist = reservations.Where(f => f.Intersect(aircraftReservation)).FirstOrDefault(); if (exist != null) { return(null); } await _reservationRepository.AddAsync(aircraftReservation); return(aircraftReservation); }
public async Task <ReservationResponse> Handle(CreateReservationCommand request, CancellationToken cancellationToken) { var reservationEntity = ReservationMapper.Mapper.Map <Reserve>(request); if (reservationEntity == null) { throw new ApplicationException($"Entity could not be mapped."); } var newOrder = await _repository.AddAsync(reservationEntity); var reservationResponse = ReservationMapper.Mapper.Map <ReservationResponse>(newOrder); return(reservationResponse); }
public async Task AddAsync(CreateReservationRequest request) { if (await _animalRepository.GetById(request.AnimalId) == null) { throw new BadRequestException("Dane zwierzę nie istnieje"); } await _reservationRepository.AddAsync(new Reservation() { StartDate = request.StartDate, EndDate = request.EndDate, AnimalId = request.AnimalId, Comments = request.Comments, Cost = request.Cost }); }
public override async Task HandleAsync(BookProduct command) { await base.LogHandleAsync(command); if (command.ProductId > 0 && await _repository.GetAsync(command.ProductId) == null) { await _repository.AddAsync(new Reservation(command.OrderId, command.ClientId, command.ProductId)); await _messageBroker.PublishAsync(new ProductReserved(command.OrderId, command.ClientId, command.ProductId, command.Price)); } else { await _messageBroker.PublishAsync(new ProductReservationFailed(command.OrderId, command.ProductId)); } }
public async Task <CommandResponse> Handle(CreateReservationCommand request, CancellationToken cancellationToken) { if (!request.ContactId.HasValue) { return(CommandResponse.Fail("Contact Invalid")); } var contact = await _contactRepository.GetByIdAsync(request.ContactId.Value); if (contact == null) { var contactCreated = CreateContact(request); if (contactCreated == null) { return(CommandResponse.Fail("Contact Invalid")); } contact = contactCreated; } var reservation = new Reservation( id: request.ReservationId, message: request.Message, contact: contact, ranking: 1, favorited: false ); if (!reservation.IsValid()) { foreach (var item in reservation.ValidationResult.Errors) { DomainNotification.Fail(item.ErrorMessage); } return(CommandResponse.Fail("Reservation invalid !")); } await _reservationRepository.AddAsync(reservation); var result = await _reservationRepository.CommitAsync(); return(result.Success ? CommandResponse.Ok() : CommandResponse.Fail("Fail recording the register in database !")); }
/// <summary> /// This Method Trys to Add the Reservation to the corresponding show /// in the show service. If success -> Add the Reservation /// </summary> public async Task <bool> AddAsync(ReservationItem item) { if (item.ShowItemId == null) // ShowItemId is invalid { return(false); } if (!item.ReservationDateTime.HasValue) // DateTime missing { item.ReservationDateTime = DateTime.UtcNow; } bool isAddedOnShow = await ShowService(item).TryAddReservationToShowAsync(item); if (!isAddedOnShow) // show was not added to show { return(false); } return(await _reservationRepository.AddAsync(item)); }
public async Task <ReservationResponse> SaveAsync(Reservation reservation) { try { var existingPackage = await packageRepository.FindByIdAsync(reservation.Packageid); if (existingPackage == null) { return(new ReservationResponse("Invalid package.")); } await reservationRepository.AddAsync(reservation); await unitOfWork.CompleteAsync(); return(new ReservationResponse(reservation)); } catch (Exception ex) { // Do some logging stuff return(new ReservationResponse($"An error occurred when saving the reservation: {ex.Message}")); } }
public async Task <int> AddReservationAsync(AddReservationDto addReservationDto) { return(await _reservationRepository.AddAsync( _reservationConverter.AddReservationDtoToReservation(addReservationDto))); }