public Model CreateModel(Model model) { List <Model> models = _modelRepository.ReadAllModels(); if (model == null) { throw new ArgumentException("Model is missing"); } if (models != null) { foreach (Model m in models) { if (model.ModelId == m.ModelId && model.Name == m.Name && model.ManufacturerId == m.ManufacturerId) { throw new InvalidOperationException("Model already exist"); } } } if (_modelValidator != null) { _modelValidator.ValidateModel(model); } return(_modelRepository.AddModel(model)); }
private async Task SaveItemAsync() { Notification result = Notification.Success(); ModelUpdateEvent updateEvent = _isNewModel ? ModelUpdateEvent.Created : ModelUpdateEvent.Updated; result = _validator.ValidateModel(Model); if (result.IsValid()) { var saveResult = await _repository.SaveSampleItemAsync(Model, updateEvent); result.AddRange(saveResult); } if (result.IsValid()) { var eventMessenger = CC.IoC.Resolve <IEventAggregator>(); ModelUpdatedMessageResult <SampleItem> eventResult = new ModelUpdatedMessageResult <SampleItem>() { UpdatedModel = Model, UpdateEvent = updateEvent }; eventMessenger.GetEvent <ModelUpdatedMessageEvent <SampleItem> >().Publish(eventResult); await Close(); } else { await UserNotifier.ShowMessageAsync(result.ToString(), "Save Failed"); } }
/// <inheritdoc/> public IEnumerable <string> ValidateStubModel(StubModel stub) { var validationResults = _modelValidator.ValidateModel(stub); var result = new List <string>(); HandleValidationResult(result, validationResults); // Validate extra duration. var extraDurationMillis = stub?.Response?.ExtraDuration ?? 0; var allowedMillis = _settings.Stub?.MaximumExtraDurationMillis; if (extraDurationMillis > 0 && extraDurationMillis > allowedMillis) { result.Add($"Value for 'ExtraDuration' cannot be higher than '{allowedMillis}'."); } ValidateScenarioVariables(stub, result); ValidateResponseBody(stub, result); return(result); }