private Security CreateSecurity() { var security = SecurityType.CreateInstance <Security>(); var code = SecurityCode.IsEmpty() ? DefaultSecurityCode : SecurityCode; security.Id = _idGenerator.GenerateId(code, Board); security.Code = code; security.Name = code; security.Board = Board; UpdateSecurity(security); return(security); }
private void Save(bool showErrorIfNoCode) { if (SecurityCode.IsEmpty() || Board == null) { if (!showErrorIfNoCode) { return; } new MessageBoxBuilder() .Owner(this) .Caption(LocalizedStrings.Str3220) .Text(LocalizedStrings.Str3221) .Warning() .Show(); return; } var id = _idGenerator.GenerateId(SecurityCode, Board); var registry = ConfigManager.GetService <IStudioEntityRegistry>(); var security = registry.Securities.ReadById(id); if (security != null && security.GetType() != SecurityType) { new MessageBoxBuilder() .Owner(this) .Caption(LocalizedStrings.Str3222) .Text(LocalizedStrings.Str3223Params.Put(security.Id, security.Type)) .Error() .Show(); return; } if (security != null) { if (security != Security) { var res = new MessageBoxBuilder() .Owner(this) .Caption(LocalizedStrings.Str3222) .Text(LocalizedStrings.Str3224Params.Put(security.Id)) .Question() .YesNo() .Show(); if (res != MessageBoxResult.Yes) { return; } } UpdateSecurity(security); registry.Securities.Save(security); Security = security; } else { security = Security; security.Id = id; security.Code = SecurityCode; security.Board = Board; UpdateSecurity(security); registry.Securities.Add(security); SecurityPicker.Securities.Add(security); //TODO индексы не приходят через событие registry.Securities.Added _bufferedChart .Elements .Select(e => _bufferedChart.GetSource(e)) .OfType <CandleSeries>() .ForEach(series => { series.Security.Id = id; series.Security.Code = SecurityCode; series.Security.Board = Board; }); CanEdit = false; Title = id; RaiseChangedCommand(); } _canSave = false; }