示例#1
0
        public async Task <OrderDto> AddAsync(OrderAddCommand command, string productPicturePath)
        {
            try
            {
                string number = string.Empty;
                do
                {
                    number = await GenerateNumber();
                }while (await GetOrderByNumberAsync(number, productPicturePath) != null);

                var order = new Order
                            (
                    number,
                    command.Carts.Select
                    (
                        x => new OrderDetail
                        (
                            x.Key,
                            _productService.GetAsync(x.Key).Result,
                            x.Value
                        )
                    ),
                    (await _userService.GetAsync(command.CustomerId)).Value,
                    command.DeliveryPlace,
                    command.CreatedAt,
                    Common.StateOptions.In_process,
                    null,
                    null,
                    null
                            );

                var result = await FirebaseClient
                             .Child(Table)
                             .PostAsync(JsonConvert.SerializeObject(order));

                return(await GetOrder(result.Key, order, productPicturePath));
            }
            catch (Firebase.Database.FirebaseException ex)
            {
                if (ex.InnerException?.InnerException?.GetType() == typeof(SocketException))
                {
                    throw new HttpRequestException("Cannot join the server. Please check your internet connexion.");
                }
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
 public async Task <IActionResult> Post([FromBody] OrderAddCommand command)
 {
     try
     {
         return(Ok
                (
                    await service.AddAsync(command, ArticleController.GetPathTemplate(Request))
                ));
     }
     catch (DuplicateWaitObjectException ex)
     {
         return(Conflict(ex.Message));
     }
     catch (HttpRequestException ex)
     {
         return(StatusCode(StatusCodes.Status503ServiceUnavailable, ex.Message));
         //return BadRequest(ex.Message);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Print(ex.ToString());
         return(BadRequest(Error));
     }
 }