public async Task <IActionResult> UpdateReservation([FromRoute] Guid id, [FromBody] UpdateReservationCommand command)
        {
            try
            {
                command.Id = id;
                var result = await _mediator.Send(command);

                return(NoContent());
            }
            catch (ClassRoomAlreadyReservedAtThatTimePeriodException e)
            {
                logger.LogError(e.Message);
                return(BadRequest(e.Message));
            }
            catch (InstructorAlreadyAssignedAtThatTimePeriodException e)
            {
                logger.LogError(e.Message);
                return(BadRequest(e.Message));
            }
            catch (EntityNotFoundException e)
            {
                logger.LogError(e.Message);
                return(NotFound(e.Message));
            }
        }
Exemple #2
0
        public async Task <FlightReservationModel> Edit([FromBody] FlightReservationModel reservation)
        {
            if (ModelState.IsValid)
            {
                //IsReservationValidQuery isReservationValidQuery = new IsReservationValidQuery(reservation);
                //var isValid =   await _mediator.Send(isReservationValidQuery);
                if (true)
                {
                    try
                    {
                        UpdateReservationCommand updateReservationCommand = new UpdateReservationCommand(reservation);
                        var result = await _mediator.Send(updateReservationCommand);

                        reservation.ReturnResult = String.Join("/n", result.Errors);
                        return(reservation);
                    }
                    catch (MyValidationException ve)
                    {
                        System.Diagnostics.Debug.WriteLine(ve.Failures);

                        reservation.ReturnResult = ve.FailuresMessage.ToString();
                        return(reservation);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                }
            }
            reservation.ReturnResult = "Model State Not Valid";
            return(reservation);
        }
Exemple #3
0
        public async Task <IActionResult> Update(int id, UpdateReservationCommand command)
        {
            command.ReservationId = id;
            await Mediator.Send(command);

            return(NoContent());
        }
        public ReservationsViewModel()
        {
            addReservationCommand         = new AddReservationCommand(this);
            updateReservationCommand      = new UpdateReservationCommand(this);
            deleteReservationCommand      = new DeleteReservationCommand(this);
            changeDayTherapistReservation = new ChangeDayTherapistReservation(this);

            DateTime currentTime    = DateTime.Now;
            DateTime dataVisitStart = new DateTime(2019, 12, 23, 08, 30, 00);
            DateTime dataVisitEnd   = new DateTime(2019, 12, 23, 09, 30, 00);

            DatesReservations = new ObservableCollection <DateTime> {
                DateTime.Today
            };
            therapistsListToReservation = new ObservableCollection <string>
            {
            };
            readPatients();
            readTherapists();
            reservationsList = new ObservableCollection <ReservationModel>
            {
            };
            //DataGrid_Loaded();
            DataGridReservation_Loaded();
        }
Exemple #5
0
        public async Task CanUpdateReturnsTrue_UpdatesReservation()
        {
            var request = new UpdateReservationCommand()
            {
                Id = this.reservation.Id,
                ReservationState = ReservationStates.Accepted,
                CanUpdate        = (_) => true
            };

            await this.sut.Handle(request, CancellationToken.None).ConfigureAwait(false);

            var dbReservation = await this.Context.Reservations.FindAsync(request.Id).ConfigureAwait(false);

            Assert.Equal(request.ReservationState, dbReservation.ReservationState);
        }
Exemple #6
0
        private async Task <IActionResult> UpdateReservationAsync(long id, string reservationState, Predicate <CanUpdateReservationArgs> CanUpdate)
        {
            if (await authService.CheckIfBanned(this.User).ConfigureAwait(false))
            {
                return(this.Forbid());
            }

            var command = new UpdateReservationCommand()
            {
                Id = id, ReservationState = reservationState, CanUpdate = CanUpdate
            };

            await this.mediator.Send(command).ConfigureAwait(false);

            return(this.Ok());
        }
Exemple #7
0
        public async Task CanUpdateReturnsFalse_DoesNotUpdateReservation()
        {
            string oldState = this.reservation.ReservationState;

            var request = new UpdateReservationCommand()
            {
                Id = this.reservation.Id,
                ReservationState = ReservationStates.Accepted,
                CanUpdate        = (_) => false
            };

            await Assert
            .ThrowsAsync <CustomInvalidOperationException>(async() => await this.sut.Handle(request, CancellationToken.None).ConfigureAwait(false))
            .ConfigureAwait(false);

            var dbReservation = await this.Context.Reservations.FindAsync(request.Id).ConfigureAwait(false);

            Assert.Equal(oldState, dbReservation.ReservationState);
        }
 public ReservationsViewModel(AccommodationUnit unit, HomePageViewModel homePageViewModel)
 {
     HomePageViewModel = homePageViewModel;
     if (unit != null)
     {
         Unit         = unit;
         Reservations = ReservationService.GetReservations(Unit.Id, Unit.Accommodation.Id);
         UnitString   = "Floor : " + Unit.Floor + ", Number : " + Unit.Number;
     }
     else
     {
         Reservations = ReservationService.GetReservations(0, HomePageViewModel.Accommodation.Id);
     }
     //EnableUpdate = false;
     //EnableDelete = false;
     AddReservationCommand    = new AddReservationCommand(Unit, Reservation, this);
     UpdateReservationCommand = new UpdateReservationCommand(this);
     DeleteReservationCommand = new DeleteReservationCommand(this);
 }
        public Task <HttpResponseMessage> Put(UpdateReservationCommand reserve)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                _service.Update(reserve);

                response = Request.CreateResponse(HttpStatusCode.OK, new { message = "Pacote alterado com sucesso" });
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
            }

            var tsc = new TaskCompletionSource <HttpResponseMessage>();

            tsc.SetResult(response);
            return(tsc.Task);
        }