public IActionResult PostOrder([FromBody] Order order)
        {
            try {
                DateTime thisDay = DateTime.Now;
                order.regDate = thisDay;

                _database.CreateOrder(order);

                string tokenString = _jwtHelper.CreateBrokerJWT(order.orderId);

                IActionResult response = Ok(new { token = tokenString, message = "Order created" });
                return(response);
            } catch (OrderAlreadyExistException) {
                return(StatusCode(StatusCodes.Status409Conflict, new { message = "Order already exists." }));
            } catch (Exception err) {
                Console.WriteLine(err);
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Internal server error." }));
            }
        }
Exemple #2
0
        public async Task <IActionResult> CreateOrder([FromQuery] Order order)
        {
            try {
                HttpContext.Request.Headers.TryGetValue("Authorization", out var basicAuthString);

                if (string.IsNullOrEmpty(basicAuthString))
                {
                    return(StatusCode(StatusCodes.Status400BadRequest, new { message = "Request must contain an Authorization header." }));
                }

                // den här funkar när jag kör postman anrop med Zm90b3BvcnRhbDpvS29rcDEyM2shb3BrQURuZHc3NDI0YTE= i Authorization header
                // men får 500 när jag kör anrop från next, därför är den utkommenterad
                // if (!validBasicAuth (basicAuthString)) {
                //     return StatusCode (StatusCodes.Status400BadRequest, new { message = "Request contains invalid value in Authorization header." });
                // }

                DateTime thisDay = DateTime.Now;
                order.regDate = thisDay;
                order         = await OrderController.CompleteOrderDetails(order);

                if (order == null)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Hub request didn't succeed." }));
                }

                _database.CreateOrder(order);

                string        tokenString = _jwtHelper.CreateBrokerJWT(order.orderId);
                IActionResult response    = Redirect(_config["SiteBaseUrl"] + "/maklare?token=" + tokenString);
                return(response);
            } catch (OrderAlreadyExistException err) {
                Console.WriteLine(err);
                return(StatusCode(StatusCodes.Status409Conflict, new { message = "Order already exists." }));
            } catch (Exception err) {
                Console.WriteLine(err);
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Internal server error." }));
            }
        }