public Product GetProduct(int productId) { Product product = null; if (ObjectsList != null) { product = ObjectsList.FirstOrDefault(p => p.Id == productId); } return(product); }
private async Task Save(ISourceProvider targetPathProvider) { if (targetPathProvider == null) { throw new ArgumentNullException(nameof(targetPathProvider), "SourceProvider can't be null."); } if (Persister.FileSystemDependency == FileSystemDependency.Independent) { targetPathProvider = new NullSourceProvider(); } if (targetPathProvider.GetAccess()) { try { string target = targetPathProvider.GetPath(); await Task.Run(async() => { if (IsTracingEnabled) { Tracer.LogSavingModel(target); Tracer.Flush(); } Persister.Access(target); await(ObjectsList?.FirstOrDefault().ModelObject as AssemblyMetadata)?.Save(Persister, target); Persister.Dispose(); InformationMessageTarget.SendMessage("Saving completed", "Model was successfully saved."); if (IsTracingEnabled) { Tracer.LogModelSaved(target); Tracer.Flush(); } }); } catch (Exception ex) { ErrorMessageTarget.SendMessage("Saving error", ex.Message); if (IsTracingEnabled) { Tracer.LogFailure( $"Exception caught when trying to open a file for writing {Environment.NewLine}{ex.Message}"); Tracer.Flush(); } } } }
public void Delete(User actionExecutor, MapObject mapObject) { var foundMapObject = ObjectsList.FirstOrDefault(x => x == mapObject); if (foundMapObject == null) { throw new ArgumentNullException(nameof(foundMapObject), "Object not found"); } if (Memberships.All(x => x.InvitedId != actionExecutor.Id)) { throw new DomainException("Have no access to map."); } foundMapObject.FileReferencesBindings.ForEach(binding => binding.FileReference.ScheduleToRemove()); foundMapObject.MarkAsRemoved(); ObjectsList.Remove(foundMapObject); AddEvent(new MapObjectRemoved(foundMapObject)); }