Beispiel #1
0
        public async Task <int> SaveJournalEntry(JournalEntry JournalEntry)
        {
            if (string.IsNullOrEmpty(this.Config.AccessToken))
            {
                await this.RefreshToken();
            }

            var saveJournalEntryRequest = new SaveJournalEntryRequest(JournalEntry);
            var response = await this.HttpService.POST_ASYNC <SaveJournalEntryRequest>($"https://{this.Config.ServerName}/jtransApi/tmpBatch", saveJournalEntryRequest, headers : new Dictionary <string, string>
            {
                ["Accept"]        = "application/json",
                ["Content-Type"]  = "application/json",
                ["Authorization"] = $"Bearer {this.Config.AccessToken}"
            });

            var status = this.ParseResponse(response.Content);

            // Unauthorized - refresh token and try again
            if (!status.Success && status.Error == "Token is not valid")
            {
                await this.RefreshToken();

                response = await this.HttpService.POST_ASYNC <SaveJournalEntryRequest>($"https://{this.Config.ServerName}/jtransApi/tmpBatch", saveJournalEntryRequest, headers : new Dictionary <string, string>
                {
                    ["Accept"]        = "application/json",
                    ["Content-Type"]  = "application/json",
                    ["Authorization"] = $"Bearer {this.Config.AccessToken}"
                });

                status = this.ParseResponse(response.Content);
            }

            if (!status.Success)
            {
                throw new Exception(response.Content);
            }

            var modelSchema = new {
                batchno = 0
            };

            var responseData = JsonConvert.DeserializeAnonymousType(response.Content, modelSchema);

            return(responseData.batchno);
        }
Beispiel #2
0
        public async Task <IActionResult> SaveJournalEntry([FromBody] SaveJournalEntryRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            PortalUser user = await repository.AuthenticateUserToken(req.CurrentUser.UserId, req.CurrentUser.UserToken);

            if (user == null)
            {
                return(NotFound());
            }

            SaveJournalEntryResponse resp = new SaveJournalEntryResponse
            {
                CurrentEntry = await SaveJournalEntryModel(user, req.JournalTypeId, ConvertJSONToModel(req.JournalEntry, req.JournalTypeId), repository)
            };

            return(Ok(resp));
        }