public async Task <IActionResult> Put([FromBody] BookingViewModel bookingViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }

                var bookingViewModelResult = await _bookingAppService.UpdateAsync(bookingViewModel);

                if (bookingViewModelResult?.Data == null)
                {
                    return(BadRequest(new { message = "A problem occurred during updating the data." }));
                }

                return(Ok(bookingViewModelResult.Data));
            }
            catch (ExceptionHandler exceptionHandler)
            {
                return(ResponseByHttpStatusCode(exceptionHandler));
            }
        }
        public async Task <ActionResult> EditBooking(BookingHeaderDto dto)
        {
            foreach (var dtoItem in dto.BookingDetails)
            {
                var check = await _stockService.CheckIfExist(dtoItem.ProductId);

                var old = await _bookingDetailsService.GetDetailsAsync(dtoItem.Id);

                if (old != null)
                {
                    if (dtoItem.TotalPieces > old.TotalPieces)
                    {
                        var change  = dtoItem.TotalPieces - old.TotalPieces;
                        var tAmount = dtoItem.PricePerPiece * change;
                        check.TotalPieces -= change;
                        check.Amount      -= tAmount;

                        await _stockService.UpdateAsync(check);
                    }
                    else if (dtoItem.TotalPieces < old.TotalPieces)
                    {
                        var change  = old.TotalPieces - dtoItem.TotalPieces;
                        var tAmount = dtoItem.PricePerPiece * change;
                        check.TotalPieces += change;
                        check.Amount      += tAmount;

                        await _stockService.UpdateAsync(check);
                    }
                }
                else
                {
                    check.TotalPieces -= dtoItem.TotalPieces;
                    check.Amount      -= dtoItem.Amount;

                    await _stockService.UpdateAsync(check);
                }
            }

            var updated = await _bookingService.UpdateAsync(dto);

            foreach (var items in dto.BookingDetails)
            {
                var getCheck = await _bookingDetailsService.GetAsync(new EntityDto <int>(items.Id));

                if (getCheck == null)
                {
                    var toCreate = new BookingDetailDto
                    {
                        BookingHeaderId   = dto.BookingId,
                        ProductId         = items.ProductId,
                        Case              = items.Case,
                        ProdCase          = items.ProdCase,
                        Box               = items.Box,
                        ProdPiece         = items.ProdPiece,
                        Piece             = items.Piece,
                        Gross             = items.Gross,
                        Discount          = items.Discount,
                        Net               = items.Net,
                        TotalProductPrice = items.TotalProductPrice,
                    };
                    await _bookingDetailsService.CreateAsync(toCreate);
                }
                else if (getCheck != null)
                {
                    var toUpdate = new BookingDetailDto
                    {
                        Id                = items.Id,
                        CreationTime      = items.CreationTime,
                        CreatorUserId     = items.CreatorUserId,
                        TenantId          = items.TenantId,
                        BookingHeaderId   = items.BookingHeaderId,
                        ProductId         = items.ProductId,
                        Case              = items.Case,
                        ProdCase          = items.ProdCase,
                        Box               = items.Box,
                        ProdPiece         = items.ProdPiece,
                        Piece             = items.Piece,
                        Gross             = items.Gross,
                        Discount          = items.Discount,
                        Net               = items.Net,
                        TotalProductPrice = items.TotalProductPrice,
                    };
                    await _bookingDetailsService.UpdateAsync(toUpdate);
                }
            }

            return(Ok(updated));
        }