private async void ExtendedEOWClosingEventHandler(object sender, DialogClosingEventArgs eventArgs) { if ((bool)eventArgs.Parameter) { var dc = (eventArgs.Session.Content as Wizards.EditOwnerWizard); //Accept if (dc._ownerLocalCopy == null) { if (!IsValid(dc as DependencyObject) || (string.IsNullOrEmpty(dc.OwnerFirstName) || string.IsNullOrEmpty(dc.OwnerSurname) || string.IsNullOrEmpty(dc.MailAddress))) { eventArgs.Cancel(); return; } //Add new owner var newOwner = new LibDataModel.Owner { OwnerId = Guid.NewGuid(), MailAddress = dc.MailAddress, OwnerFirstName = dc.OwnerFirstName, OwnerSurname = dc.OwnerSurname, IsDeleted = false }; using (var db = new DB.DomenaDBContext()) { db.Owners.Add(newOwner); db.SaveChanges(); } InitializeOwnerList(); SelectedOwnerName = OwnersNames.Where(x => x.OwnerId.Equals(newOwner.OwnerId)).FirstOrDefault(); } else { if (!IsValid(dc as DependencyObject) || (string.IsNullOrEmpty(dc.OwnerFirstName) || string.IsNullOrEmpty(dc.OwnerSurname) || string.IsNullOrEmpty(dc.MailAddress))) { eventArgs.Cancel(); return; } //Edit Owner using (var db = new DB.DomenaDBContext()) { var q = db.Owners.Where(x => x.OwnerId.Equals(dc._ownerLocalCopy.OwnerId)).FirstOrDefault(); q.OwnerFirstName = dc.OwnerFirstName; q.OwnerSurname = dc.OwnerSurname; q.MailAddress = dc.MailAddress; db.SaveChanges(); } InitializeOwnerList(); SelectedOwnerName = OwnersNames.Where(x => x.OwnerId.Equals(dc._ownerLocalCopy.OwnerId)).FirstOrDefault(); } } else if (!(bool)eventArgs.Parameter) { bool ynResult = await Helpers.YNMsg.Show("Czy chcesz anulować?"); if (!ynResult) { //eventArgs.Cancel(); var dc = (eventArgs.Session.Content as Wizards.EditOwnerWizard); var result = await DialogHost.Show(dc, "HelperDialog", ExtendedEOWOpenedEventHandler, ExtendedEOWClosingEventHandler); } } }
private void SaveDialog(object param) { //Accept if (this._ownerLocalCopy == null) { if (!IsValid(this as DependencyObject) || (string.IsNullOrEmpty(this.OwnerFirstName) || string.IsNullOrEmpty(this.OwnerSurname) || string.IsNullOrEmpty(this.MailAddress))) { return; } //Add new owner using (var db = new DB.DomenaDBContext()) { var newOwner = new LibDataModel.Owner { OwnerId = Guid.NewGuid(), MailAddress = this.MailAddress, OwnerFirstName = this.OwnerFirstName, OwnerSurname = this.OwnerSurname, IsDeleted = false }; db.Owners.Add(newOwner); db.SaveChanges(); } } else { if (!IsValid(this as DependencyObject) || (string.IsNullOrEmpty(this.OwnerFirstName) || string.IsNullOrEmpty(this.OwnerSurname) || string.IsNullOrEmpty(this.MailAddress))) { return; } //Edit Owner using (var db = new DB.DomenaDBContext()) { var q = db.Owners.Where(x => x.OwnerId.Equals(this._ownerLocalCopy.OwnerId)).FirstOrDefault(); q.OwnerFirstName = this.OwnerFirstName; q.OwnerSurname = this.OwnerSurname; q.MailAddress = this.MailAddress; db.SaveChanges(); } } }