Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdeli committed Jun 15, 2018
1 parent 77fee9b commit e737aea
Show file tree
Hide file tree
Showing 40 changed files with 492 additions and 86 deletions.
Binary file modified DI_v2.pptx
Binary file not shown.
2 changes: 1 addition & 1 deletion Domain/Context/MoviesMvcContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

entity.Property(e => e.ReleaseDate).HasColumnType("date");

entity.Property(e => e.Revenue).HasColumnType("decimal(14, 2)");
entity.Property(e => e.Price).HasColumnType("decimal(14, 2)");

entity.Property(e => e.Summary).HasMaxLength(1024);

Expand Down
2 changes: 1 addition & 1 deletion Domain/Interfaces/IMovieService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IMovieService
{
Task<IList<Movie>> GetAllAsync();

Task<Movie> GetAsync(int id);
Task<Movie> GetAsync(int id, string code = null);

Task<IList<ContentRating>> GetContentRatingsAsync();

Expand Down
2 changes: 1 addition & 1 deletion Domain/Models/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Movie()

[Required]
public string Title { get; set; }
public decimal? Revenue { get; set; }
public decimal? Price { get; set; }
public string PosterUrl { get; set; }
public string VideoUrl { get; set; }
public string VideoPosterUrl { get; set; }
Expand Down
17 changes: 17 additions & 0 deletions Domain/Services/FakePricingService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Domain.Interfaces;

namespace Domain.Services
{
public class FakePricingService : IPricingService
{
/// <summary>
///
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public decimal DiscountPercentage(string code)
{
return 0M;
}
}
}
15 changes: 12 additions & 3 deletions Domain/Services/MovieService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ namespace Domain.Services
public class MovieService : IMovieService
{
private readonly MoviesMvcContext context_;
private readonly IPricingService pricing_;

public MovieService(MoviesMvcContext context)
public MovieService(MoviesMvcContext context, IPricingService pricing)
{
context_ = context;
pricing_ = pricing;
}

public async Task<bool> AddAsync(Movie movie)
Expand All @@ -39,12 +41,19 @@ public async Task<IList<Movie>> GetAllAsync()
return movies;
}

public async Task<Movie> GetAsync(int id)
public async Task<Movie> GetAsync(int id, string code = null)
{
var movie = await context_.Movie
.Include(m => m.ContentRating)
.SingleOrDefaultAsync(m => m.MovieId == id);

if (movie == null) {
return null;
}

var discount = pricing_.DiscountPercentage(code);

movie.Price -= movie.Price * (discount / 100);

return movie;
}

Expand Down
43 changes: 43 additions & 0 deletions MoviesApi/Controllers/MoviesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Interfaces;
using Microsoft.AspNetCore.Mvc;

namespace MoviesApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MoviesController : ControllerBase
{
private readonly IMovieService movieService_;

public MoviesController(IMovieService movieService)
{
movieService_ = movieService;
}

// GET api/movies
[HttpGet]
public async Task<IActionResult> GetAllAsync()
{
var movies = await movieService_.GetAllAsync();

return Ok(movies);
}

// GET api/movies/1?code=12abc
[HttpGet("{id}")]
public async Task<IActionResult> GetAsync(int id, string code)
{
var movie = await movieService_.GetAsync(id, code);

if (movie == null) {
return NotFound(movie);
}

return Ok(movie);
}
}
}
19 changes: 19 additions & 0 deletions MoviesApi/MoviesApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions MoviesApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace MoviesApi
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
30 changes: 30 additions & 0 deletions MoviesApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59201",
"sslPort": 44372
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MoviesApi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
59 changes: 59 additions & 0 deletions MoviesApi/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Context;
using Domain.Interfaces;
using Domain.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace MoviesApi
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var connection = @"Server=localhost,1433;Database=MoviesMvc;Persist Security Info=True;uid=sa;pwd=D1m1tr1s!;ConnectRetryCount=0";

services.AddDbContext<MoviesMvcContext>(
options => options.UseSqlServer(connection));

services.AddTransient<IMovieService, MovieService>();
services.AddTransient<IPricingService, PricingService>();

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

// 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.UseHsts();
}

app.UseHttpsRedirection();
app.UseMvc();
}
}
}
9 changes: 9 additions & 0 deletions MoviesApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
8 changes: 8 additions & 0 deletions MoviesApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion MoviesHub/Models/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Movie()

[Required]
public string Title { get; set; }
public decimal? Revenue { get; set; }
public decimal? Price { get; set; }
public string PosterUrl { get; set; }
public string VideoUrl { get; set; }
public string VideoPosterUrl { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion MoviesHub/Models/MoviesMvcContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

entity.Property(e => e.ReleaseDate).HasColumnType("date");

entity.Property(e => e.Revenue).HasColumnType("decimal(14, 2)");
entity.Property(e => e.Price).HasColumnType("decimal(14, 2)");

entity.Property(e => e.Summary).HasMaxLength(1024);

Expand Down
6 changes: 3 additions & 3 deletions MoviesHub/Views/Movies/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Revenue" class="control-label"></label>
<input asp-for="Revenue" class="form-control" />
<span asp-validation-for="Revenue" class="text-danger"></span>
<label asp-for="Price" class="control-label"></label>
<input asp-for="Price" class="form-control" />
<span asp-validation-for="Price" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="PosterUrl" class="control-label"></label>
Expand Down
4 changes: 2 additions & 2 deletions MoviesHub/Views/Movies/Delete.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Revenue)
@Html.DisplayNameFor(model => model.Price)
</dt>
<dd>
@Html.DisplayFor(model => model.Revenue)
@Html.DisplayFor(model => model.Price)
</dd>
<dt>
@Html.DisplayNameFor(model => model.PosterUrl)
Expand Down
4 changes: 2 additions & 2 deletions MoviesHub/Views/Movies/Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
@Html.DisplayFor(model => model.Title)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Revenue)
@Html.DisplayNameFor(model => model.Price)
</dt>
<dd>
@Html.DisplayFor(model => model.Revenue)
@Html.DisplayFor(model => model.Price)
</dd>
<dt>
@Html.DisplayNameFor(model => model.PosterUrl)
Expand Down
6 changes: 3 additions & 3 deletions MoviesHub/Views/Movies/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Revenue" class="control-label"></label>
<input asp-for="Revenue" class="form-control" />
<span asp-validation-for="Revenue" class="text-danger"></span>
<label asp-for="Price" class="control-label"></label>
<input asp-for="Price" class="form-control" />
<span asp-validation-for="Price" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="PosterUrl" class="control-label"></label>
Expand Down
8 changes: 4 additions & 4 deletions MoviesHub/Views/Movies/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Revenue)
@Html.DisplayNameFor(model => model.Price)
</th>
<th>
@Html.DisplayNameFor(model => model.PosterUrl)
Expand Down Expand Up @@ -46,7 +46,7 @@
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Revenue)
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.DisplayFor(modelItem => item.PosterUrl)
Expand All @@ -67,9 +67,9 @@
@Html.DisplayFor(modelItem => item.ContentRating.ShortDescription)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.MovieId">Edit</a> |
@*<a asp-action="Edit" asp-route-id="@item.MovieId">Edit</a> |
<a asp-action="Details" asp-route-id="@item.MovieId">Details</a> |
<a asp-action="Delete" asp-route-id="@item.MovieId">Delete</a>
<a asp-action="Delete" asp-route-id="@item.MovieId">Delete</a>*@
</td>
</tr>
}
Expand Down
6 changes: 3 additions & 3 deletions MoviesHub/Views/MoviesNew/Create.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Revenue" class="control-label"></label>
<input asp-for="Revenue" class="form-control" />
<span asp-validation-for="Revenue" class="text-danger"></span>
<label asp-for="Price" class="control-label"></label>
<input asp-for="Price" class="form-control" />
<span asp-validation-for="Price" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="PosterUrl" class="control-label"></label>
Expand Down
Loading

0 comments on commit e737aea

Please sign in to comment.