コード例 #1
0
        //TODO
        internal CancelBikeReservationResult CancelReservation(int idUser, int idBike, string reserveCode, string comments)
        {
            UserManager usrManager = new UserManager();
            CancelBikeReservationResult res = new CancelBikeReservationResult();
            BikeDao dao = new BikeDao();
            ReserveDao reDao = new ReserveDao();
            ReserveCancelationDao reCnsDao = new ReserveCancelationDao();

            Reserve reserve = reDao.getReserve(idBike, reserveCode);
            if (reserve == null)
            {
                throw new Exception("Código de reserva inválido");
            }
            else if (reserve.idUser != idUser)
            {
                throw new Exception("La reserva no pertenece a ese usuario.");
            }
            else if (reserve.idState != Constants.STATE_RESERVE_ACTIVE)
            {
                throw new Exception("La reserva no está en un estado válido");
            }
            else if ((DateTime.Now - reserve.creationTime).Minutes > Constants.RESERVE_TIMEOUT)
            {
                res.resCod = 1;
                res.resDesc = "La reserva ha expirado";

                reDao.UpdateStatus(reserve.id, Constants.STATE_RESERVE_EXPIRED);
                reCnsDao.Insert(reserve.id, comments);
                User currentUsr = usrManager.getUser(idUser);
                if (currentUsr.profile == Constants.PROFILE_COMMON)
                {
                    dao.UpdateStatus(idBike, Constants.STATE_BIKE_FREE);
                }
                else if (currentUsr.profile == Constants.PROFILE_STATION)
                {
                    dao.UpdateStatus(idBike, Constants.STATE_BIKE_IN_STATION);
                }

                usrManager.cancelReservation(reserve.idUser);
            }
            else
            {
                dao.UpdateStatus(idBike, Constants.STATE_BIKE_FREE);
                usrManager.cancelReservation(reserve.idUser);
                res.resCod = 0;
            }

            return res;
        }
コード例 #2
0
        internal PassBikeResult Pass(int idUser, int idBike, string reserveCode)
        {
            PassBikeResult res = new PassBikeResult();

            BikeDao dao = new BikeDao();
            ReserveDao reDao = new ReserveDao();
            ReserveCancelationDao reCnsDao = new ReserveCancelationDao();

            UserManager usrManager = new UserManager();

            bool userOk = usrManager.isOkForPass(idUser);
            if (userOk == false)
            {
                throw new Exception("Usuario no tiene bicicleta");
            }

            Bike bike = dao.getBike(idBike);
            if (bike.idState != Constants.STATE_BIKE_RESERVED
                && bike.idState != Constants.STATE_BIKE_FREE)
            {
                throw new Exception("Bicicleta no disponible para entrega");
            }

            Reserve reserve = reDao.getReserve(idBike, reserveCode);
            if (reserve == null)
            {
                throw new Exception("Código de reserva inválido");
            }
            else if (reserve.idState != Constants.STATE_RESERVE_ACTIVE)
            {
                throw new Exception("La reserva no está en un estado válido");
            }
            else if ((DateTime.Now - reserve.creationTime).Minutes > Constants.RESERVE_TIMEOUT)
            {
                res.resCod = 1;
                res.resDesc = "La reserva ha expirado";

                reDao.UpdateStatus(reserve.id, Constants.STATE_RESERVE_EXPIRED);
                reCnsDao.Insert(reserve.id, Constants.RESERVE_CANCEL_REASON_TIMEOUT);
                User currentUsr = usrManager.getUser(idUser);
                if (currentUsr.profile == Constants.PROFILE_COMMON)
                {
                    dao.UpdateStatus(idBike, Constants.STATE_BIKE_FREE);
                }
                else if (currentUsr.profile == Constants.PROFILE_STATION)
                {
                    dao.UpdateStatus(idBike, Constants.STATE_BIKE_IN_STATION);
                }

                usrManager.cancelReservation(reserve.idUser);
            }
            else
            {
                dao.UpdateUser(idBike, reserve.idUser);
                dao.UpdateStatus(idBike, Constants.STATE_BIKE_IN_USE);
                reDao.UpdateStatus(reserve.id, Constants.STATE_RESERVE_USED);
                usrManager.changeState(reserve.idUser, Constants.STATE_USER_HAS_BIKE_ASSIGNED);
                usrManager.changeState(idUser, Constants.STATE_USER_HAS_NO_BIKE);
                res.resCod = 0;
            }
            return res;
        }