Fixing compilation errors in the view components.

Marked one of the controller actions with [HttpGet] to prevent it being chosen for non get methods.
This commit is contained in:
Praburaj 2014-05-01 13:06:13 -07:00
parent 306513a844
commit 10a280580c
3 changed files with 24 additions and 10 deletions

View File

@ -1,8 +1,7 @@
using System;
using Microsoft.AspNet.Mvc;
using MusicStore.Models;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using MusicStore.Models;
namespace MusicStore.Components
{
@ -18,16 +17,23 @@ namespace MusicStore.Components
public async Task<IViewComponentResult> InvokeAsync()
{
var cart = ShoppingCart.GetCart(db, this.Context);
var cartItems = cart.GetCartItems()
.Select(a => a.Album.Title)
.OrderBy(x => x);
var cartItems = await GetCartItems();
ViewBag.CartCount = cartItems.Count();
ViewBag.CartSummary = string.Join("\n", cartItems.Distinct());
return View();
}
private Task<IOrderedEnumerable<string>> GetCartItems()
{
var cart = ShoppingCart.GetCart(db, this.Context);
var cartItems = cart.GetCartItems()
.Select(a => a.Album.Title)
.OrderBy(x => x);
return Task.FromResult(cartItems);
}
}
}

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using MusicStore.Models;
using System.Collections.Generic;
namespace MusicStore.Components
{
@ -17,6 +18,13 @@ namespace MusicStore.Components
}
public async Task<IViewComponentResult> InvokeAsync()
{
var genres = await GetGenres();
return View(genres);
}
private Task<List<Genre>> GetGenres()
{
// TODO [EF] We don't query related data as yet, so the OrderByDescending isn't doing anything
//var genres = db.Genres
@ -28,8 +36,7 @@ namespace MusicStore.Components
//.ToList();
var genres = db.Genres.ToList();
return View(genres);
return Task.FromResult(genres);
}
}
}

View File

@ -22,6 +22,7 @@ namespace MusicStore.Controllers
//
// GET: /Checkout/
[HttpGet]
public IActionResult AddressAndPayment()
{
return View();