public ViewAnalogousVM CollectExistingAnalogousReactions() { var mainViewModel = ((MainWindow)(App.Current.MainWindow)).DataContext as MainVM; List <RsnVM> tanRsns = new List <RsnVM>(); List <ReactionVM> tanReactions = new List <ReactionVM>(); var tanParticipants = new List <ReactionParticipantVM>(); AnalogousReactions.Clear(); AllParticipants.Clear(); ReactionParticipants.Clear(); try { var analogousReactions = mainViewModel.TanVM.Reactions.Where(r => r.AnalogousVMId == SelectedMasterReaction.Id); foreach (var existingAnalogousReaction in analogousReactions) { AnalogousReactions.Add(existingAnalogousReaction); AllParticipants.AddRange(mainViewModel.TanVM.ReactionParticipants.Where(rp => rp.ReactionVM.Id == existingAnalogousReaction.Id)); ReactionParticipants.AddRange(mainViewModel.TanVM.ReactionParticipants.Where(rp => rp.ReactionVM.Id == existingAnalogousReaction.Id)); foreach (var rsn in (mainViewModel.TanVM.Rsns.Where(rsn => rsn.Reaction.Id == existingAnalogousReaction.Id))) { Rsns.Add(rsn); } } } catch (Exception ex) { AppErrorBox.ShowErrorMessage("Error while collecting analogous reactions", ex.Message); } return(this); }
private void DoSaveForm(object obj) { try { string outMsg = string.Empty; if (!string.IsNullOrEmpty(FreeText.Trim()) || !string.IsNullOrEmpty(CVT)) { if (!RV.ValidateRsnFreetext(FreeText, ReactionVM, StageVM, RsnLevel, out outMsg)) { AppInfoBox.ShowInfoMessage(outMsg); return; } if (RV.ValidateRsnReactionLevel(ReactionVM, StageVM, RsnLevel, CVT, FreeText, Rsns.ToList(), out outMsg, EditingRsn)) { if (EditingRsn != null) { EditingRsn.CvtText = CVT; EditingRsn.IsIgnorableInDelivery = IsIgnorableInDelivery; EditingRsn.FreeText = FreeText.Trim().TrimEnd('.'); EditingRsn.Stage = RsnLevel == RsnLevel.STAGE ? StageVM : null; UpdateRsnLengths(); } else { var rsn = new RsnVM { }; rsn.CvtText = CVT; rsn.IsIgnorableInDelivery = IsIgnorableInDelivery; rsn.FreeText = FreeText.Trim().TrimEnd('.'); rsn.Reaction = ReactionVM; rsn.Id = Guid.NewGuid(); rsn.Stage = RsnLevel == RsnLevel.STAGE ? StageVM : null; rsn.RSNWindowVM = this; Rsns.Add(rsn); } } else { AppInfoBox.ShowInfoMessage(outMsg); return; } if (Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).Count() > 0 && Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.BIOTRANSFORMATION_CVT)).Count() == 0) { var enzymicRSN = Rsns.Where(rsn => rsn.CvtText.SafeEqualsLower(S.ENZYMIC_CVT)).FirstOrDefault(); string freeTextToAdd = !string.IsNullOrEmpty(enzymicRSN.FreeText) ? RV.GetStageInfoWithOutFreeText(enzymicRSN.FreeText) : string.Empty; Rsns.Add(new RsnVM { CvtText = S.BIOTRANSFORMATION_CVT, FreeText = RsnLevel == RsnLevel.STAGE ? $"{S.BIOTRANSFORMATION_FREETEXT} {freeTextToAdd}" : string.Empty, IsRXN = true, Stage = enzymicRSN.Stage != null ? enzymicRSN.Stage : null, Reaction = ReactionVM, RSNWindowVM = this, Id = Guid.NewGuid() }); } ClearEditForm.Execute(this); } else { AppInfoBox.ShowInfoMessage("Either CVT or FreeText mandatory to save RSN"); } } catch (Exception ex) { Log.This(ex); AppErrorBox.ShowErrorMessage(ex.Message, ex.ToString()); } }