Hello everyone,
I have a problem with my Code. Some classes shouldn't be possible to write in propertys but some classes should be able to write and read them.
Problem in detail:
I coded the invoice in the Controller as private set, so i can only set the invoice in this class. that is what i want.
I also want that i can set the properties of the model in the controller, but not in the view.
But if i set the properties not public in the model, i cant set the properties in the controller too.
I have got 4 classes they looks like the model-view-controller:
Models:
namespace payOffice.Model
{
class InvoicePosition
{
public string Name { get; set; }
public double Price { get; set; }
}
}
namespace payOffice.Model
{
class Invoice
{
public List<InvoicePosition> Positions { get; set; }
public string Consumer { get; set; }
public bool Completed { get; set; }
public int InvoiceNumber { get; set; }
public Invoice(string consumer)
{
Consumer = consumer;
}
}
}
Controller:
namespace payOffice.Controller
{
class InvoiceManager
{
public Invoice loadedInvoice {get;private set;}
public InvoiceManager(...){...}
public void addInvoicePosition(...)
{
loadedInvoice.Positions.Add(...);
}
}
}
View:
namespace payOffice.View
{
public partial class MyView : Form
{
InvoiceManager invoiceManager;
public MyView()
{
InitializeComponent();
}
public void addInvoicePosition(...)
{
invoiceManager.addInvoicePosition(...);
invoiceManager.loadedInvoice.Positions.Add(...);
Console.WriteLine(invoiceManager.loadedInvoice.Consumer);
Console.WriteLine(invoiceManager.loadedInvoice.Positions[0].Price);
}
}
}
Did someone have an idea how i can make this possible?