Criei uma classe chamada Order
, e nela criei um field com o propósito de inserir uma data de entrega da order.
Porém criei o objeto no Main()
, e na hora que executo ele preenche com a data default, já fiz o debug mas não sei onde estou errando.
Essa é minha classe Order
:
namespace SergioS_301011342_LIB
{
public class Order
{
private DateTime orderDateMade;
private DateTime orderDateDeli;
private AddressStruct orderAddressDeli;
private decimal cost;
private Customer customer;
private static int orderNumber;
private OrderItem[] orderItems;
private int noOrders;
private const uint MAX_NUMBER_OF_ORDERS = 50;
public Order()
{
orderItems = new OrderItem[MAX_NUMBER_OF_ORDERS];
noOrders = 0;
orderNumber += 1;
orderDateDeli = new DateTime();
}
public Customer Customer
{
get { return customer; }
set { customer = value; }
}
public OrderItem[] OrderItems
{
get { return orderItems; }
set { orderItems = value; }
}
public int OrderId
{
get { return orderNumber; }
}
public DateTime OrderDateMade
{
get { return orderDateMade; }
set { orderDateMade = DateTime.Now; }
}
public DateTime OrderDateDeli
{
get { return orderDateDeli; }
set { orderDateMade = DateTime.Today; }
}
public AddressStruct OrderAddressDeli
{
get { return orderAddressDeli; }
set {orderAddressDeli = value; }
}
public decimal Cost
{
get { return cost; }
set { cost = value; }
}
public void AddOrderItem(OrderItem orderItem)
{
orderItems[noOrders++] = orderItem;//verify if the array is not full before save it.
Cost += orderItem.MenuItem.MenuBaseCost;
}
public string GetInfo()
{
string result = string.Empty;
result += "\n\t\t\t\t\tId Order : " + orderNumber + "\n";
result += "========================================================================================";
result += "\nDate of the order: " + this.OrderDateMade.ToString();
result += "\t\tDate of the delivery: " + orderDateDeli.ToString();
result += "\nDelivery Address: " + this.orderAddressDeli.streetNumber + ", ";
result += this.orderAddressDeli.streetName + ", " + this.orderAddressDeli.city + "-";
result += this.orderAddressDeli.province + "\n";
result += "Orders: \n";
foreach (OrderItem item in this.orderItems)
{
if (item == null)break;
result += item.GetInfo();
}
result += "\n========================================================================================";
result += "\nCost total of the order: " + this.Cost.ToString("C2");
result += "\n========================================================================================";
return result;
}
}
}
Esse é o Main
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SergioS_301011342_LIB;
namespace SergioS_301011342_A1
{
class Program
{
static void Main(string[] args)
{
OrderItem orderItem = new OrderItem(new MenuItem()
{
MenuName = "Hot Coffee",
MenuDescription = "Dark Coffee with 2 milks and 2 creams",
MenuBaseCost = 3.5M,
});
OrderItem orderItem2 = new OrderItem(new MenuItem()
{
MenuName = "Milk",
MenuDescription = "Hot Milk",
MenuBaseCost = 2.5M,
});
Customer customer1 = new Customer();
customer1.Name = "Richard Silva";
customer1.PhoneNumber = "6471231212";
var address = new AddressStruct()
{
streetNumber = 1600,
streetName = "Progress Avenue",
city = "Toronto",
province = "ON",
};
customer1.Address = address;
var addressDelivery = new AddressStruct()
{
streetNumber = 890,
streetName = "Keele Street",
city = "Toronto",
province = "ON",
};
var order = new Order();
order.OrderAddressDeli = addressDelivery;
order.AddOrderItem(orderItem);order.OrderItems[0] = orderItem;
order.AddOrderItem(orderItem2);order.OrderItems[1] = orderItem2;
customer1.Orders[0] = order;
order.OrderDateMade = new DateTime();
order.OrderDateDeli = new DateTime();
Console.WriteLine(customer1.GetInfo());
Console.ReadLine();
}