Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.81 KB | None | 0 0
  1. // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
  2. // for details on configuring this project to bundle and minify static web assets.
  3.  
  4.  
  5. // Write your JavaScript code.
  6. const rateMovie = async (name, rating) => {
  7. const response = await fetch('/Movie/Rate', {
  8. body: JSON.stringify({ name, rating, }),
  9. method: 'POST',
  10. headers: {
  11. 'Content-Type': 'application/json',
  12. dataType: 'application/json',
  13. }
  14. })
  15.  
  16. const responseParsedFromJSON = await response.json();
  17.  
  18. return responseParsedFromJSON;
  19. };
  20.  
  21.  
  22. $('.rating-dropdown .dropdown-item').on('click', async (ev) => {
  23. const ratingSelected = $(ev.target).html();
  24. const movieName = $(ev.target).attr('data-name');
  25. try {
  26. const updatedMovie = await rateMovie(movieName, ratingSelected);
  27. $('.rating-dropdown .dropdown-toggle').html(updatedMovie.rating);
  28. } catch (err) {
  29. alert('There was an error submitting your request!');
  30. }
  31. })
  32.  
  33.  
  34. @model MovieViewModel
  35.  
  36. @{
  37. ViewData["Title"] = "Admin Dashboard";
  38.  
  39. }
  40.  
  41. <div class="container">
  42. <div class="form-row">
  43. <div class="p-3 mb-2 bg-light text-dark col-lg-8">
  44. <h3>
  45. @Model.Name
  46. <div class="dropdown rating-dropdown">
  47. <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  48. @Model.Rating
  49. </button>
  50. <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
  51. @for (int i = 1; i < 4; i++)
  52. {
  53. <a data-name="@Model.Name" class="dropdown-item" href="#">@i</a>
  54. }
  55. </div>
  56. </div>
  57. </h3>
  58. </div>
  59. </div>
  60.  
  61. <div class="form-row">
  62. <div class="p-3 mb-2 bg-light text-dark col-lg-8">
  63. <img src="~/images/@Model.ImageUrl" alt="Movie Image" class="img-fluid" style="width: 100%; height:250px;" />
  64. </div>
  65. <div class="col-lg-2">
  66. @if (User.IsInRole("Admin"))
  67. {
  68. <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>
  69. <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>
  70. <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>
  71. }</div> </div>
  72. <div class="form-row">
  73. <div class="p-3 mb-2 bg-light text-dark col-lg-8">
  74. <div class="form-group">
  75. <div class="form-row">
  76. <p>@Model.Storyline</p>
  77. </div>
  78. <div class="form-row">
  79. <p class="font-weight-bold">Director:</p> <br /><p class="pLeftPush">@Model.Director</p>
  80.  
  81. </div>
  82. <div class="form-row">
  83. <p class="font-weight-bold">Duration:</p> <br /><p class="pLeftPush">@Model.Duration</p>
  84. </div>
  85. <div class="form-row">
  86. <p class="font-weight-bold">Genre:</p> <br /><p class="pLeftPush">@string.Join(" ", @Model.Genre)</p>
  87. </div>
  88. <div class="form-row">
  89. <p class="font-weight-bold">Actors:</p> <br /><p class="pLeftPush">@string.Join(", ", @Model.Actors)</p>
  90. </div>
  91. <div class="form-row">
  92. <div class="col-md-4">
  93. @if (!Model.Users.Contains(User.Identity.Name))
  94. {
  95. <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>
  96. }
  97. else
  98. {
  99. <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>
  100. }
  101. </div>
  102. <div class="col-md-3">
  103. @*<a asp-area="" asp-controller="Comment" asp-action="Edit" asp-route-id="@Model.Name" class="btn btn-outline-primary">+ Add Comment</a>*@
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110.  
  111.  
  112. [HttpPost]
  113. public async Task<IActionResult> Rate([FromBody] RateMovieModel rateMovieModel)
  114. {
  115. var movie = await this.movieService.RateMovie(rateMovieModel.Name, rateMovieModel.Rating);
  116.  
  117. return Json(movie);
  118. }
  119. }
  120. }
  121.  
  122. public class RateMovieModel
  123. {
  124. public string Name { get; set; }
  125.  
  126. public double Rating { get; set; }
  127. }
  128.  
  129. using AutoMapper;
  130. using Microsoft.AspNetCore.Builder;
  131. using Microsoft.AspNetCore.Hosting;
  132. using Microsoft.AspNetCore.Http;
  133. using Microsoft.AspNetCore.Identity;
  134. using Microsoft.AspNetCore.Mvc;
  135. using Microsoft.EntityFrameworkCore;
  136. using Microsoft.Extensions.Configuration;
  137. using Microsoft.Extensions.DependencyInjection;
  138. using MovieManagement.Data;
  139. using MovieManagement.DataModels;
  140. using MovieManagement.Infrastructure;
  141. using MovieManagement.Services;
  142. using MovieManagement.Services.Contracts;
  143. using MovieManagement.Wrappers;
  144.  
  145. namespace MovieManagement
  146. {
  147. public class Startup
  148. {
  149. public Startup(IConfiguration configuration, IHostingEnvironment environment)
  150. {
  151. this.Configuration = configuration;
  152. this.Environment = environment;
  153. }
  154.  
  155. public IConfiguration Configuration { get; }
  156. public IHostingEnvironment Environment { get; }
  157.  
  158. // This method gets called by the runtime. Use this method to add services to the container.
  159. public void ConfigureServices(IServiceCollection services)
  160. {
  161. services.Configure<CookiePolicyOptions>(options =>
  162. {
  163. // This lambda determines whether user consent for non-essential cookies is needed for a given request.
  164. options.CheckConsentNeeded = context => true;
  165. options.MinimumSameSitePolicy = SameSiteMode.None;
  166. });
  167.  
  168. services.AddDbContext<MovieManagementContext>(options =>
  169. options.UseSqlServer(this.Configuration.GetConnectionString("TConnection")));
  170.  
  171. if (this.Environment.IsDevelopment())
  172. {
  173. services.Configure<IdentityOptions>(options =>
  174. {
  175. // Password configuration
  176. options.Password.RequireDigit = false;
  177. options.Password.RequiredLength = 1;
  178. options.Password.RequireNonAlphanumeric = false;
  179. options.Password.RequireUppercase = false;
  180. options.Password.RequireLowercase = false;
  181. options.Password.RequiredUniqueChars = 0;
  182. });
  183. }
  184.  
  185. // we register them as scoped because services are using dbcontext, which should be the same for during the operation.
  186. services.AddScoped<IMovieService, MovieService>();
  187. services.AddScoped<IUserService, UserService>();
  188. services.AddScoped<IGenreService, GenreService>();
  189. services.AddScoped<IWatchlistService, WatchlistService>();
  190. services.AddScoped<IMappingProvider, MappingProvider>();
  191. services.AddScoped<IUserManagerWrapper, UserManagerWrapper>();
  192. services.AddScoped<IRoleManagerWrapper, RoleManagerWrapper>();
  193.  
  194. services.AddCors();
  195.  
  196. services.AddIdentity<ApplicationUser, IdentityRole>()
  197. .AddRoleManager<RoleManager<IdentityRole>>()
  198. .AddEntityFrameworkStores<MovieManagementContext>()
  199. .AddDefaultTokenProviders();
  200.  
  201. services.AddMemoryCache();
  202.  
  203. services.AddAutoMapper();
  204.  
  205.  
  206. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  207. }
  208.  
  209. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  210. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  211. {
  212. if (env.IsDevelopment())
  213. {
  214. app.UseDeveloperExceptionPage();
  215. }
  216. else
  217. {
  218. app.UseExceptionHandler("/Home/Error");
  219. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  220. app.UseHsts();
  221. }
  222.  
  223. app.UseHttpsRedirection();
  224. app.UseStaticFiles();
  225. app.UseCookiePolicy();
  226.  
  227. app.UseAuthentication();
  228.  
  229. app.UseCors();
  230.  
  231. app.UseMvc(routes =>
  232. {
  233. routes.MapRoute(
  234. name: "areas",
  235. template: "{area:exists}/{controller=Admin}/{action=Index}/{id?}");
  236.  
  237. routes.MapRoute(
  238. name: "default",
  239. template: "{controller=Home}/{action=Index}/{id?}");
  240. });
  241. }
  242. }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement