public async Task <Reviewer> CreateReviewer(int userId) { Reviewer reviewer = new Reviewer { //UserId = userId }; await _dbContext.Reviewers.AddAsync(reviewer); await _dbContext.SaveChangesAsync(); return(reviewer); }
public async Task <bool> AddUser(SignUpModel signUpModel) { User user = _dbContext.Users.FirstOrDefault(u => u.Username == signUpModel.Username); if (user == null) { var reviewer = new Reviewer { Username = signUpModel.Username, User = new User { FirstName = signUpModel.FirstName, LastName = signUpModel.LastName, MiddleName = signUpModel.MiddleName, Username = signUpModel.Username, EmailAddress = signUpModel.EmailAddress, DateOfBirth = signUpModel.DateOfBirth, PasswordHash = BCrypt.Net.BCrypt.HashPassword(signUpModel.Password) } }; _dbContext.Reviewers.Add(reviewer); await _dbContext.SaveChangesAsync(); return(true); } return(false); }
public async Task <Movie> CreateMovie(MovieCreate createModel) { Movie movie = new Movie { Title = createModel.Title, Author = createModel.Author, ReleaseYear = createModel.ReleaseYear, ImagePath = await _posterData.GetMoviePoster(createModel.ReleaseYear, createModel.Title), AverageRating = 0 }; await _dbContext.Movies.AddAsync(movie); await _dbContext.SaveChangesAsync(); return(movie); }
public async Task <Review> CreateReview(ReviewCreate creationModel) { Review review; Movie movie = await _dbContext.Movies .FirstOrDefaultAsync(m => m.Title.ToLower() == creationModel.Movie.Title.ToLower() && m.ReleaseYear == creationModel.Movie.ReleaseYear); Reviewer reviewer = await _dbContext.Reviewers .FirstOrDefaultAsync(r => r.Username == creationModel.ReviewerName); // Create review model for an existing movie if (movie != null) { review = new Review { Title = creationModel.Title, MovieId = movie.Id, Body = creationModel.Body, Rating = creationModel.Rating, SubmitTime = creationModel.SubmitTime, ReviewerId = reviewer.Id }; // If movie exists, update it's AverageRating await UpdateAverageRating(movie.Id, creationModel.Rating); } // Create Review model for a new movie else { review = new Review { Title = creationModel.Title, Movie = new Movie { Title = creationModel.Movie.Title, Author = creationModel.Movie.Author, AverageRating = creationModel.Rating, ImagePath = await _posterData.GetMoviePoster(creationModel.Movie.ReleaseYear, creationModel.Movie.Title), ReleaseYear = creationModel.Movie.ReleaseYear }, Body = creationModel.Body, Rating = creationModel.Rating, SubmitTime = creationModel.SubmitTime, ReviewerId = reviewer.Id }; } await _dbContext.AddAsync(review); reviewer.NumberOfReviewsSubmitted++; _dbContext.Reviewers.Update(reviewer); await _dbContext.SaveChangesAsync(); return(review); }