General clean up to the musicstore app

1. Removed many unncessary comments
2. Added comments to Startup.cs
3. Fixed some code comments across the app
4. Renamed Config.json -> LocalConfig.json to reflect the scenario
This commit is contained in:
Praburaj 2014-05-01 15:32:21 -07:00
parent 10a280580c
commit 3ae8b93e26
28 changed files with 79 additions and 64 deletions

View File

@ -39,6 +39,7 @@ namespace MusicStore.Controllers
//
// GET: /Account/Login
[AllowAnonymous]
//Bug: https://github.com/aspnet/WebFx/issues/339
[HttpGet]
public IActionResult Login(string returnUrl)
{
@ -77,7 +78,8 @@ namespace MusicStore.Controllers
//
// GET: /Account/Register
[AllowAnonymous]
[HttpGet] //TODO: Do we need this. Without this I seem to be landing here irrespective of the HTTP verb?
//Bug: https://github.com/aspnet/WebFx/issues/339
[HttpGet]
public IActionResult Register()
{
return View();
@ -90,7 +92,7 @@ namespace MusicStore.Controllers
//[ValidateAntiForgeryToken]
public async Task<IActionResult> Register(RegisterViewModel model)
{
//Bug: https://github.com/aspnet/DataAnnotations/issues/21
//Bug: https://github.com/aspnet/WebFx/issues/247
//if (ModelState.IsValid == true)
{
var user = new ApplicationUser() { UserName = model.UserName };
@ -112,6 +114,7 @@ namespace MusicStore.Controllers
//
// GET: /Account/Manage
//Bug: https://github.com/aspnet/WebFx/issues/339
[HttpGet]
public async Task<IActionResult> Manage(ManageMessageId? message)
{
@ -130,7 +133,7 @@ namespace MusicStore.Controllers
public async Task<IActionResult> Manage(ManageUserViewModel model)
{
ViewBag.ReturnUrl = Url.Action("Manage");
//Bug: https://github.com/aspnet/DataAnnotations/issues/21
//Bug: https://github.com/aspnet/WebFx/issues/247
//if (ModelState.IsValid == true)
{
var user = await GetCurrentUserAsync();

View File

@ -22,6 +22,7 @@ namespace MusicStore.Controllers
//
// GET: /Checkout/
//Bug: https://github.com/aspnet/WebFx/issues/339
[HttpGet]
public IActionResult AddressAndPayment()
{
@ -31,9 +32,7 @@ namespace MusicStore.Controllers
//
// POST: /Checkout/AddressAndPayment
//Bug: Using direct model binding until we have TryUpdateModel available.
[HttpPost]
//public IActionResult AddressAndPayment(FormCollection values)
public async Task<IActionResult> AddressAndPayment(Order order)
{
var formCollection = await Context.Request.GetFormAsync();

View File

@ -42,8 +42,6 @@ namespace MusicStore.Controllers
if (album == null)
{
//Bug: Need method HttpNotFound() on Controller
//return HttpNotFound();
return new HttpStatusCodeResult(404);
}
@ -90,8 +88,6 @@ namespace MusicStore.Controllers
if (album == null)
{
//Bug: Need method HttpNotFound() on Controller
//return HttpNotFound();
return new HttpStatusCodeResult(404);
}
ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
@ -118,13 +114,13 @@ namespace MusicStore.Controllers
//
// GET: /StoreManager/Delete/5
//Bug: https://github.com/aspnet/WebFx/issues/339
[HttpGet]
public IActionResult Delete(int id = 0)
{
Album album = db.Albums.Single(a => a.AlbumId == id);
if (album == null)
{
//Bug: Missing Helper
return new HttpStatusCodeResult(404);
}
return View(album);

View File

@ -3,6 +3,9 @@ using System.Runtime.Versioning;
namespace Microsoft.Net.Runtime
{
/// <summary>
/// Service provided by the host containing application environment details.
/// </summary>
[AssemblyNeutral]
public interface IApplicationEnvironment
{

View File

@ -31,7 +31,7 @@ namespace MusicStore.Models
public virtual List<OrderDetail> OrderDetails { get; set; }
/// <summary>
/// Bug: We use this to populate the order details. This should be removed once we have an actual DB with EF.
/// TODO: Temporary hack to populate the orderdetails until EF does this automatically.
/// </summary>
public Album()
{

View File

@ -16,12 +16,4 @@ namespace MusicStore.Models
public class ApplicationUser : IdentityUser
{
}
//public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
//{
// public ApplicationDbContext()
// : base("DefaultConnection")
// {
// }
//}
}

View File

@ -23,13 +23,6 @@ namespace MusicStore.Models
return cart;
}
//TODO: Not used by anyone. Not sure why we have this.
// Helper method to simplify shopping cart calls
//public static ShoppingCart GetCart(MusicStoreEntities db, Controller controller)
//{
// return GetCart(db, controller.HttpContext);
//}
public void AddToCart(Album album)
{
// Get the matching cart and album instances
@ -160,7 +153,6 @@ namespace MusicStore.Models
// Iterate over the items in the cart, adding the order details for each
foreach (var item in cartItems)
{
//Bug: Missing EF
//var album = _db.Albums.Find(item.AlbumId);
var album = _db.Albums.Single(a => a.AlbumId == item.AlbumId);

View File

@ -8,6 +8,10 @@ using System.Threading.Tasks;
namespace MusicStore
{
/// <summary>
/// This demonstrates how the application can be launched in a K console application.
/// k run command in the application folder will invoke this.
/// </summary>
public class Program
{
private readonly IServiceProvider _hostServiceProvider;
@ -19,7 +23,7 @@ namespace MusicStore
public Task<int> Main(string[] args)
{
//Add command line to the configuration source to read command line parameters.
//Add command line configuration source to read command line parameters.
var config = new Configuration();
config.AddCommandLine(args);

View File

@ -31,26 +31,43 @@ public class Startup
{
app.UseServices(services =>
{
//Add configuration as a service
/* Adding IConfiguration as a service in the IoC to avoid instantiating Configuration again.
* Below code demonstrates usage of multiple configuration sources. For instance a setting say 'setting1' is found in both the registered sources,
* then the later source will win. By this way a Local config can be overridden by a different setting while deployed remotely.
*/
var applicationEnvironment = app.ApplicationServices.GetService<IApplicationEnvironment>();
var configuration = new Configuration();
configuration.AddJsonFile(Path.Combine(applicationEnvironment.ApplicationBasePath, "Config.json"));
configuration.AddEnvironmentVariables(); //If configuration flows through environment we should pick that first
configuration.AddJsonFile(Path.Combine(applicationEnvironment.ApplicationBasePath, "LocalConfig.json"));
configuration.AddEnvironmentVariables(); //All environment variables in the process's context flow in as configuration values.
services.AddInstance<IConfiguration>(configuration);
//Bug: https://github.com/aspnet/Hosting/issues/20
services.AddInstance<ILoggerFactory>(new NullLoggerFactory());
//Add all MVC related services to IoC.
services.AddMvc();
/*Add all EF related services to IoC.
Using an InMemoryStore in K until SQL server is available.*/
#if NET45
services.AddEntityFramework(s => s.AddSqlServer());
#else
services.AddEntityFramework(s => s.AddInMemoryStore());
#endif
services.AddTransient<MusicStoreContext, MusicStoreContext>();
// File an issue trying to use IdentityUser/IdentityRole and open generic UserManager<>
/*
* Add all Identity related services to IoC.
* Using an InMemory store to store membership data until SQL server is available.
* Users created will be lost on application shutdown.
*/
//Bug: https://github.com/aspnet/Identity/issues/50
services.AddIdentity<ApplicationUser, IdentityRole>(s =>
{
// Turn off password defaults since register error display blows up
s.UsePasswordValidator(() => new PasswordValidator());
s.UsePasswordValidator(() => new PasswordValidator());
//s.UseDbContext(() => context);
//s.UseUserStore(() => new UserStore(context));
@ -61,9 +78,12 @@ public class Startup
});
});
//ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
/* Error page middleware displays a nice formatted HTML page for any unhandled exceptions in the request pipeline.
* Note: ErrorPageOptions.ShowAll to be used only at development time. Not recommended for production.
*/
app.UseErrorPage(ErrorPageOptions.ShowAll);
//Serves static files in the application.
app.UseFileServer();
app.UseCookieAuthentication(new CookieAuthenticationOptions()
@ -81,15 +101,23 @@ public class Startup
app.UseMvc(routes =>
{
routes.MapRoute(
null,
null,
"{controller}/{action}",
new { controller = "Home", action = "Index" });
});
//Populates the MusicStore sample data
SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait();
//Creates a Store manager user who can manage the store.
CreateAdminUser(app.ApplicationServices).Wait();
}
/// <summary>
/// Creates a store manager user who can manage the inventory.
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
private async Task CreateAdminUser(IServiceProvider serviceProvider)
{
var configuration = serviceProvider.GetService<IConfiguration>();

View File

@ -1,7 +1,7 @@
@model MusicStore.Models.LoginViewModel
@{
//Bug: Need a way to specify the layout page in a single place
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Log in";
}
@ -51,7 +51,7 @@
</div>
</div>
@section Scripts {
@*Bug : Script helpers are out of scope for alpha*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Scripts.Render("~/bundles/jqueryval")*@
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>

View File

@ -1,5 +1,5 @@
@{
//Bug: Need a way to specify the layout page in a single place
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Manage Account";
}
@ -14,7 +14,7 @@
</div>
@section Scripts {
@*Bug : Script helpers are out of scope for alpha*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Scripts.Render("~/bundles/jqueryval")*@
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>

View File

@ -1,6 +1,6 @@
@model MusicStore.Models.RegisterViewModel
@{
//Bug: Need a way to specify the layout page in a single place
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Register";
}
@ -39,7 +39,7 @@
}
@section Scripts {
@*Bug : Script helpers are out of scope for alpha*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Scripts.Render("~/bundles/jqueryval")*@
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>

View File

@ -8,7 +8,7 @@
@Html.AntiForgeryToken()
<h4>Change Password Form</h4>
<hr />
@*@Html.ValidationSummary()*@
@Html.ValidationSummary()
<div class="form-group">
@Html.LabelFor(m => m.OldPassword, new { @class = "col-md-2 control-label" })
<div class="col-md-10">

View File

@ -1,13 +1,13 @@
@model MusicStore.Models.Order
@{
//Bug: Need a way to specify the layout page in a single place
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Address And Payment";
}
@section Scripts {
@*Bug : Script helpers are out of scope for alpha*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Scripts.Render("~/bundles/jqueryval")*@
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>

View File

@ -1,7 +1,7 @@
@model int
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Checkout Complete";
}

View File

@ -1,5 +1,5 @@
@{
//Bug: Need a way to specify the layout page in a single place
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Home Page";
}

View File

@ -1,5 +1,5 @@
@{
//Bug: Need a way to specify the layout page in a single place
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Error";
}

View File

@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title MVC Music Store</title>
@*Bug: No Style and Script helpers yet. Manually including the script files*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")*@
<link rel="stylesheet" href="~/Content/bootstrap.min.css" />
@ -42,7 +42,7 @@
</footer>
</div>
@*Bug: No script helpers yet*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")*@
<script src="~/Scripts/jquery-1.10.2.js"></script>

View File

@ -1,6 +1,6 @@
@model MusicStore.ViewModels.ShoppingCartViewModel
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Shopping Cart";
}

View File

@ -1,6 +1,6 @@
@model MusicStore.Models.Genre
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Browse Albums";
}

View File

@ -1,7 +1,7 @@
@model MusicStore.Models.Album
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Album - " + Model.Title;
}

View File

@ -1,6 +1,6 @@
@model IEnumerable<MusicStore.Models.Genre>
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Store";
}

View File

@ -1,8 +1,7 @@
@*Bug: Fully dependent on HTML helpers*@
@model MusicStore.Models.Album
@model MusicStore.Models.Album
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Create";
}
@ -71,7 +70,7 @@
</div>
@section Scripts {
@*Bug : Script helpers are out of scope for alpha*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Scripts.Render("~/bundles/jqueryval")*@
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>

View File

@ -1,8 +1,7 @@
@*Bug: Dependent on Htmlhelpers*@
@model MusicStore.Models.Album
@model MusicStore.Models.Album
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Delete";
}

View File

@ -1,7 +1,7 @@
@model MusicStore.Models.Album
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Details";
}

View File

@ -1,7 +1,7 @@
@model MusicStore.Models.Album
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Edit";
}
@ -71,7 +71,7 @@
</div>
@section Scripts {
@*Bug : Script helpers are out of scope for alpha*@
@*TODO : Until script helpers are available, adding script references manually*@
@*@Scripts.Render("~/bundles/jqueryval")*@
<script src="@Url.Content("~/Scripts/jquery.validate.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")"></script>

View File

@ -13,7 +13,7 @@
}
@{
//Bug: Need to have a way to specify an application level layout page
//TODO: Until we have a way to specify the layout page at application level.
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Index";
}