public async Task <BlResult <GraphModel> > SaveAsync(GraphModel graphModel) { BlResult <GraphModel> blResult = new BlResult <GraphModel>(); try { if (graphModel is null) { throw new ArgumentException(); } EnsureTransaction(); var fetchedEntity = await _graphRepository.GetByIdWithReferencAsync(graphModel.Id); fetchedEntity = _mapper.Map(graphModel, fetchedEntity); if (graphModel.Id > 0) { _graphRepository.Edit(fetchedEntity); } else { fetchedEntity = _graphRepository.Add(fetchedEntity); await SaveChangesAsync(); NodeModel nodeModel = new NodeModel() { Name = fetchedEntity.Name, GraphId = fetchedEntity.Id, Data = "Entery node for graph " + fetchedEntity.Name, NodeAttributes = new System.Collections.ObjectModel.ObservableCollection <AttributeDescriptionModel>() { new AttributeDescriptionModel() { Id = (int)AttributesTypesEnum.EnteryNode } } }; if (fetchedEntity.IsAbstract) { nodeModel.NodeAttributes.Add(new AttributeDescriptionModel() { Id = (int)AttributesTypesEnum.Abstract }); } var result = await _nodeService.SaveAsync(nodeModel); if (result.Succeed) { EnsureTransaction(); fetchedEntity.EnteryNodeId = result.Value.Id; _graphRepository.Edit(fetchedEntity); } else { RollbackTransaction(); throw result.Exception; } } await SaveChangesAsync(); blResult.Success(_mapper.Map <GraphModel>(fetchedEntity)); } catch (ArgumentException) { blResult.Fail(ConstDictionary.CantSaveNullModel); } catch (Exception ex) { blResult.Fail(ex); } return(blResult); }