public bool SaveTrainingDay(bool isWindowClosing) { if (!validateControls()) { return(false); } foreach (XtraTabPage tabPage in xtraTabControl1.TabPages) { IEntryObjectControl entryControl = (IEntryObjectControl)tabPage.Controls[0]; entryControl.UpdateEntryObject(); } if (day.Id == Constants.UnsavedObjectId && day.IsEmpty) { return(true); } day = ServiceManager.SaveTrainingDay(day); foreach (var module in PluginsManager.Instance.Modules) { module.AfterSave(UserContext.SessionData, day); } if (isWindowClosing) {//optimalization - we are closing window so we don't need to refresh the tabs (code below) return(true); } for (int index = xtraTabControl1.TabPages.Count - 1; index >= 0; index--) { XtraTabPage tabPage = xtraTabControl1.TabPages[index]; IEntryObjectControl entryControl = tabPage.Controls[0] as IEntryObjectControl; if (entryControl != null) { ParentWindow.SynchronizationContext.Send(delegate { entryControl.AfterSave(isWindowClosing); EntryObjectDTO entry = (EntryObjectDTO)tabPage.Controls[0].Tag; //here we assume that training day contains only one instance of the specific entry type var newEntry = day.GetSpecifiedEntries(entry.GetType()); if (newEntry != null) { tabPage.Controls[0].Tag = newEntry; entryControl.Fill(newEntry); } else { xtraTabControl1.TabPages.Remove(tabPage); } }, null); } } return(true); }
public bool SaveTrainingDay(bool isWindowClosing) { bool res = true; Guid? customerId = null; Guid? userId = null; TrainingDayDTO originalDay = null; Dispatcher.Invoke(new Action(delegate { if (!validateControls()) { res = false; return; } customerId = Customer != null ? Customer.GlobalId : (Guid?)null; userId = User != null ? User.GlobalId : (Guid?)null; foreach (TabItemViewModel tabPage in xtraTabControl1.Items) { IEntryObjectControl entryControl = (IEntryObjectControl)tabPage.Content; entryControl.UpdateEntryObject(); } originalDay = TrainingDayPageContext.Day; if (commentsControl != null) { day.AllowComments = commentsControl.AllowComments; } })); if (!res) { return(false); } if (day.GlobalId == Constants.UnsavedGlobalId && day.IsEmpty) { return(true); } var result = ServiceManager.SaveTrainingDay(day); day = result.TrainingDay; TrainingDayDTO tempDay = null; var cache = TrainingDaysReposidory.GetCache(customerId, userId); if (day == null) { tempDay = day = new TrainingDayDTO(originalDay.TrainingDate); cache.Remove(originalDay.TrainingDate); } else { tempDay = day.StandardClone(); cache.Add(tempDay); } ensureRemindersRefreshed(originalDay, day); Dispatcher.Invoke(new Action(delegate { //if (TrainingDayPageContext.Day.IsNew) //{ // rowSplitter.Process(tempDay.IsNew); //} TrainingDayPageContext.Day = tempDay; SetModifiedFlag(); if (commentsControl != null) { commentsControl.Fill(day); } foreach (var tabItemViewModel in Tabs) { var ctrl = (IEntryObjectControl)tabItemViewModel.Content; ctrl.AfterSave(false); } Tabs.Clear(); refreshTabs(filterType, result); })); return(true); }