Ejemplo n.º 1
0
        public ReservationAndPaidParkingPlacesDTO(Reservation r, PaidParkingPlace rp, List <PaidParkingPlace> ps)
        {
            if (r == null)
            {
                Reservation = null;
            }
            else
            {
                Reservation = new ReservationDTO(r);
            }

            if (rp == null)
            {
                RegularPaidParkingPlace = null;
            }
            else
            {
                RegularPaidParkingPlace = new PaidParkingPlaceDTO(rp);
            }

            if (ps == null || (ps != null && ps.Count == 0))
            {
                PaidParkingPlacesForFavoritePlaces = new List <PaidParkingPlaceDTO>();
            }
            else
            {
                PaidParkingPlacesForFavoritePlaces = ps.Select(p => new PaidParkingPlaceDTO(p)).ToList();
            }
        }
Ejemplo n.º 2
0
 public PaidParkingPlaceDTO(PaidParkingPlace paidParkingPlace)
 {
     Id = paidParkingPlace.Id;
     StartDateTimeAndroid = paidParkingPlace.GetStartDateTimeAndroidString();
     StartDateTimeServer  = paidParkingPlace.GetStartDateTimeServerString();
     TicketType           = paidParkingPlace.TicketType;
     ArrogantUser         = paidParkingPlace.ArrogantUser;
     ParkingPlace         = paidParkingPlace.ParkingPlace;
     ZoneId = ParkingPlace.Zone.Id;
 }
 public void AddPaidParkingPlace(PaidParkingPlace paidParkingPlace)
 {
     paidParkingPlaces.Add(paidParkingPlace);
 }
Ejemplo n.º 4
0
 public void AddPaidParkingPlace(PaidParkingPlace paidParkingPlace)
 {
     paidParkingPlaceDAO.AddPaidParkingPlace(paidParkingPlace);
 }
        public async Task <HttpResponseMessage> PostTaking([FromBody] TakingDTO value)
        {
            string token = GetHeader("token");

            if (token == null || (token != null && !TokenManager.ValidateToken(token)))
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            User loggedUser = usersService.GetLoggedUser(token);

            if (value.TicketType != TicketType.REGULAR)
            {
                bool nearByFavoritePlace = paidParkingPlacesService.CheckWheterIsParkingPlaceNearByFavoritePlace(
                    loggedUser.FavoritePlaces,
                    value.CurrentLocationLatitude,
                    value.CurrentLocationLongitude);
                if (!nearByFavoritePlace)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }
            }

            bool reservationFoundedAndRemoved = reservationsService.RemoveReservation(loggedUser);

            Zone zone = null;

            try
            {
                zone = zonesService.GetZone(value.ZoneId);
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }

            ParkingPlace parkingPlace = null;

            try
            {
                parkingPlace = zone.ParkingPlaces
                               .Where(pp => pp.Id == value.ParkingPlaceId)
                               .Single();
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }

            PaidParkingPlace paidParkingPlace;

            lock (parkingPlace)
            {
                if (parkingPlace.Status == ParkingPlaceStatus.TAKEN)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "parkingPlace.Status == ParkingPlaceStatus.TAKEN"));
                }
                else if (parkingPlace.Status == ParkingPlaceStatus.RESERVED && !reservationFoundedAndRemoved)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "parkingPlace.Status == ParkingPlaceStatus.RESERVED && !reservationRemoved"));
                }

                double distance = Distance.computeDistance(value.CurrentLocationLatitude,
                                                           value.CurrentLocationLongitude,
                                                           parkingPlace.Location.Latitude,
                                                           parkingPlace.Location.Longitude);
                if (distance > MAX_DISTANCE_FOR_TAKING)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }


                parkingPlace.Status = ParkingPlaceStatus.TAKEN;
                paidParkingPlace    = new PaidParkingPlace(parkingPlace, loggedUser, value.DateTimeAndroid, value.TicketType);
                paidParkingPlacesService.AddPaidParkingPlace(paidParkingPlace);

                lock (parkingPlace.Zone)
                {
                    parkingPlace.Zone.Version++;
                    parkingPlace.Zone.AddParkingPlaceChange(parkingPlace.Id, parkingPlace.Status);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, new PaidParkingPlaceDTO(paidParkingPlace)));
        }