public static async Task <Order> PostOrder(Order order)
        {
            PostOrderDTO orderDTO = PostOrderDTO.FromOrder(order);
            string       content  = JsonConvert.SerializeObject(orderDTO);

            UserService serv   = UserService.GetInstance();
            HttpClient  client = new HttpClient();

            client.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", serv.Token));
            HttpResponseMessage res = await client.PostAsync(new Uri($"https://flightappapi.azurewebsites.net/api/Shop/create_order/{serv.User.FlightId}"),
                                                             new HttpStringContent(content, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"));

            if (res.IsSuccessStatusCode)
            {
                OrderDTO response = JsonConvert.DeserializeObject <OrderDTO>(res.Content.ToString());
                return(response.ToOrder());
            }
            return(null);
        }
Esempio n. 2
0
        public async Task <IDictionary <string, object> > Create(OrderDTO orderDTO)
        {
            // var user = User.;
            try{
                if (orderDTO.OrderDetails == null || orderDTO.OrderDetails.Count == 0)
                {
                    return(Const.Response.ControlerResponse(Const.StatusCode.BadRequest));
                }
                var order = orderDTO.ToOrder();
                order.Status     = OrderStatus.Sent;
                order.CreateDate = DateTime.Now;

                await _orderRepo.Create(order);

                return(Const.Response.ControlerResponse(Const.StatusCode.OK, "Action complete successfully"));
            }
            catch (Exception e) {
                Console.WriteLine(e.ToString());
                return(Const.Response.ControlerResponse(Const.StatusCode.InternalServerError, e.ToString()));
            }
        }