Exemple #1
0
        public async Task <IActionResult> Create(CartridgeAddRequest request)
        {
            var movieDb = MovieService.GetMovie(request.MovieId, true);

            if (movieDb == null)
            {
                return(BadRequest(ApiResponse.Failure("Movie", $"Movie with id: {request.MovieId} does not exist")));
            }

            await CartridgeService.AddCartridge(request);

            return(Ok(ApiResponse.Success()));
        }
Exemple #2
0
        /// <summary>
        /// Allows to add new cartridge
        /// </summary>
        /// <param name="request">Cartridge add request</param>
        public async Task AddCartridge(CartridgeAddRequest request)
        {
            var cartridgeToAdd = Mapper.Map <Cartridge>(request);
            await CartridgeRepo.CreateAsync(cartridgeToAdd);

            await CartridgeRepo.SaveChangesAsync();

            var cartridgeDb = await CartridgeRepo
                              .GetAll()
                              .AsNoTracking()
                              .FirstOrDefaultAsync(c => c.Id == cartridgeToAdd.Id);

            var copiesAmount = request.AvaibleAmount + request.UnavaibleAmount;

            if (copiesAmount == 0)
            {
                return;
            }

            await AddCopies(copiesAmount, request.AvaibleAmount, cartridgeDb.Id);
        }