コード例 #1
0
        public object GetTripForUser(int ID)
        {
            var trip          = service.Get(ID);
            var apartment     = apartmentService.GetAll();
            var CurrentUserID = User.GetEmpoeeID();
            var tripToBoard   = new
            {
                ArrivalCountry   = trip.ArrivalOffice.Country,
                ArrivalCity      = trip.ArrivalOffice.City,
                DepartureCountry = trip.DepartureOffice.Country,
                DepartureCity    = trip.DepartureOffice.City,
                ReturnDate       = trip.ReturnDate,
                DepartureDate    = trip.DepartureDate,
                Status           = trip.Status,

                Employee = trip.EmployeesToTrip.ToInfo().Where(x => x.EmployeeID == CurrentUserID),

                Tickets = trip.PlaneTickets?.ToInfo().Where(x => x.EmployeeID == CurrentUserID),

                trip.IsPlaneNeeded,

                Reservations = trip.Reservations?.ToInfo().Where(x => x.EmployeeID == CurrentUserID),

                trip.IsCarRentalNeeded,
                Rentals = trip.CarRentals?.ToInfo(),

                trip.IsCarCompensationNeeded,
                GasCompensations = trip.GasCompensations?.ToInfo().Where(x => x.EmployeeID == CurrentUserID),
            };

            return(tripToBoard);
        }
コード例 #2
0
        public async Task <ActionResult> ApproveTrip(int id, bool needRoom)
        {
            EmployeeToTrip employeeToTrip = employeeToTripService.GetByID(id);
            var            UserID         = User.GetEmpoeeID();

            employeeToTrip.Status = "APPROVED";
            employeeToTripService.Update(employeeToTrip);

            Trip trip = service.Get(employeeToTrip.TripId);

            if (trip.Status == "CREATED")
            {
                trip.Status = "CONFIRMED";
                service.Update(trip);
            }

            if (needRoom != true)
            {
                var home = new Apartment
                {
                    Name       = "HOME",
                    RoomNumber = 1,
                    Price      = 0,
                    Currency   = "EUR",
                    Address    = " ",
                    Type       = "HOME",
                    OfficeId   = employeeToTrip.Trip.ArrivalOfficeID
                };

                await service.SaveHotelorHome(home);

                var newReservation = new Reservation
                {
                    TripID      = employeeToTrip.TripId,
                    EmployeeID  = employeeToTrip.EmployeeID,
                    ApartmentID = home.ApartmentID,
                    CheckIn     = employeeToTrip.Trip.DepartureDate,
                    CheckOut    = employeeToTrip.Trip.ReturnDate
                };

                await service.SaveReservation(newReservation);

                return(Ok());
            }

            return(Ok());
        }
コード例 #3
0
        public bool AllowEdit(int tripID)
        {
            var currentUserID = User.GetEmpoeeID();
            var trip          = service.Get(tripID);

            if (User.IsInRole(Role.Admin))
            {
                return(true);
            }
            else if (trip.OrganizerID == currentUserID)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public IEnumerable <object> GetMyTrips()
        {
            var currentUserID = User.GetEmpoeeID();
            var myTrips       = service.GetAllMyTrips();

            myTrips = myTrips.OrderByDescending(x => x.EmployeesToTrip.Where(a => a.EmployeeID == currentUserID).Select(t => t.Status).Contains("PENDING") ? 1 : 2).ThenBy(x => x.Status.Equals("FINISHED") ? 3 : x.Status.Equals("PLANNED") ? 4 : 5).ThenByDescending(a => a.DepartureDate);

            IEnumerable <object> trips = myTrips.Select(x =>
            {
                return(new
                {
                    ID = x.TripID,
                    ArrivalOffice = x.ArrivalOffice,
                    DepartureOffice = x.DepartureOffice,
                    ReturnDate = x.ReturnDate,
                    DepartureDate = x.DepartureDate,
                    Status = x.EmployeesToTrip.Where(a => a.EmployeeID == currentUserID).Select(t => t.Status),
                });
            });

            return(trips);
        }
コード例 #5
0
        public async Task <ActionResult> Add([FromBody] CreateTrip item)
        {
            var trip = new Trip
            {
                ArrivalOfficeID         = item.ArrivalOfficeID,
                DepartureDate           = item.DepartureDate,
                DepartureOfficeID       = item.DepartureOfficeID,
                IsPlaneNeeded           = item.IsPlaneNeeded,
                IsCarCompensationNeeded = item.IsCarCompensationNeeded,
                IsCarRentalNeeded       = item.IsCarRentalNeeded,
                ReturnDate      = item.ReturnDate,
                Status          = "CREATED",
                OrganizerID     = User.GetEmpoeeID(),
                EmployeesToTrip = item.Employees.Select(employee => new EmployeeToTrip
                {
                    EmployeeID = employee,
                    Status     = "PENDING",
                    WasRead    = false,
                }).ToList(),
            };
            var result = await service.Add(trip);

            //foreach (var employee in item.Employees)
            //{
            //    var employeeToTrip = new EmployeeToTrip
            //    {
            //        EmployeeID = employee,
            //        TripId = result.TripID,
            //        Status = "PENDING",
            //        WasRead = false,
            //    };
            //    await employeeToTripService.Add(employeeToTrip);
            //}

            return(Ok());
        }