//подгружаем данные private void LoadData() { var queryLocation=(from c in context.Locations where c.LocationName==prevLocation select c).FirstOrDefault(); if (queryLocation != null) currentLocation = queryLocation; }
//подтверждение операции private void buttonOK_Click(object sender, EventArgs e) { if (CheckData()) { switch (mode) { case WindowsMode.ADD: currentLocation = new Location(); currentLocation.LocationName = textBoxLocation.Text.Trim(); context.Locations.Add(currentLocation); context.SaveChanges(); break; case WindowsMode.EDIT: currentLocation.LocationName = textBoxLocation.Text.Trim(); context.Entry(currentLocation).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); break; } this.DialogResult = DialogResult.OK; } else { switch (validateInput) { case LocationInputValidate.LocationEmpty: NotifyWarning("Location input is empty!"); break; case LocationInputValidate.LocationNotUnique: NotifyWarning("Location is not unique!"); break; } } }