Exemplo n.º 1
0
        protected override async Task Handle(DeleteMovie request, CancellationToken cancellationToken)
        {
            var idOrUrl = request.IdOrUrl;
            var Context = request.Context;

            var result = await omdbService.Get(idOrUrl);

            if (result == null)
            {
                await Context.Channel.SendMessageAsync($"No movie with that id was found...");
            }

            using var scope = serviceProvider.CreateScope();
            var db = scope.ServiceProvider.GetService <BotDbContext>();

            if (!await db.Movie.AnyAsync(x => x.Id == result.imdbID))
            {
                await Context.Channel.SendMessageAsync($"***{ result.Title }*** was not on the list!");

                return;
            }
            var movie = await db.Movie.SingleAsync(x => x.Id == result.imdbID);

            db.Movie.Remove(movie);

            await db.SaveChangesAsync();

            await Context.Channel.SendMessageAsync($"***{ result.Title }*** was removed from the watchlist");
        }
Exemplo n.º 2
0
        protected override async Task Handle(AddWatched request, CancellationToken cancellationToken)
        {
            var idOrUrl = request.IdOrUrl;
            var Context = request.Context;

            var result = await omdbService.Get(idOrUrl);

            if (result == null)
            {
                await Context.Channel.SendMessageAsync($"No movie with that id was found...");
            }

            using var scope = serviceProvider.CreateScope();
            var db = scope.ServiceProvider.GetService <BotDbContext>();

            if (await db.Movie.AsQueryable().AnyAsync(x => x.Id == result.imdbID))
            {
                var movie = await db.Movie.AsQueryable().SingleAsync(x => x.Id == result.imdbID);

                movie.Picked      = false;
                movie.Watched     = true;
                movie.WatchedDate = DateTime.Now;
            }
            else
            {
                db.Movie.Add(new Movie
                {
                    Id              = result.imdbID,
                    Title           = result.Title,
                    Plot            = result.Plot,
                    Actors          = result.Actors,
                    Director        = result.Director,
                    Language        = result.Director,
                    Runtime         = result.Runtime,
                    Watched         = true,
                    WatchedDate     = DateTime.Now,
                    AddedBy         = Context.User.Id.ToString(),
                    AddedByUsername = Context.User.Username,
                    AddedAt         = DateTime.Now
                });
            }
            await db.SaveChangesAsync();

            await Context.Channel.SendMessageAsync($"***{ result.Title }*** has now been watched");
        }
Exemplo n.º 3
0
        protected override async Task Handle(DeletePick request, CancellationToken cancellationToken)
        {
            var idOrUrl = request.IdOrUrl;
            var Context = request.Context;

            var result = await omdbService.Get(idOrUrl);

            if (result == null)
            {
                await Context.Channel.SendMessageAsync($"No movie with that id was found...");
            }

            using var scope = serviceProvider.CreateScope();
            var db = scope.ServiceProvider.GetService <BotDbContext>();

            var mevent = await db.Event
                         .Include(x => x.EventMovies)
                         .ThenInclude(x => x.Movie)
                         .SingleOrDefaultAsync(x => x.Id == request.EventId);

            if (mevent == null)
            {
                await Context.Channel.SendMessageAsync($"Event not found...");

                return;
            }

            var em = mevent.EventMovies.SingleOrDefault(x => x.MovieId == result.imdbID);

            if (em != null)
            {
                mevent.EventMovies.Remove(em);
                await db.SaveChangesAsync();
            }

            await Context.Channel.SendMessageAsync($"***{ result.Title }*** removed from event");
        }
Exemplo n.º 4
0
        protected override async Task Handle(AddPick request, CancellationToken cancellationToken)
        {
            var idOrUrl = request.IdOrUrl;
            var Context = request.Context;

            var result = await omdbService.Get(idOrUrl);

            if (result == null)
            {
                await Context.Channel.SendMessageAsync($"No movie with that id was found...");
            }

            using var scope = serviceProvider.CreateScope();
            var db = scope.ServiceProvider.GetService <BotDbContext>();

            var mevent = await db.Event
                         .Include(x => x.EventMovies)
                         .ThenInclude(x => x.Movie)
                         .SingleOrDefaultAsync(x => x.Id == request.EventId);

            if (mevent == null)
            {
                await Context.Channel.SendMessageAsync($"Event not found...");

                return;
            }

            var alreadyselected = mevent.EventMovies.Select(x => x.Movie);

            if (alreadyselected.Any(x => x.Id == result.imdbID))
            {
                await Context.Channel.SendMessageAsync($"Movie already added to event..");
            }

            Movie movie;

            if (await db.Movie.AsQueryable().AnyAsync(x => x.Id == result.imdbID))
            {
                movie = await db.Movie.AsQueryable().SingleAsync(x => x.Id == result.imdbID);
            }
            else
            {
                movie = new Movie
                {
                    Id              = result.imdbID,
                    Title           = result.Title,
                    Plot            = result.Plot,
                    Actors          = result.Actors,
                    Director        = result.Director,
                    Language        = result.Director,
                    Runtime         = result.Runtime,
                    Picked          = true,
                    AddedBy         = Context.User.Id.ToString(),
                    AddedByUsername = Context.User.Username,
                    AddedAt         = DateTime.Now
                };
            }
            mevent.EventMovies.Add(new EventMovie {
                Movie = movie
            });
            await db.SaveChangesAsync();

            await Context.Channel.SendMessageAsync($"***{ result.Title }*** added to event");
        }