Example #1
0
        public async Task <IActionResult> Put(string id, [FromBody] OrderEditCommand command)
        {
            try
            {
                await service.EditAsync
                (
                    id,
                    command,
                    ArticleController.GetPathTemplate(Request)
                );

                return(NoContent());
            }
            catch (KeyNotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            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));
            }
        }
Example #2
0
        public async Task EditAsync(string id, OrderEditCommand command, string productPicturePath)
        {
            try
            {
                var oldOrder = await GetAsync(id);

                if (oldOrder == null)
                {
                    throw new KeyNotFoundException($"{nameof(Order)} {id} not found");
                }

                var order = new Order
                            (
                    oldOrder.Number,
                    oldOrder.Details,
                    oldOrder.Customer,
                    command.DeliveryPlace,
                    oldOrder.CreatedAt,
                    command.State,
                    command.Comment,
                    command.DeliveryPredicateAt,
                    command.DeliveryAt
                            );
                await FirebaseClient
                .Child(Table)
                .Child(id)
                .PutAsync(JsonConvert.SerializeObject(order));
            }
            catch (KeyNotFoundException ex)
            {
                throw ex;
            }
            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;
            }
        }