/// <summary>
        /// Requests the movie to be barrowed
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task OnPostAsync(int id)
        {
            // Get the movie from the database
            var movie = await DbContext.Movie.Where(m => m.ID == id).SingleOrDefaultAsync();

            // Check to see if the movie is null
            if (movie != null)
            {
                // Create a new barrow request
                var request = new BarrowRequest
                {
                    DateRequested = DateTime.UtcNow,
                    MovieID       = movie.ID,
                    MovieTitle    = movie.Title,
                    MovieOwner    = movie.OwnerObjectIdentifier,
                    RequestedByObjectIdentifier = AuthenticatedUserInfo.ObjectIdentifier,
                    RequestedByFirstName        = AuthenticatedUserInfo.FirstName,
                    RequestedByLastName         = AuthenticatedUserInfo.LastName,
                    RequestedByEmailAddress     = AuthenticatedUserInfo.EmailAddress,
                    Status = MovieStatuses.BarrowRequested
                };
                // Add the request to the database
                DbContext.BarrowRequest.Add(request);
                // Save the database changes
                await DbContext.SaveChangesAsync();
            }
            // Fetch the updated movies set
            Movies = await DbContext.Movie.Where(m => m.Sharable == true).ToListAsync();
        }
示例#2
0
        /// <summary>
        /// Request to return the movie back to the user
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            // Make sure an id is present
            if (id <= 0)
            {
                return(NotFound());
            }
            // Get the movie from the db
            var movie = await DbContext.Movie.Where(m => m.ID == id).SingleOrDefaultAsync();

            // Make sure the movie isn't null
            if (movie == null)
            {
                return(NotFound());
            }
            // Create a new return request
            var request = new BarrowRequest
            {
                MovieID                     = movie.ID,
                MovieOwner                  = movie.OwnerObjectIdentifier,
                MovieTitle                  = movie.Title,
                RequestedByFirstName        = AuthenticatedUserInfo.FirstName,
                RequestedByLastName         = AuthenticatedUserInfo.LastName,
                RequestedByEmailAddress     = AuthenticatedUserInfo.EmailAddress,
                RequestedByObjectIdentifier = AuthenticatedUserInfo.ObjectIdentifier,
                DateRequested               = DateTime.UtcNow,
                Status = MovieStatuses.ReturnRequested
            };

            // Update the status of the movie
            movie.Status = MovieStatuses.ReturnRequested;
            // Update the movie
            DbContext.Movie.Update(movie);
            // Add the request
            DbContext.BarrowRequest.Add(request);
            // Save the db changes
            await DbContext.SaveChangesAsync();

            // Get the updated list of barrowed movies
            Movies = await DbContext.Movie.Where(m => m.BarrowedByObjectIdentifier == AuthenticatedUserInfo.ObjectIdentifier).ToListAsync();

            // Return the page
            return(Page());
        }