public async Task <object> AddJournal(oJournal jrnal) { HttpResponseMessage _resp = new HttpResponseMessage(); try { if (!GlobalInstance.Instance.IsConnected) { GlobalInstance.Instance.InitializeSboComObject(); } var j = await repo.GetByRDTransId(jrnal.TransactionId); string validationStr = ModelValidator.ValidateModel(jrnal); if (!string.IsNullOrEmpty(validationStr)) { errMsg = string.Format(validationStr); var resp = new HttpResponseMessage(HttpStatusCode.Conflict); resp.Content = new StringContent(errMsg); resp.ReasonPhrase = "Object property validation error"; ErrorLog _err = new ErrorLog(); _err.ErrorCode = (int)HttpStatusCode.Conflict; _err.Message = errMsg; _err.StackTrace = Environment.StackTrace; var err = ErrorLogger.Log(_err); transactionLogger.LogJournalTransaction(jrnal, false, "A", HttpContext.Current.Request.UserHostAddress, _err); _resp = resp; throw new HttpResponseException(resp); } if (j != null) { errMsg = string.Format("Journal {0} already exist.", jrnal.TransactionId); var resp = new HttpResponseMessage(HttpStatusCode.Conflict); resp.Content = new StringContent(errMsg); resp.ReasonPhrase = "Object already exist."; ErrorLog _err = new ErrorLog(); _err.ErrorCode = (int)HttpStatusCode.Conflict; _err.Message = errMsg; _err.StackTrace = Environment.StackTrace; var err = ErrorLogger.Log(_err); transactionLogger.LogJournalTransaction(jrnal, false, "A", HttpContext.Current.Request.UserHostAddress, _err); _resp = resp; throw new HttpResponseException(resp); } if (repo.Add(jrnal) != 0) { errMsg = GlobalInstance.Instance.SBOErrorMessage; var resp = new HttpResponseMessage(HttpStatusCode.Conflict); resp.Content = new StringContent(errMsg); resp.ReasonPhrase = "SBO Error"; ErrorLog _err = new ErrorLog(); _err.ErrorCode = (int)HttpStatusCode.Conflict; _err.Message = errMsg; _err.StackTrace = Environment.StackTrace; var err = ErrorLogger.Log(_err); transactionLogger.LogJournalTransaction(jrnal, false, "A", HttpContext.Current.Request.UserHostAddress, _err); _resp = resp; throw new HttpResponseException(resp); } transactionLogger.LogJournalTransaction(jrnal, true, "A", HttpContext.Current.Request.UserHostAddress); var _j = await repo.GetByRDTransId(jrnal.TransactionId); return(new { SAPTransactionId = _j.TransId, ReturnMessage = $"Journal {jrnal.TransactionId} successfully added." }); } catch (HttpResponseException ex) { throw new HttpResponseException(ex.Response); } }