예제 #1
0
        public async Task <IEnumerable <BookingLine> > GetBookingLines(int marinaOwnerId)
        {
            marinaOwnerId.ThrowIfNegativeId();

            var bookingLines = (List <BookingLine>) await _bookingLineService.GetAll();

            return(bookingLines.FindAll(b => b.Spot.Marina.MarinaOwner.MarinaOwnerId == marinaOwnerId));
        }
        public async Task <IActionResult> BookingsByMarinaOwner()
        {
            var bookingLines = await _bookingLineService.GetAll();

            bookingLines = new List <BookingLine>(bookingLines.ToList().FindAll(bl => bl.StartDate > DateTime.Now.AddDays(2)));

            // User is fully authorized to all content if he is a manager or admin
            var isFullyAuthorized =
                User.IsInRole(RoleName.Administrator) ||
                User.IsInRole(RoleName.Manager);

            // If he is an admin or manager indeed
            if (isFullyAuthorized)
            {
                // Return a view with all the resources displayed
                return(View(bookingLines));
            }

            // If user is only a boat owner instead
            if (User.IsInRole(RoleName.MarinaOwner))
            {
                // Get the logged in user's related marina owner object
                var loggedPerson = await _userService.GetUserAsync(User);

                var marinaOwner = _userService.GetMarinaOwnerFromPerson(loggedPerson);

                // Filter results so that they only see their spots in bookings
                bookingLines = await _marinaOwnerService.GetBookingLines(marinaOwner.MarinaOwnerId);

                bookingLines = new List <BookingLine>(bookingLines.ToList().FindAll(bl => bl.StartDate > DateTime.Now.AddDays(2)));

                // Return a view that only displays that marina owner's spots to confirm / cancel
                return(View(bookingLines));
            }

            // Forbid access to the page if user is none of the roles of a marinaowner owner, manager or admin
            return(Forbid());
        }