React to MVC model binding changes and fix build break
This commit is contained in:
parent
e0c5e6c2fb
commit
52e2784f82
|
|
@ -152,7 +152,7 @@ namespace MusicStore.Areas.Admin.Controllers
|
||||||
DbContext.Update(album);
|
DbContext.Update(album);
|
||||||
await DbContext.SaveChangesAsync(requestAborted);
|
await DbContext.SaveChangesAsync(requestAborted);
|
||||||
//Invalidate the cache entry as it is modified
|
//Invalidate the cache entry as it is modified
|
||||||
Cache.Remove(GetCacheKey(album.AlbumId));
|
Cache.Remove(GetCacheKey(album.AlbumId.Value));
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace MusicStore.Controllers
|
||||||
|
|
||||||
// This doesn't count login failures towards account lockout
|
// This doesn't count login failures towards account lockout
|
||||||
// To enable password failures to trigger account lockout, change to lockoutOnFailure: true
|
// To enable password failures to trigger account lockout, change to lockoutOnFailure: true
|
||||||
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure: false);
|
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe ?? false , lockoutOnFailure: false);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
return RedirectToLocal(returnUrl);
|
return RedirectToLocal(returnUrl);
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace MusicStore.Models
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
|
||||||
[Display(Name = "Remember me?")]
|
[Display(Name = "Remember me?")]
|
||||||
public bool RememberMe { get; set; }
|
public bool? RememberMe { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RegisterViewModel
|
public class RegisterViewModel
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace MusicStore.Models
|
||||||
public class Album
|
public class Album
|
||||||
{
|
{
|
||||||
[ScaffoldColumn(false)]
|
[ScaffoldColumn(false)]
|
||||||
public int AlbumId { get; set; }
|
public int? AlbumId { get; set; }
|
||||||
|
|
||||||
public int GenreId { get; set; }
|
public int GenreId { get; set; }
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ namespace MusicStore.Models
|
||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TODO: Temporary hack to populate the orderdetails until EF does this automatically.
|
/// TODO: Temporary hack to populate the orderdetails until EF does this automatically.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Album()
|
public Album()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace MusicStore.Models
|
||||||
// Create a new cart item if no cart item exists
|
// Create a new cart item if no cart item exists
|
||||||
cartItem = new CartItem
|
cartItem = new CartItem
|
||||||
{
|
{
|
||||||
AlbumId = album.AlbumId,
|
AlbumId = album.AlbumId.Value,
|
||||||
CartId = ShoppingCartId,
|
CartId = ShoppingCartId,
|
||||||
Count = 1,
|
Count = 1,
|
||||||
DateCreated = DateTime.Now
|
DateCreated = DateTime.Now
|
||||||
|
|
@ -100,7 +100,7 @@ namespace MusicStore.Models
|
||||||
|
|
||||||
public async Task<decimal> GetTotal()
|
public async Task<decimal> GetTotal()
|
||||||
{
|
{
|
||||||
// Multiply album price by count of that album to get
|
// Multiply album price by count of that album to get
|
||||||
// the current price for each of those albums in the cart
|
// the current price for each of those albums in the cart
|
||||||
// sum all album price totals to get the cart total
|
// sum all album price totals to get the cart total
|
||||||
|
|
||||||
|
|
@ -154,7 +154,7 @@ namespace MusicStore.Models
|
||||||
|
|
||||||
if (cartId == null)
|
if (cartId == null)
|
||||||
{
|
{
|
||||||
//A GUID to hold the cartId.
|
//A GUID to hold the cartId.
|
||||||
cartId = Guid.NewGuid().ToString();
|
cartId = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
// Send cart Id as a cookie to the client.
|
// Send cart Id as a cookie to the client.
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace MvcMusicStore.Models
|
namespace MvcMusicStore.Models
|
||||||
{
|
{
|
||||||
public class Album {
|
public class Album {
|
||||||
[ScaffoldColumn(false)]
|
[ScaffoldColumn(false)]
|
||||||
|
|
||||||
public int AlbumId { get; set; }
|
public int? AlbumId { get; set; }
|
||||||
|
|
||||||
public int GenreId { get; set; }
|
public int GenreId { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ namespace MvcMusicStore.Models
|
||||||
}
|
}
|
||||||
|
|
||||||
[ScaffoldColumn(false)]
|
[ScaffoldColumn(false)]
|
||||||
public int OrderId { get; set; }
|
public int? OrderId { get; set; }
|
||||||
|
|
||||||
[ScaffoldColumn(false)]
|
[ScaffoldColumn(false)]
|
||||||
public System.DateTime OrderDate { get; set; }
|
public System.DateTime? OrderDate { get; set; }
|
||||||
|
|
||||||
[ScaffoldColumn(false)]
|
[ScaffoldColumn(false)]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
|
@ -66,7 +66,7 @@ namespace MvcMusicStore.Models
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|
||||||
[ScaffoldColumn(false)]
|
[ScaffoldColumn(false)]
|
||||||
public decimal Total { get; set; }
|
public decimal? Total { get; set; }
|
||||||
|
|
||||||
public List<OrderDetail> OrderDetails { get; set; }
|
public List<OrderDetail> OrderDetails { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,13 @@ namespace MvcMusicStore.Models
|
||||||
|
|
||||||
public async Task AddToCart(Album album)
|
public async Task AddToCart(Album album)
|
||||||
{
|
{
|
||||||
var cartItem = await GetCartItem(album.AlbumId);
|
var cartItem = await GetCartItem(album.AlbumId.Value);
|
||||||
|
|
||||||
if (cartItem == null)
|
if (cartItem == null)
|
||||||
{
|
{
|
||||||
cartItem = new Cart
|
cartItem = new Cart
|
||||||
{
|
{
|
||||||
AlbumId = album.AlbumId,
|
AlbumId = album.AlbumId.Value,
|
||||||
CartId = _cartId,
|
CartId = _cartId,
|
||||||
Count = 1,
|
Count = 1,
|
||||||
DateCreated = DateTime.Now
|
DateCreated = DateTime.Now
|
||||||
|
|
@ -119,7 +119,7 @@ namespace MvcMusicStore.Models
|
||||||
order.OrderDetails.Add(new OrderDetail
|
order.OrderDetails.Add(new OrderDetail
|
||||||
{
|
{
|
||||||
AlbumId = item.AlbumId,
|
AlbumId = item.AlbumId,
|
||||||
OrderId = order.OrderId,
|
OrderId = order.OrderId.Value,
|
||||||
UnitPrice = item.Album.Price,
|
UnitPrice = item.Album.Price,
|
||||||
Quantity = item.Count,
|
Quantity = item.Count,
|
||||||
});
|
});
|
||||||
|
|
@ -131,7 +131,7 @@ namespace MvcMusicStore.Models
|
||||||
|
|
||||||
await EmptyCart();
|
await EmptyCart();
|
||||||
|
|
||||||
return order.OrderId;
|
return order.OrderId.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task EmptyCart()
|
private async Task EmptyCart()
|
||||||
|
|
@ -142,7 +142,7 @@ namespace MvcMusicStore.Models
|
||||||
_storeContext.Carts.Remove(cartItem);
|
_storeContext.Carts.Remove(cartItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task MigrateCart(string userName)
|
public async Task MigrateCart(string userName)
|
||||||
{
|
{
|
||||||
var carts = await _storeContext.Carts.Where(c => c.CartId == _cartId).ToListAsync();
|
var carts = await _storeContext.Carts.Where(c => c.CartId == _cartId).ToListAsync();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue