Ejemplo n.º 1
0
        public async Task <IActionResult> AddToWatchHistory(int id)
        {
            var hasSeen = _context.Watchhistory.Where(r => r.CustomerMailAddress == User.Identity.Name).FirstOrDefault(r => r.MovieId == id);

            if (!ModelState.IsValid || hasSeen != null)
            {
                return(BadRequest(ModelState));
            }

            _repository.AddToWatchHistory(new Watchhistory()
            {
                CustomerMailAddress = User.Identity.Name,
                Invoiced            = true,
                MovieId             = id,
                Price     = 2,
                WatchDate = DateTime.Now
            });
            if (await _repository.SaveChangesAsync())
            {
                return(Json($"/api/movies/{id}/watch"));
            }

            return(BadRequest("Failed to save changes to the database"));
        }