public async Task <IActionResult> Edit(int RideId, [Bind("RideId,RideStatusId,PostId,RequestId")] Ride ride)
        {
            if (RideId != ride.RideId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _rideLogic.UpdateRide(ride);
                    await _rideLogic.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RideExists(ride.RideId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PostId"]       = new SelectList(_context.Post, "PostId", "Destination", ride.PostId);
            ViewData["RequestId"]    = new SelectList(_context.Request, "RequestId", "RequestId", ride.RequestId);
            ViewData["RideStatusId"] = new SelectList(_context.RideStatus, "RideStatusId", "RideStatusDescription", ride.RideStatusId);
            return(View(ride));
        }
示例#2
0
        public void UpdateRequest(RideRequestDto request)
        {
            var entityRequest  = _rideRequestRepository.GetRequestById(request.RideRequestId);
            var previousStatus = _mapper.Map <Db.Entities.Status, Dto.Status>(entityRequest.Status);

            if (request.Status == previousStatus)
            {
                return; // Should exception be thrown ? This is unexpected behavior, though returning prevents any undesired consequences
            }

            if (request.Status == Dto.Status.CANCELED)
            {
                request.SeenByDriver    = false;
                request.SeenByPassenger = true;
            }
            else
            {
                request.SeenByDriver    = true;
                request.SeenByPassenger = false;
            }
            var rideToUpdate = _rideLogic.GetRideById(request.RideId);

            if (request.Status == Dto.Status.ACCEPTED && previousStatus == Dto.Status.WAITING)
            {
                if (rideToUpdate.NumberOfSeats != 0)
                {
                    if (_passengerLogic.IsUserAlreadyAPassenger(request.RideId, entityRequest.PassengerEmail))
                    {
                        throw new AlreadyAPassengerException();
                    }
                    else
                    {
                        _passengerLogic.AddPassenger(new PassengerDto {
                            Email = entityRequest.PassengerEmail, RideId = request.RideId, Completed = false
                        });
                        rideToUpdate.NumberOfSeats--;
                        _rideLogic.UpdateRide(rideToUpdate);
                    }
                }
                else
                {
                    throw new NoSeatsInRideException();
                }
            }
            else if (request.Status == Dto.Status.CANCELED && previousStatus == Dto.Status.ACCEPTED)
            {
                _passengerLogic.RemovePassenger(entityRequest.PassengerEmail, request.RideId);
                rideToUpdate.NumberOfSeats++;
                _rideLogic.UpdateRide(rideToUpdate);
            }
            _rideRequestRepository.UpdateRequest(_mapper.Map <RideRequestDto, RideRequest>(request));
        }
示例#3
0
        public bool UpdateRequest(RideRequestDto request)
        {
            request.SeenByPassenger = false;
            var isUpdated = _rideRequestRepository.UpdateRequest(_mapper.Map <RideRequestDto, RideRequest>(request));

            if (isUpdated && request.Status == Dto.Status.ACCEPTED)
            {
                var entityRequest = _rideRequestRepository.GetRequestById(request.RequestId);
                var rideToUpdate  = _rideLogic.GetRideById(request.RideId);
                if (rideToUpdate.NumberOfSeats != 0)
                {
                    var added = _passengerLogic.AddPassenger(new PassengerDto {
                        Email = entityRequest.PassengerEmail, RideId = request.RideId, Completed = false
                    });
                    if (added)
                    {
                        rideToUpdate.NumberOfSeats--;
                        var updatedSeats = _rideLogic.UpdateRide(rideToUpdate);
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(isUpdated);
        }
示例#4
0
        public void UpdateRequest(RideRequestDto request, string userEmail)
        {
            var entityRequest  = _rideRequestRepository.GetRequestById(request.RideRequestId);
            var previousStatus = _mapper.Map <Db.Entities.Status, Dto.Status>(entityRequest.Status);

            if (entityRequest.DriverEmail != userEmail && entityRequest.PassengerEmail != userEmail)
            {
                throw new UnauthorizedAccessException();
            }

            var driver = userEmail == entityRequest.DriverEmail;

            if (driver)
            {
                if (request.Status == Dto.Status.WAITING ||
                    request.Status == Dto.Status.CANCELED ||
                    previousStatus == Dto.Status.DELETED ||
                    previousStatus == Dto.Status.DENIED ||
                    (previousStatus == Dto.Status.ACCEPTED && request.Status == Dto.Status.DENIED))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            else
            {
                if (request.Status != Dto.Status.CANCELED)
                {
                    throw new UnauthorizedAccessException();
                }
            }

            if (request.Status == previousStatus)
            {
                return;
            }

            if (request.Status == Dto.Status.CANCELED)
            {
                request.SeenByDriver    = false;
                request.SeenByPassenger = true;
            }
            else
            {
                request.SeenByDriver    = true;
                request.SeenByPassenger = false;
            }
            var rideToUpdate = _rideLogic.GetRideById(request.RideId);

            if (request.Status == Dto.Status.ACCEPTED && previousStatus == Dto.Status.WAITING)
            {
                if (rideToUpdate.NumberOfSeats != 0)
                {
                    if (_passengerLogic.IsUserAlreadyAPassenger(request.RideId, entityRequest.PassengerEmail))
                    {
                        throw new AlreadyAPassengerException();
                    }
                    else
                    {
                        _passengerLogic.AddPassenger(new PassengerDto {
                            Email = entityRequest.PassengerEmail, RideId = request.RideId, Completed = false
                        });
                        rideToUpdate.NumberOfSeats--;
                        _rideLogic.UpdateRide(rideToUpdate);
                    }
                }
                else
                {
                    throw new NoSeatsInRideException();
                }
            }
            else if (request.Status == Dto.Status.CANCELED && previousStatus == Dto.Status.ACCEPTED)
            {
                _passengerLogic.RemovePassenger(entityRequest.PassengerEmail, request.RideId);
                rideToUpdate.NumberOfSeats++;
                _rideLogic.UpdateRide(rideToUpdate);
            }
            _rideRequestRepository.UpdateRequest(_mapper.Map <RideRequestDto, RideRequest>(request));
        }