Example #1
0
        public ActionResult RendreCar(int idBooking)
        {
            CarRendreCarViewsModel vm = new CarRendreCarViewsModel();

            BookingDTO         booking         = bookingLogic.Get(idBooking);
            RequestBookingDTO  requestBooking  = requestBookingLogic.GetByRequestBooking(booking.id_Request_Booking);
            StopOverDTO        stopOver        = stopOverLogic.GetByBooking(booking.Id);
            List <UserDTO>     passagersAller  = utilisateurLogic.ListPassagers(booking.Id, 1);
            List <UserDTO>     passagersRetour = utilisateurLogic.ListPassagers(booking.Id, 0);
            StatusDTO          status          = statusLogic.GetStatus(requestBooking.Id_Status);
            StopOverAddressDTO stopOverAddress = stopOverAddressLogic.GetStopOverAddress(stopOver.Id);
            UserDTO            driverAller     = utilisateurLogic.GetDriver(booking.Id, 1);
            UserDTO            driverRetour    = utilisateurLogic.GetDriver(booking.Id, 0);
            AddressDTO         addressAller    = addressLogic.GetAddress(booking.Id, 1);
            AddressDTO         addressRetour   = addressLogic.GetAddress(booking.Id, 0);
            UserDTO            createdBy       = utilisateurLogic.Get(requestBooking.CreateBy);

            Booking _booking = new Booking
            {
                booking         = booking,
                requestBooking  = requestBooking,
                stopOver        = stopOver,
                passagersAller  = passagersAller,
                passagerRetour  = passagersRetour,
                status          = status,
                stopOverAddress = stopOverAddress,
                driverAller     = driverAller,
                driverRetour    = driverRetour,
                addressRetour   = addressRetour,
                addressAller    = addressAller,
                createdBy       = createdBy
            };

            vm.Booking = _booking;

            return(View(vm));
        }
        /**
         * GetNotificationsTuples
         * Transforme une list de NotificationDTO en Tuple pour la NotificationIndexViewModel
         */
        private List <(NotificationDTO notification, RequestBookingDTO requestBooking, UserDTO user, string departureCity)> GetNotificationsTuples(List <NotificationDTO> list)
        {
            List <(NotificationDTO notification, RequestBookingDTO requestBooking, UserDTO user, string departureCity)> newList =
                new List <(NotificationDTO notification, RequestBookingDTO requestBooking, UserDTO user, string departureCity)>();

            if (list != null)
            {
                foreach (NotificationDTO notif in list)
                {
                    RequestBookingDTO reqBooking = new RequestBookingDTO();
                    reqBooking = requestBookingLogic.Get(notif.IdRequestBooking);

                    UserDTO user = new UserDTO();
                    user = userLogic.Get(reqBooking.CreateBy);

                    int        idBooking     = bookingLogic.GetByRequestBooking(reqBooking.id).Id;
                    AddressDTO address       = addressLogic.GetAddress(idBooking);
                    string     departureCity = "Non précisé";
                    if (address.Name != null)
                    {
                        departureCity = address.Name;
                    }
                    else if (address.Locality != null)
                    {
                        departureCity = address.Locality;
                    }

                    newList.Add((notif, reqBooking, user, departureCity));
                    if (notif.IsRead == 0)
                    {
                        notifLogic.MarkAsRead(notif.Id);
                    }
                }
            }

            return(newList);
        }
        public ActionResult Validations()
        {
            BookingValidationsViewsModel vm = new BookingValidationsViewsModel();
            List <Booking> bookings         = new List <Booking>();

            foreach (RequestBookingDTO requestBooking in requestBookingLogic.ListbyStatus(2))
            {
                BookingDTO         booking         = bookingLogic.GetByRequestBooking(requestBooking.id);
                StopOverDTO        stopOver        = stopOverLogic.GetByBooking(booking.Id);
                List <UserDTO>     passagersAller  = utilisateurLogic.ListPassagers(booking.Id, 1);
                List <UserDTO>     passagersRetour = utilisateurLogic.ListPassagers(booking.Id, 0);
                StatusDTO          status          = statusLogic.GetStatus(requestBooking.Id_Status);
                StopOverAddressDTO stopOverAddress = stopOverAddressLogic.GetStopOverAddress(stopOver.Id);
                UserDTO            driverAller     = utilisateurLogic.GetDriver(booking.Id, 1);
                UserDTO            driverRetour    = utilisateurLogic.GetDriver(booking.Id, 0);
                AddressDTO         addressAller    = addressLogic.GetAddress(booking.Id);
                AddressDTO         addressRetour   = addressLogic.GetAddress(booking.Id);
                UserDTO            createdBy       = utilisateurLogic.Get(requestBooking.CreateBy);


                bookings.Add(new Booking
                {
                    booking         = booking,
                    requestBooking  = requestBooking,
                    stopOver        = stopOver,
                    passagersAller  = passagersAller,
                    passagerRetour  = passagersRetour,
                    status          = status,
                    stopOverAddress = stopOverAddress,
                    driverAller     = driverAller,
                    driverRetour    = driverRetour,
                    addressRetour   = addressRetour,
                    addressAller    = addressAller,
                    createdBy       = createdBy
                });
            }

            vm.Bookings = bookings;

            return(View(vm));
        }
        public JsonResult AddRequestBooking(RequestBookingDTO requestBooking, int[] _passagers, int driver, int driver2, StopOverDTO stopOver, int addressDeparture, int addressArrival)
        {
            requestBooking.CreateBy = (int)Session["userID"];
            RequestBookingDTO requestBooking2 = requestBookingLogic.Insert(requestBooking);
            BookingDTO        booking         = bookingLogic.Insert(0, null, requestBooking2.id);
            NotificationDTO   notification    = new NotificationDTO
            {
                // CreationDateTimestamp default getdate en base
                IdRequestBooking = requestBooking2.id,
                IsForNewRequest  = 1,
                IsRead           = 0,
                IsForAdmin       = 0,
            };


            // Ajout des passagers
            if (_passagers != null)
            {
                for (int i = 0; i < _passagers.Length; i++)
                {
                    userBookingLogic.Insert(0, 1, booking.Id, _passagers[i]);
                    userBookingLogic.Insert(0, 0, booking.Id, _passagers[i]);

                    // Ajout des notification pour chaque passager
                    notification.IdUser = _passagers[i];
                    notificationLogic.Insert(notification);
                }
            }


            // Ajout des conducteurs. Ne pas oublier d'jaouter le driver retour.
            userBookingLogic.Insert(1, 1, booking.Id, driver);
            userBookingLogic.Insert(1, 0, booking.Id, driver2);

            // Ajout des notification pour les conducteurs
            notification.IdUser = driver;
            notificationLogic.Insert(notification);
            if (driver2 != null && driver2 != notification.IdUser)
            {
                notification.IdUser = driver2;
                notificationLogic.Insert(notification);
            }

            // Ajout de l'étape de base
            stopOver.Id_Booking        = booking.Id;
            stopOver.Id_Stop_Over_Type = 1;
            stopOver = stopOverLogic.Insert(stopOver);

            stopOverAddressLogic.Insert(addressDeparture, stopOver.Id, 1);
            stopOverAddressLogic.Insert(addressArrival, stopOver.Id, 0);

            List <UserDTO>     passagersAller  = utilisateurLogic.ListPassagers(booking.Id, 1);
            List <UserDTO>     passagersRetour = utilisateurLogic.ListPassagers(booking.Id, 0);
            StatusDTO          status          = statusLogic.GetStatus(requestBooking.Id_Status);
            StopOverAddressDTO stopOverAddress = stopOverAddressLogic.GetStopOverAddress(stopOver.Id);
            UserDTO            driverAller     = utilisateurLogic.GetDriver(booking.Id, 1);
            UserDTO            driverRetour    = utilisateurLogic.GetDriver(booking.Id, 0);
            AddressDTO         addressAller    = addressLogic.GetAddress(booking.Id, 1);
            AddressDTO         addressRetour   = addressLogic.GetAddress(booking.Id, 0);

            Booking _booking = new Booking
            {
                booking         = booking,
                requestBooking  = requestBooking,
                stopOver        = stopOver,
                passagersAller  = passagersAller,
                passagerRetour  = passagersRetour,
                status          = status,
                stopOverAddress = stopOverAddress,
                driverAller     = driverAller,
                driverRetour    = driverRetour,
                addressRetour   = addressAller,
                addressAller    = addressRetour
            };

            // Ajout des notifications pour les administrateurs
            List <UserDTO> admins      = roleLogic.Get_Users_With_Role("Administrateur");
            List <UserDTO> adminsToAdd = roleLogic.Get_Users_With_Role("Admin");

            admins.AddRange(adminsToAdd);

            notification.IsForAdmin = 1;
            if (admins.Count > 0)
            {
                foreach (UserDTO admin in admins)
                {
                    if (admin.Id != requestBooking.CreateBy)
                    {
                        notification.IdUser = admin.Id;
                        notificationLogic.Insert(notification);
                    }
                }
            }
            Session["notifs"] = notificationLogic.ListAllForUser((int)Session["userID"]).FindAll(n => n.IsRead == 0).Count;

            return(Json(_booking));
        }