private bool InitSave() { bool ok = false; List <ReasonExt> toSaveList = new List <ReasonExt>(); List <ReasonExt> toUpdateList = new List <ReasonExt>(); foreach (var rsn in Reasons.ToList()) { if (rsn.ID == 0 && !string.IsNullOrEmpty(rsn.ReasonDesc)) { toSaveList.Add(rsn); } else if (rsn.ID != 0) { toUpdateList.Add(rsn); } } try { List <Reason> addObj = Add(toSaveList); if (addObj.Count() > 0) { ok = ReasonServices.Save(addObj, "Save"); } List <Reason> updateObj = Update(toUpdateList); if (updateObj.Count() > 0) { ok = ReasonServices.Save(updateObj, "Update"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Notification", MessageBoxButton.OK); } return(ok); }
private void Save(object ignored) { SendState = SavingStateKey; var data = this.ReasonData; try { var reason = ReasonServices.GetReason(data.ID); if (reason != null) { reason.ReasonDesc = ReasonDescAlias; reason.ModifiedOn = DateTime.Now; reason.ModifiedBy = AuthenticatedUser; } else { reason = new Reason(); reason.ReasonDesc = ReasonDescAlias; reason.CreatedOn = DateTime.Now; reason.CreatedBy = AuthenticatedUser; reason.ModifiedOn = DateTime.Now; reason.ModifiedBy = AuthenticatedUser; } if (ReasonServices.Save(reason)) { this.SendState = SavedStateKey; if (this.navigationJournal != null) { this.navigationJournal.GoBack(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Notification", MessageBoxButton.OK); this.SendState = NormalStateKey; } }