Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
- // for details on configuring this project to bundle and minify static web assets.
- // Write your JavaScript code.
- const rateMovie = async (name, rating) => {
- const response = await fetch('/Movie/Rate', {
- body: JSON.stringify({ name, rating, }),
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- dataType: 'application/json',
- }
- })
- const responseParsedFromJSON = await response.json();
- return responseParsedFromJSON;
- };
- $('.rating-dropdown .dropdown-item').on('click', async (ev) => {
- const ratingSelected = $(ev.target).html();
- const movieName = $(ev.target).attr('data-name');
- try {
- const updatedMovie = await rateMovie(movieName, ratingSelected);
- $('.rating-dropdown .dropdown-toggle').html(updatedMovie.rating);
- } catch (err) {
- alert('There was an error submitting your request!');
- }
- })
- @model MovieViewModel
- @{
- ViewData["Title"] = "Admin Dashboard";
- }
- <div class="container">
- <div class="form-row">
- <div class="p-3 mb-2 bg-light text-dark col-lg-8">
- <h3>
- @Model.Name
- <div class="dropdown rating-dropdown">
- ☆
- <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- @Model.Rating
- </button>
- <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
- @for (int i = 1; i < 4; i++)
- {
- <a data-name="@Model.Name" class="dropdown-item" href="#">@i</a>
- }
- </div>
- </div>
- </h3>
- </div>
- </div>
- <div class="form-row">
- <div class="p-3 mb-2 bg-light text-dark col-lg-8">
- <img src="~/images/@Model.ImageUrl" alt="Movie Image" class="img-fluid" style="width: 100%; height:250px;" />
- </div>
- <div class="col-lg-2">
- @if (User.IsInRole("Admin"))
- {
- <a asp-area="Administration" asp-controller="MovieManagement" asp-action="ManageActors" asp-route-name="@Model.Name" class="btn btn-primary detailsMovieButton btn-block">Manage Actors</a>
- <a asp-area="Administration" asp-controller="MovieManagement" asp-action="Edit" asp-route-oldName="@Model.Name" class="btn btn-primary detailsMovieButton btn-block">Edit Movie</a>
- <a asp-area="Administration" asp-controller="MovieManagement" asp-action="Delete" asp-route-id="@Model.Name" class="btn btn-danger detailsMovieButton btn-block">Delete Movie</a>
- }</div> </div>
- <div class="form-row">
- <div class="p-3 mb-2 bg-light text-dark col-lg-8">
- <div class="form-group">
- <div class="form-row">
- <p>@Model.Storyline</p>
- </div>
- <div class="form-row">
- <p class="font-weight-bold">Director:</p> <br /><p class="pLeftPush">@Model.Director</p>
- </div>
- <div class="form-row">
- <p class="font-weight-bold">Duration:</p> <br /><p class="pLeftPush">@Model.Duration</p>
- </div>
- <div class="form-row">
- <p class="font-weight-bold">Genre:</p> <br /><p class="pLeftPush">@string.Join(" ", @Model.Genre)</p>
- </div>
- <div class="form-row">
- <p class="font-weight-bold">Actors:</p> <br /><p class="pLeftPush">@string.Join(", ", @Model.Actors)</p>
- </div>
- <div class="form-row">
- <div class="col-md-4">
- @if (!Model.Users.Contains(User.Identity.Name))
- {
- <a asp-area="" asp-controller="Watchlist" asp-action="Add" asp-route-username="@User.Identity.Name" asp-route-movieName="@Model.Name" class="btn btn-primary">+ Add to Watchlist</a>
- }
- else
- {
- <a asp-area="" asp-controller="Watchlist" asp-action="Remove" asp-route-username="@User.Identity.Name" asp-route-movieName="@Model.Name" class="btn btn-danger">- Remove from Watchlist</a>
- }
- </div>
- <div class="col-md-3">
- @*<a asp-area="" asp-controller="Comment" asp-action="Edit" asp-route-id="@Model.Name" class="btn btn-outline-primary">+ Add Comment</a>*@
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- [HttpPost]
- public async Task<IActionResult> Rate([FromBody] RateMovieModel rateMovieModel)
- {
- var movie = await this.movieService.RateMovie(rateMovieModel.Name, rateMovieModel.Rating);
- return Json(movie);
- }
- }
- }
- public class RateMovieModel
- {
- public string Name { get; set; }
- public double Rating { get; set; }
- }
- using AutoMapper;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using MovieManagement.Data;
- using MovieManagement.DataModels;
- using MovieManagement.Infrastructure;
- using MovieManagement.Services;
- using MovieManagement.Services.Contracts;
- using MovieManagement.Wrappers;
- namespace MovieManagement
- {
- public class Startup
- {
- public Startup(IConfiguration configuration, IHostingEnvironment environment)
- {
- this.Configuration = configuration;
- this.Environment = environment;
- }
- public IConfiguration Configuration { get; }
- public IHostingEnvironment Environment { get; }
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.Configure<CookiePolicyOptions>(options =>
- {
- // This lambda determines whether user consent for non-essential cookies is needed for a given request.
- options.CheckConsentNeeded = context => true;
- options.MinimumSameSitePolicy = SameSiteMode.None;
- });
- services.AddDbContext<MovieManagementContext>(options =>
- options.UseSqlServer(this.Configuration.GetConnectionString("TConnection")));
- if (this.Environment.IsDevelopment())
- {
- services.Configure<IdentityOptions>(options =>
- {
- // Password configuration
- options.Password.RequireDigit = false;
- options.Password.RequiredLength = 1;
- options.Password.RequireNonAlphanumeric = false;
- options.Password.RequireUppercase = false;
- options.Password.RequireLowercase = false;
- options.Password.RequiredUniqueChars = 0;
- });
- }
- // we register them as scoped because services are using dbcontext, which should be the same for during the operation.
- services.AddScoped<IMovieService, MovieService>();
- services.AddScoped<IUserService, UserService>();
- services.AddScoped<IGenreService, GenreService>();
- services.AddScoped<IWatchlistService, WatchlistService>();
- services.AddScoped<IMappingProvider, MappingProvider>();
- services.AddScoped<IUserManagerWrapper, UserManagerWrapper>();
- services.AddScoped<IRoleManagerWrapper, RoleManagerWrapper>();
- services.AddCors();
- services.AddIdentity<ApplicationUser, IdentityRole>()
- .AddRoleManager<RoleManager<IdentityRole>>()
- .AddEntityFrameworkStores<MovieManagementContext>()
- .AddDefaultTokenProviders();
- services.AddMemoryCache();
- services.AddAutoMapper();
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- app.UseExceptionHandler("/Home/Error");
- // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
- app.UseHsts();
- }
- app.UseHttpsRedirection();
- app.UseStaticFiles();
- app.UseCookiePolicy();
- app.UseAuthentication();
- app.UseCors();
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "areas",
- template: "{area:exists}/{controller=Admin}/{action=Index}/{id?}");
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement