public OperationResult <Guid?> CreateAlarmMetric(AlarmMetricEditDto dto) { //Validazione argomenti if (dto == null) { throw new ArgumentNullException(nameof(dto)); } //Dichiaro la lista di risultati di ritorno IList <ValidationResult> vResults = new List <ValidationResult>(); //Definisco l'entità AlarmMetric entity = new AlarmMetric(); entity.Metric = dto.Metric; entity.Device = dto.Device != null && dto.Device.Id.HasValue ? _deviceRepository.Load(dto.Device.Id) : null; entity.Alarm = dto.Alarm.HasValue ? _alarmRepository.Load(dto.Alarm) : null; entity.ThresholdMax = dto.ThresholdMax; entity.ThresholdMin = dto.ThresholdMin; //Eseguo la validazione logica vResults = ValidateEntity(entity); if (!vResults.Any()) { //Salvataggio su db _alarmMetricRepository.Save(entity); } //Ritorno i risultati return(new OperationResult <Guid?> { ReturnedValue = entity.Id, ValidationResults = vResults }); }
public OperationResult <Guid?> CloseProcessInstance(Guid?id) { if (!id.HasValue) { throw new ArgumentNullException(nameof(id)); } IList <ValidationResult> vResults = new List <ValidationResult>(); ProcessInstance entity = _processInstanceRepository.Load(id); entity.ProcessInstanceState = ProcessInstanceState.Close; entity.CloseDate = DateTime.Now; entity.CloseFrom = IdentityHelper.GetUsername(); foreach (var parameter in entity.Process.Parameters) { foreach (var alarm in parameter.Alarms) { foreach (var alarmMetric in alarm.AlarmMetrics) { alarmMetric.Device = null; var alarmMetricValidation = ValidateEntity(alarmMetric); if (!alarmMetricValidation.Any()) { _alarmMetricRepository.Save(alarmMetric); } } } } vResults = ValidateEntity(entity); if (!vResults.Any()) { //Salvataggio su db _processInstanceRepository.Save(entity); } //Ritorno i risultati return(new OperationResult <Guid?> { ReturnedValue = null, ValidationResults = vResults }); }