Exemplo n.º 1
0
        public async Task <IActionResult> PutActor(int id, Actor actor)
        {
            if (id != actor.Id)
            {
                return(BadRequest());
            }

            _context.Entry(actor).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ActorExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutMovie(int id, Movie movie)
        {
            if (id != movie.MovieID)
            {
                return(BadRequest());
            }

            _context.Entry(movie).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MovieExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutShowing(int id, Showing showing)
        {
            if (id != showing.ShowingID)
            {
                return(BadRequest());
            }

            _context.Entry(showing).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ShowingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,Name,Adress")] Venue venue)
        {
            if (ModelState.IsValid)
            {
                db.Entry(venue).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(venue));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,MovieId,VenueId,ScreeningStart,ScreeningEnd,BasePrice,IsPremiere,SubtitleLanguage,Language")] Screening screening)
        {
            if (ModelState.IsValid)
            {
                db.Entry(screening).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.MovieId = new SelectList(db.Movies, "ID", "Title", screening.MovieId);
            ViewBag.VenueId = new SelectList(db.Venues, "ID", "Name", screening.VenueId);
            return(View(screening));
        }
Exemplo n.º 6
0
        public async Task <ActionResult <UserViewModel> > Register([FromForm] RegisterViewModel registerDetails)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!Role.AllRoles.Contains(registerDetails.Role))
            {
                return(BadRequest());
            }
            if (!CheckPasswordRequirements(registerDetails.Password))
            {
                return(BadRequest());
            }

            var resultUser = new User
            {
                UserName = encoder.Encode(registerDetails.Username),
                FullName = encoder.Encode(registerDetails.FullName),
            };

            context.Users.Add(resultUser);

            var createResult = await userManager.CreateAsync(resultUser, registerDetails.Password);

            if (!createResult.Succeeded)
            {
                return(BadRequest());
            }
            var roleResult = await userManager.AddToRoleAsync(resultUser, registerDetails.Role);

            if (!roleResult.Succeeded)
            {
                return(BadRequest());
            }

            context.Entry(resultUser).State = EntityState.Modified;
            await context.SaveChangesAsync();

            if (resultUser != null)
            {
                return(new OkObjectResult(new UserViewModel(resultUser, encoder, registerDetails.Role)));
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult> Edit([Bind(Include = "ID,Title,ReleaseDate,GenreId,Rating,Description,YouTubeLink")] Movie movie, HttpPostedFileBase upload)
        {
            var avatar = new Models.File();

            if (upload != null && upload.ContentLength > 0)
            {
                avatar = new Models.File
                {
                    Movie       = movie,
                    MovieId     = movie.ID,
                    FileName    = System.IO.Path.GetFileName(upload.FileName),
                    FileType    = FileType.Stock,
                    ContentType = upload.ContentType
                };
                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    avatar.Content = reader.ReadBytes(upload.ContentLength);
                }

                if (movie.Files != null)
                {
                    movie.Files = null;
                    db.Files.Remove(movie.Files.FirstOrDefault());
                }
                movie.Files = new List <Models.File> {
                    avatar
                };
            }

            if (ModelState.IsValid)
            {
                db.Entry(movie).State = EntityState.Modified;

                await db.SaveChangesAsync();

                db.Files.Add(avatar);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.GenreId = new SelectList(db.Genres, "ID", "Name", movie.GenreId);
            return(View(movie));
        }