eShopOnContainers/src/Web/WebMVC/Services/OrderingService.cs

73 lines
2.8 KiB
C#
Raw Normal View History

2016-10-21 05:46:30 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.eShopOnContainers.WebMVC.Models;
2016-10-31 17:56:24 +01:00
using Microsoft.AspNetCore.Http;
2016-10-21 05:46:30 +02:00
namespace Microsoft.eShopOnContainers.WebMVC.Services
{
public class OrderingService : IOrderingService
{
private List<Order> _orders;
2016-10-31 17:56:24 +01:00
private int _itemsInCart;
2016-11-02 20:41:12 +01:00
2016-10-31 17:56:24 +01:00
public int ItemsInCart { get { return _itemsInCart; } }
2016-10-31 09:25:47 +01:00
//var ordersUrl = _settings.OrderingUrl + "/api/ordering/orders";
//var dataString = await _http.GetStringAsync(ordersUrl);
//var items = JsonConvert.DeserializeObject<List<Order>>(dataString);
2016-10-21 05:46:30 +02:00
2016-10-31 17:56:24 +01:00
public OrderingService(IHttpContextAccessor httpContextAccessor)
2016-10-21 05:46:30 +02:00
{
_orders = new List<Order>()
{
new Order()
{
2016-10-31 17:56:24 +01:00
BuyerId = new Guid("ebcbcb4c-b032-4baa-834b-7fd66d37bc95").ToString(),
OrderDate = DateTime.Now,
2016-11-02 20:41:12 +01:00
State = OrderState.InProcess,
2016-10-31 17:56:24 +01:00
OrderItems = new List<OrderItem>()
{
2016-11-02 20:41:12 +01:00
new OrderItem() { UnitPrice = 12, PictureUrl = "https://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt", Quantity = 1, ProductName="Roslyn Red T-Shirt" }
2016-10-31 17:56:24 +01:00
}
},
new Order()
{
BuyerId = new Guid("ebcbcb4c-b032-4baa-834b-7fd66d37bc95").ToString(),
OrderDate = DateTime.Now,
State = OrderState.InProcess,
OrderItems = new List<OrderItem>()
{
2016-11-02 20:41:12 +01:00
new OrderItem() { UnitPrice = 12, PictureUrl = "https://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt", Quantity = 1, ProductName="Roslyn Red T-Shirt" }
2016-10-31 17:56:24 +01:00
}
},
new Order()
{
BuyerId = new Guid("ebcbcb4c-b032-4baa-834b-7fd66d37bc95").ToString(),
OrderDate = DateTime.Now,
2016-11-02 20:41:12 +01:00
State = OrderState.Delivered,
2016-10-21 05:46:30 +02:00
OrderItems = new List<OrderItem>()
{
2016-11-02 20:41:12 +01:00
new OrderItem() { UnitPrice = 12, PictureUrl = "https://fakeimg.pl/370x240/EEEEEE/000/?text=RoslynRedT-Shirt", Quantity = 1, ProductName="Roslyn Red T-Shirt" }
2016-10-21 05:46:30 +02:00
}
}
};
}
2016-10-31 17:56:24 +01:00
public Order GetOrder(ApplicationUser user, Guid Id)
2016-10-21 05:46:30 +02:00
{
2016-10-31 17:56:24 +01:00
return _orders.Where(x => x.BuyerId.Equals(user.Id) && x.Id.Equals(Id)).FirstOrDefault();
2016-10-21 05:46:30 +02:00
}
2016-10-31 17:56:24 +01:00
public List<Order> GetMyOrders(ApplicationUser user)
2016-10-21 05:46:30 +02:00
{
2016-10-31 17:56:24 +01:00
return _orders.Where(x => x.BuyerId.Equals(user.Id)).ToList();
2016-10-21 05:46:30 +02:00
}
2016-11-02 20:41:12 +01:00
public void CreateOrder(Order order)
2016-10-21 05:46:30 +02:00
{
2016-11-02 20:41:12 +01:00
throw new NotImplementedException();
2016-10-21 05:46:30 +02:00
}
}
}