Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

React to kpm subcommand renaming #351

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
5b69fb5
Merge pull request #264 from aspnet/release
Oct 21, 2014
a2e005c
Update MusicStore.Spa to latest angular-ui-bootstrap
DamianEdwards Oct 21, 2014
05237d9
MusicStore.Spa fixes:
DamianEdwards Oct 24, 2014
947a3f8
Reacting to EF API renames
ajcvickers Oct 29, 2014
1c3c7a0
Merge branch 'release' into dev
pranavkm Nov 6, 2014
0352ef8
MusicStore.Spa changes:
DamianEdwards Oct 28, 2014
1e2152c
Update kproj files to move artifacts out of project folder
DamianEdwards Nov 10, 2014
88ebb16
Fixed kproj artifacts dir location
DamianEdwards Nov 11, 2014
2970af1
Update KProj to the latest format
Nov 12, 2014
6a4f49a
Fix facebook endpoint tests.
Tratcher Nov 15, 2014
22ad9b9
MusicStore.Spa changes:
DamianEdwards Nov 19, 2014
62e84ae
Make MusicStore.Spa..NoCacheAttribute try *really* hard to prevent ca…
DamianEdwards Nov 19, 2014
dbee8c1
And you get NoCache, and you get NoCache, and you get NoCache
DamianEdwards Nov 19, 2014
f72b23c
Test flakiness - Moving the first request into a retry block
Nov 19, 2014
12858ae
Fixing port number to 5001 as social logins need this port number to …
Nov 20, 2014
5ae536f
Some fixes
Nov 21, 2014
4267d9b
React to hosting changes
HaoK Nov 21, 2014
0d7c284
Disable tests for now
HaoK Nov 21, 2014
0edfde8
Revert "Disable tests for now"
HaoK Nov 21, 2014
3b6e988
Remove use of context.Configuration
ajcvickers Nov 21, 2014
d8041cb
React to identity changes
HaoK Nov 25, 2014
1120863
Add schema version to kproj files
Nov 25, 2014
688771a
Corresponding changes for changing AssociatedMetadataProvider's inter…
harshgMSFT Nov 27, 2014
681327f
Fixed tests to run on Mono
Dec 2, 2014
e21f605
Using .Include in queries instead of manual joining
Dec 2, 2014
65f58b9
Fixing the test failure
Dec 2, 2014
715b744
React to EF API changes
ajcvickers Dec 2, 2014
2286b14
Add retry logic for Publishtests
Dec 2, 2014
b580856
Updating for EntityFramework API change to DbContext Entry Methods
mikary Dec 4, 2014
a67bd68
Adding some coverage for the .Include EF statements
Dec 4, 2014
4e929bb
Stop setting WebRoot explicitly.
Tratcher Dec 5, 2014
b20b184
Merge remote-tracking branch 'origin/release' into dev
Dec 8, 2014
9214253
Updating to release NuGet.config
Dec 8, 2014
9e9f331
Updating to dev NuGet.config
Dec 8, 2014
9d643ae
Move web.config from project root to wwwroot
ChengTian Dec 10, 2014
6120168
Reacting to the new EF relationship discovery convention
AndriySvyryd Dec 10, 2014
9b72e3a
Reacting to EF API changes
ajcvickers Dec 8, 2014
acc191e
Merge branch 'release' into dev
ChengTian Dec 12, 2014
0c59794
A few changes
Dec 13, 2014
c8323f4
Let VS assign a port for the MVC 6.0 project
dougbu Dec 11, 2014
50b756a
Clean up - removing work arounds for bugs
Dec 15, 2014
4315eb2
Some more fixes
Dec 15, 2014
51f60d5
Enabling native module variations.
Dec 16, 2014
2df9d8f
Update tests to use official xunit
BrennanConroy Dec 16, 2014
368e96a
Fixes teamcity issue with Console.ReadLine()
Dec 17, 2014
b15e1a7
Fixed README typos
Dec 18, 2014
102270d
Merge pull request #309 from stefaanvermassen/patch-2
Dec 19, 2014
9c442e9
Using the latest xunit skip condition attributes to skip tests
Dec 19, 2014
3c49e43
Removing an incorrect test variation.
Dec 19, 2014
68102b8
Enabling IIS variation of the test
Dec 19, 2014
2dae44a
Disabling IIS variation test as CI machine does not have IIS installed.
Dec 19, 2014
e5a92da
Corrected json for mono
Dec 19, 2014
a9ea8a8
Fixing the KRE name issue on mono
Dec 19, 2014
9e62865
Fixing code to pass KRE folder path not including bin
Dec 22, 2014
d9148bd
Fixing KRE_ENV to ASPNET_ENV
Dec 23, 2014
e609602
Clean up and refactoring
Dec 30, 2014
a4d2d18
Fixing tests on mono
Dec 30, 2014
14ec796
React to identity changes
HaoK Dec 30, 2014
6407ff0
Cleanup : Moving the mock code to the test project
Jan 3, 2015
87f895f
Updating path to kvm
Jan 6, 2015
76017af
Handle Form and helpers breaking changes.
Tratcher Jan 8, 2015
56d6dfe
Adding a retry logic for NtlmAuth test
Jan 9, 2015
ce17824
Fixing a test regression
Jan 9, 2015
a6bf0e1
Adding console logger to the sample
Jan 9, 2015
fdfe88f
Using Console logger to print logs instead of using Console.WriteLine
Jan 10, 2015
2df24fd
Creating a helper to retry a piece of code.
Jan 13, 2015
cc38726
LoggerExtensions can take in param objects[] instead of param string[]
Jan 13, 2015
8864111
Increasing wait time out on mono tests
Jan 14, 2015
b46bec1
Increase wait time for server to start
Jan 15, 2015
0f9173e
Adding a Start up class for OpenIdConnect authentication
Jan 15, 2015
c9d0a4d
Reacting to namespace changes PipelineCore => Http.Core
Jan 15, 2015
ad5cfb9
Reacting to namespace changes PipelineCore => Http.Core V2
Jan 15, 2015
ef22f9f
React to MVC/Auth changes
HaoK Jan 16, 2015
f67f577
Fixing build break due to model binding changes
Jan 16, 2015
9e68b43
Adding authorization policy for the missed startup class.
Jan 16, 2015
86ab6b7
Changing an error string in the tests due to identity change.
Jan 16, 2015
cec6370
Reacting to EF changes
AndriySvyryd Jan 15, 2015
4644388
Fix music store policies
HaoK Jan 16, 2015
0e2dfb9
React to kpm subcommand renaming
ChengTian Jan 16, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MusicStore.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22112.0
VisualStudioVersion = 14.0.22230.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{44621553-AA7D-4893-8834-79582A7D8348}"
EndProject
Expand Down
3 changes: 2 additions & 1 deletion NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetrelease/api/v2" />
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
<add key="AzureADNighty" value="http://www.myget.org/F/azureadwebstacknightly"/>
</packageSources>
</configuration>
49 changes: 20 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
# MusicStore application

This project is part of ASP.NET vNext. You can find samples, documentation and getting started instructions for ASP.NET vNext at the [Home](https://github.com/aspnet/home) repo.
This project is part of ASP.NET 5.0. You can find samples, documentation and getting started instructions for ASP.NET 5.0 at the [Home](https://github.com/aspnet/home) repo.

* Clone the repository

### Run the application on Helios:
## Run the application on Helios:
* If you have Visual Studio 2015
1. Open MusicStore.sln in Visual Studio 2015 and run the individual applications on ```Helios```.
1. Open MusicStore.sln in Visual Studio 2015 and run the individual applications on `IIS Express`.
* If you don't have Visual Studio 2015
1. Open a command prompt and cd ```\src\MusicStore\```
2. Execute ``kpm restore```
3. Execute ```Helios.cmd``` to launch the app on IISExpress from command line (Application started at URL **http://localhost:5001/**).
NOTE: App and Tests require Visual Studio 2015 LocalDB on the machine to run. Please change the connection string if you don't have Visual studio 2015 installed.
1. Open a command prompt and cd `\src\MusicStore\`.
2. Execute `kpm restore`.
3. Execute `Helios.cmd` to launch the app on IISExpress from command line (Application started at URL **http://localhost:5001/**).
NOTE: App and tests require Visual Studio 2015 LocalDB on the machine to run.

### Run on WebListener/Kestrel:
* Open a command prompt and cd ```\src\MusicStore\```
## Run on WebListener/Kestrel:
* Open a command prompt and cd `\src\MusicStore\`.
* **[WebListener]:**
4. Run ```k WebListener``` (Application started at URL **http://localhost:5002/**)
4. Run `k web` (Application started at URL **http://localhost:5002/**).
* **[Kestrel]:**
5. Run ```k Kestrel``` (Application started at URL **http://localhost:5004/**)
5. Run `k kestrel` (Application started at URL **http://localhost:5004/**).
* **[CustomHost]:**
6. Run ```k run``` (This hosts the app in a console application - Application started at URL **http://localhost:5003/**)
6. Run `k run` (This hosts the app in a console application - Application started at URL **http://localhost:5003/**).

### To run the sample on Mac/Mono:
* Follow [Home](https://github.com/aspnet/home) instructions to install mono, kvm on Mac
* Open a command prompt and cd ```\src\MusicStore\```
* Execute ``kpm restore```
* Try `k kestrel` to run the application
## To run the sample on Mac/Mono:
* Follow [Home](https://github.com/aspnet/home) instructions to install mono, kvm on Mac.
* Open a command prompt and cd `\src\MusicStore\`.
* Execute `kpm restore`.
* Try `k kestrel` to run the application.
**NOTE: On Mono since SQL client is not available the sample uses an InMemoryStore to run the application. So the changes that you make will not be persisted.

### Run Tests:
* Open a command prompt and cd ```\test\E2ETests\```
* Execute ``kpm restore```
* Set KRE_ENV environment variable to "SocialTesting"
* Run ```k test```

###NTLM authentication
More information at src/MusicStore/StartupNtlmAuthentication.cs
**NOTE: Ntlm authentication works only on desktop CLR right now.
More information at src/MusicStore/StartupNtlmAuthentication.cs.

### Note:
1. Application is started on different ports on different hosts. To change the port or URL modify ```Helios.cmd``` or project.json commands section in case of self-host and customhost.
###OpenIdConnect authentication
More information at src/MusicStore/StartupOpenIdConnect.cs.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if test ! -d packages/KoreBuild; then
fi

if ! type k > /dev/null 2>&1; then
source setup/kvm.sh
source packages/KoreBuild/build/kvm.sh
fi

if ! type k > /dev/null 2>&1; then
Expand Down
121 changes: 88 additions & 33 deletions src/MusicStore.Spa/Apis/AlbumsApiController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Linq;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using MusicStore.Infrastructure;
using MusicStore.Models;
using MusicStore.Spa.Infrastructure;

namespace MusicStore.Apis
{
Expand All @@ -17,17 +19,25 @@ public AlbumsApiController(MusicStoreContext storeContext)
}

[HttpGet]
[NoCache]
public async Task<ActionResult> Paged(int page = 1, int pageSize = 50, string sortBy = null)
{
await _storeContext.Genres.LoadAsync();
await _storeContext.Artists.LoadAsync();

var albums = await _storeContext.Albums
//.Include(a => a.Genre)
//.Include(a => a.Artist)
.ToPagedListAsync(page, pageSize, sortBy, a => a.Title);
.ToPagedListAsync(page, pageSize, sortBy,
a => a.Title, // sortExpression
SortDirection.Ascending, // defaultSortDirection
a => SimpleMapper.Map(a, new AlbumResultDto())); // selector

return Json(albums);
}

[HttpGet("all")]
[NoCache]
public async Task<ActionResult> All()
{
var albums = await _storeContext.Albums
Expand All @@ -36,10 +46,11 @@ public async Task<ActionResult> All()
.OrderBy(a => a.Title)
.ToListAsync();

return Json(albums);
return Json(albums.Select(a => SimpleMapper.Map(a, new AlbumResultDto())));
}

[HttpGet("mostPopular")]
[NoCache]
public async Task<ActionResult> MostPopular(int count = 6)
{
count = count > 0 && count < 20 ? count : 6;
Expand All @@ -48,60 +59,71 @@ public async Task<ActionResult> MostPopular(int count = 6)
.Take(count)
.ToListAsync();

return Json(albums);
// TODO: Move the .Select() to end of albums query when EF supports it
return Json(albums.Select(a => SimpleMapper.Map(a, new AlbumResultDto())));
}

[HttpGet("{albumId:int}")]
[NoCache]
public async Task<ActionResult> Details(int albumId)
{
// TODO: Remove this when EF supports related entity loading
await _storeContext.Artists.ToListAsync();
await _storeContext.Genres.ToListAsync();
await _storeContext.Genres.LoadAsync();
await _storeContext.Artists.LoadAsync();

// TODO: Make async when EF supports SingleOrDefaultAsync
var album = _storeContext.Albums
var album = await _storeContext.Albums
//.Include(a => a.Artist)
//.Include(a => a.Genre)
.SingleOrDefault(a => a.AlbumId == albumId);
.Where(a => a.AlbumId == albumId)
.SingleOrDefaultAsync();

var albumResult = SimpleMapper.Map(album, new AlbumResultDto());

// TODO: Get these from the related entities when EF supports that again, i.e. when .Include() works
//album.Artist.Name = (await _storeContext.Artists.SingleOrDefaultAsync(a => a.ArtistId == album.ArtistId)).Name;
//album.Genre.Name = (await _storeContext.Genres.SingleOrDefaultAsync(g => g.GenreId == album.GenreId)).Name;

// TODO: Add null checking and return 404 in that case

return Json(album);
return Json(albumResult);
}

[HttpPost]
[Authorize("ManageStore", "Allowed")]
public async Task<ActionResult> CreateAlbum()
[Authorize("app-ManageStore")]
public async Task<ActionResult> CreateAlbum([FromBody]AlbumChangeDto album)
{
var album = new Album();

//if (!await TryUpdateModelAsync(album, excludeProperties: new[] { "Genre", "Artist", "OrderDetails" }))
if (!await TryUpdateModelAsync(album))
if (!ModelState.IsValid)
{
// Return the model errors
return new ApiResult(ModelState);
}

// Save the changes to the DB
await _storeContext.Albums.AddAsync(album);
var dbAlbum = new Album();
await _storeContext.Albums.AddAsync(SimpleMapper.Map(album, dbAlbum));
await _storeContext.SaveChangesAsync();

// TODO: Handle missing record, key violations, concurrency issues, etc.

return new ApiResult
{
Data = album.AlbumId,
Data = dbAlbum.AlbumId,
Message = "Album created successfully."
};
}

[HttpPut("{albumId:int}/update")]
[Authorize("ManageStore", "Allowed")]
public async Task<ActionResult> UpdateAlbum(int albumId)
[Authorize("app-ManageStore")]
public async Task<ActionResult> UpdateAlbum(int albumId, [FromBody]AlbumChangeDto album)
{
var album = _storeContext.Albums.SingleOrDefault(a => a.AlbumId == albumId);
if (!ModelState.IsValid)
{
// Return the model errors
return new ApiResult(ModelState);
}

if (album == null)
var dbAlbum = await _storeContext.Albums.SingleOrDefaultAsync(a => a.AlbumId == albumId);

if (dbAlbum == null)
{
return new ApiResult
{
Expand All @@ -110,14 +132,8 @@ public async Task<ActionResult> UpdateAlbum(int albumId)
};
}

//if (!TryUpdateModel(album, prefix: null, includeProperties: null, excludeProperties: new[] { "Genre", "Artist", "OrderDetails" }))
if (!await TryUpdateModelAsync(album))
{
// Return the model errors
return new ApiResult(ModelState);
}

// Save the changes to the DB
SimpleMapper.Map(album, dbAlbum);
await _storeContext.SaveChangesAsync();

// TODO: Handle missing record, key violations, concurrency issues, etc.
Expand All @@ -129,11 +145,11 @@ public async Task<ActionResult> UpdateAlbum(int albumId)
}

[HttpDelete("{albumId:int}")]
[Authorize("ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public async Task<ActionResult> DeleteAlbum(int albumId)
{
//var album = await _storeContext.Albums.SingleOrDefaultAsync(a => a.AlbumId == albumId);
var album = _storeContext.Albums.SingleOrDefault(a => a.AlbumId == albumId);
var album = await _storeContext.Albums.SingleOrDefaultAsync(a => a.AlbumId == albumId);
//var album = _storeContext.Albums.SingleOrDefault(a => a.AlbumId == albumId);

if (album != null)
{
Expand All @@ -150,5 +166,44 @@ public async Task<ActionResult> DeleteAlbum(int albumId)
Message = "Album deleted successfully."
};
}

[BuddyType(typeof(Album))]
public class AlbumChangeDto
{
public int GenreId { get; set; }

public int ArtistId { get; set; }

public string Title { get; set; }

public decimal Price { get; set; }

public string AlbumArtUrl { get; set; }
}

public class AlbumResultDto : AlbumChangeDto
{
public AlbumResultDto()
{
Artist = new ArtistResultDto();
Genre = new GenreResultDto();
}

public int AlbumId { get; set; }

public ArtistResultDto Artist { get; private set; }

public GenreResultDto Genre { get; private set; }
}

public class ArtistResultDto
{
public string Name { get; set; }
}

public class GenreResultDto
{
public string Name { get; set; }
}
}
}
2 changes: 2 additions & 0 deletions src/MusicStore.Spa/Apis/GenresApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using MusicStore.Models;
using MusicStore.Spa.Infrastructure;

namespace MusicStore.Apis
{
Expand Down Expand Up @@ -52,6 +53,7 @@ public async Task<ActionResult> GenreMenuList(int count = 9)
}

[HttpGet("{genreId:int}/albums")]
[NoCache]
public async Task<ActionResult> GenreAlbums(int genreId)
{
var albums = await _storeContext.Albums
Expand Down
25 changes: 13 additions & 12 deletions src/MusicStore.Spa/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid == true)
{
var signInStatus = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
switch (signInStatus)
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
if (result.Succeeded)
{
return RedirectToLocal(returnUrl);
}
if (result.IsLockedOut)
{
ModelState.AddModelError("", "User is locked out, try again later.");
}
else
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
ModelState.AddModelError("", "User is locked out, try again later.");
return View(model);
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid username or password.");
return View(model);
ModelState.AddModelError("", "Invalid username or password.");
return View(model);
}
}

Expand Down Expand Up @@ -138,7 +139,7 @@ private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error);
ModelState.AddModelError("", error.Description);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MusicStore.Spa/Controllers/PageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public IActionResult Home()
}

[HttpGet("admin")]
[Authorize("ManageStore", "Allowed")]
[Authorize("app-ManageStore")]
public IActionResult Admin()
{
return View("/Pages/Admin.cshtml");
Expand Down
Loading