I'm doing a POS software, the client requires the POS to do Cuotes but in separate window, so I dit the main POS window, this have an Audit
object wish stores the information of the actual sale history before the cashier cut so I pass the ref Audit
object to the frmCuotes
so both of the windows are changing the Audit
class POS:Form
{
EFContext db = new EFContext();
//Get the last audit open if doesn't exist make a new one
Audit _audit = getLastAudit(ref db);
private void POS_Load(object sender, EventArg e)
{
frmCuotes cuoteswdw = new frmCuotes(ref _audit, ref db);
cuoteswdw.Show();
}
private void CashierCut()
{
_audit.State = Close;
db.SaveChanges();
_audit = getLastAudit(ref db);
}
//Other more POS operations
}
class frmCuotes:Form
{
Audit _audit;
EFContext db;
public frmCuotes(ref Audit aud, ref EFContext db)
{
this._audit = aud;
this.db = db;
}
private void cmdSaveCuote_Click(object sender, EventArgs e)
{
var cuote = new Cuote();
//fill Cuote object ...
_audit.Cuotes.Add(cuote)
db.SaveChanges();
}
}
class Audit
{
public int Id { get; set; }
public int Id_Company { get; set; }
public int Id_Terminal { get; set; }
public virtual ICollection<Cuotes> Cuotes { get; set; }
public virtual ICollection<Sales> Sales { get; set; }
}
So this works fine when frmCuotes adds new Cuotes, the _audit
in POS get the changes reflected, but when I change _audit
from POS it self i get no changes reflected in frmCuotes, for example when CashierCut()
is executed, new Audit
is created with different Id
in consecuence, but after POS makes this Cashier cut I mention the frmCuotes still have the old Audit.Id
.
Why is the changes reflected in just one way?