2016-10-21 05:46:30 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Microsoft.eShopOnContainers.WebMVC.Services;
|
|
|
|
using Microsoft.eShopOnContainers.WebMVC.Models;
|
2016-10-31 17:56:24 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2016-11-02 20:41:12 +01:00
|
|
|
using Microsoft.eShopOnContainers.WebMVC.Models.OrderViewModels;
|
2016-10-21 05:46:30 +02:00
|
|
|
|
|
|
|
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
|
|
|
{
|
2016-10-31 17:56:24 +01:00
|
|
|
[Authorize]
|
2016-10-21 05:46:30 +02:00
|
|
|
public class OrderController : Controller
|
|
|
|
{
|
|
|
|
private IOrderingService _orderSvc;
|
2016-11-02 20:41:12 +01:00
|
|
|
private IBasketService _basketSvc;
|
2016-10-31 17:56:24 +01:00
|
|
|
private readonly UserManager<ApplicationUser> _userManager;
|
2016-11-02 20:41:12 +01:00
|
|
|
public OrderController(IOrderingService orderSvc, IBasketService basketSvc, UserManager<ApplicationUser> userManager)
|
2016-10-21 05:46:30 +02:00
|
|
|
{
|
2016-10-31 17:56:24 +01:00
|
|
|
_userManager = userManager;
|
2016-10-21 05:46:30 +02:00
|
|
|
_orderSvc = orderSvc;
|
2016-11-02 20:41:12 +01:00
|
|
|
_basketSvc = basketSvc;
|
2016-10-21 05:46:30 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 20:41:12 +01:00
|
|
|
public async Task<IActionResult> Create()
|
2016-10-31 09:25:47 +01:00
|
|
|
{
|
2016-11-02 20:41:12 +01:00
|
|
|
var vm = new CreateOrderViewModel();
|
2016-10-31 17:56:24 +01:00
|
|
|
var user = await _userManager.GetUserAsync(HttpContext.User);
|
2016-11-02 20:41:12 +01:00
|
|
|
var basket = _basketSvc.GetBasket(user);
|
|
|
|
var order = _basketSvc.MapBasketToOrder(basket);
|
|
|
|
vm.Order = order;
|
|
|
|
|
|
|
|
return View(vm);
|
2016-10-21 05:46:30 +02:00
|
|
|
}
|
|
|
|
|
2016-10-31 17:56:24 +01:00
|
|
|
public async Task<IActionResult> Index(Order item)
|
2016-10-21 05:46:30 +02:00
|
|
|
{
|
2016-10-31 17:56:24 +01:00
|
|
|
var user = await _userManager.GetUserAsync(HttpContext.User);
|
|
|
|
return View(_orderSvc.GetMyOrders(user));
|
2016-10-21 05:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|