public OperationResult <Guid?> CreateDeviceErrorLog(DeviceErrorLogDto 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à DeviceErrorLog entity = new DeviceErrorLog(); entity.Error = dto.Error; entity.DeviceId = dto.DeviceId; entity.ProcessInstanceId = dto.ProcessInstanceId; //Eseguo la validazione logica vResults = ValidateEntity(entity); if (!vResults.Any()) { //Salvataggio su db _deviceErrorLogRepository.Save(entity); } //Ritorno i risultati return(new OperationResult <Guid?> { ReturnedValue = entity.Id, ValidationResults = vResults }); }
public IHttpActionResult Log(DeviceErrorLogDto dto) { try { var results = _deviceErrorLogService.CreateDeviceErrorLog(dto); if (results.HasErrors()) { Log4NetConfig.ApplicationLog.Error(string.Format("Errore durante la chiamata api/DeviceErrorLog/Log: {0}", results.GetValidationErrorsInline("-"))); NHibernateHelper.SessionFactory.GetCurrentSession().Transaction.Rollback(); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, results.GetValidationErrorsInline("-")))); } } catch (Exception ex) { Log4NetConfig.ApplicationLog.Error(string.Format("Errore durante la chiamata api/DeviceErrorLog/Log: {0}", ex.Message.ToString())); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest))); } //Ritorno i risultati return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK))); }