Exemplo n.º 1
0
        public async Task <IActionResult> ApproveRequest(string id)
        {
            //var userRequest = await _context.Request.SingleOrDefaultAsync(x => x.Id == requestId);
            var requests = _context.Request.Where(x => x.MovieId == id);

            var movie = await _mediator.Send(new GetSingleMovieRequest()
            {
                TmdbId = id
            });

            var request = GenerateApproveRequest(movie.Movie);

            var command = new ApproveRequestCommand {
                RequestObject = request
            };
            var result = await _mediator.Send(command);

            if (result == true)
            {
                //userRequest.Status = true;
                await requests.ForEachAsync(x => x.Status = true);

                await _context.SaveChangesAsync();
            }
            else
            {
                //userRequest.Status = false;
                await requests.ForEachAsync(x => x.Status = false);

                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Requests", "Admin"));
        }
Exemplo n.º 2
0
        public async Task Setup()
        {
            #region Configuration classes

            var fixture = new ConfigurationFixture();
            configurationBuilder = fixture.GenerateConfiguration();
            _radarrClient        = fixture.radarrClient;

            #endregion

            #region Database Con++text

            _mediaDbContext = fixture.GetDbContext();
            if (!_mediaDbContext.Request.Any())
            {
                _mediaDbContext.Request.Add(new Domain.UserRequest {
                    Id = 1, MovieId = "577922", UserId = "bacbb67d-819e-4e7b-bb29-c81ff99b5d1d"
                });
                await _mediaDbContext.SaveChangesAsync();
            }

            #endregion

            #region Http Helper
            _httpHelper = new HttpHelper(fixture.ServicePath, fixture.ApiKeys, fixture.radarrClient, fixture.tmdbClient);
            #endregion

            _mediator = A.Fake <IMediator>();
        }
Exemplo n.º 3
0
        public async Task <Unit> Handle(AddRequestCommand request, CancellationToken cancellationToken)
        {
            var res = await _context.Request.AddAsync(request.Request);

            await _context.SaveChangesAsync();

            return(new Unit());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> InviteWithUrl()
        {
            var token     = GenerateToken();
            var creatorId = await _userManager.GetUserAsync(User);

            var invite = new InviteToken
            {
                CreatedAt    = DateTime.Now.ToUniversalTime(),
                ValidUntil   = DateTime.Now.ToUniversalTime().AddHours(24),
                Status       = false,
                Token        = token,
                TokenOwnerId = creatorId.Id
            };

            await _context.InviteTokens.AddAsync(invite);

            await _context.SaveChangesAsync();

            var url = GenerateInviteUrl(token);

            return(PartialView("_InviteLinkPartial", url));
        }
Exemplo n.º 5
0
        public async Task <Unit> Handle(CancelRequestCommand command, CancellationToken cancellationToken)
        {
            try
            {
                var request = await _context.Request.SingleOrDefaultAsync(x => x.Id == command.RequestID);

                if (request == null)
                {
                    throw new Exception("Request returned no results");
                }
                else
                {
                    _context.Request.Remove(request);
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(new Unit());
        }