Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class OrderRecord
- {
- public virtual int Id { get; set; }
- public virtual int CustomerId { get; set; }
- public virtual DateTime CreatedAt { get; set; }
- public virtual decimal SubTotal { get; set; }
- public virtual decimal Vat { get; set; }
- public virtual OrderStatus Status { get; set; }
- public virtual IList<OrderDetailRecord> Details { get; private set; }
- public virtual string PaymentServiceProviderResponse { get; set; }
- public virtual string PaymentReference { get; set; }
- public virtual DateTime? PaidAt { get; set; }
- public virtual DateTime? CompletedAt { get; set; }
- public virtual DateTime? CancelledAt { get; set; }
- public virtual decimal Total
- {
- get { return SubTotal + Vat; }
- private set { }
- }
- public virtual string Number
- {
- get { return (Id + 1000).ToString(CultureInfo.InvariantCulture); }
- private set { }
- }
- public OrderRecord()
- {
- Details = new List<OrderDetailRecord>();
- }
- public virtual void UpdateTotals()
- {
- var subTotal = 0m;
- var vat = 0m;
- foreach (var detail in Details)
- {
- subTotal += detail.SubTotal;
- vat += detail.Vat;
- }
- SubTotal = subTotal;
- Vat = vat;
- }
- SchemaBuilder.CreateTable("OrderRecord", t => t
- .Column<int>("Id", c => c.PrimaryKey().Identity())
- .Column<int>("CustomerId", c => c.NotNull())
- .Column<DateTime>("CreatedAt", c => c.NotNull())
- .Column<decimal>("SubTotal", c => c.NotNull())
- .Column<decimal>("Vat", c => c.NotNull())
- .Column<string>("Status", c => c.WithLength(50).NotNull())
- .Column<string>("PaymentServiceProviderResponse", c => c.WithLength(null))
- .Column<string>("PaymentReference", c => c.WithLength(50))
- .Column<DateTime>("PaidAt", c => c.Nullable())
- .Column<DateTime>("CompletedAt", c => c.Nullable())
- .Column<DateTime>("CancelledAt", c => c.Nullable())
- );
- public OrderRecord CreateOrder(int customerId, IEnumerable<ShoppingCartItem> items)
- {
- if (items == null)
- throw new ArgumentNullException("items");
- // Convert to an array to avoid re-running the enumerable
- var itemsArray = items.ToArray();
- if (!itemsArray.Any())
- throw new ArgumentException("Creating an order with 0 items is not supported", "items");
- var order = new OrderRecord
- {
- CreatedAt = _dateTimeService.Now,
- CustomerId = customerId,
- Status = OrderStatus.New
- };
- _orderRepository.Create(order);
Add Comment
Please, Sign In to add comment