public async Task <GarmentShippingInvoiceViewModel> ReadById(int id)
        {
            var data = await _repository.ReadByIdAsync(id);

            var viewModel = MapToViewModel(data);

            return(viewModel);
        }
        public virtual async Task <int> Update(int id, GarmentPackingListViewModel viewModel)
        {
            viewModel.ShippingMarkImagePath = await UploadImage(viewModel.ShippingMarkImageFile, viewModel.Id, viewModel.ShippingMarkImagePath, viewModel.CreatedUtc);

            viewModel.SideMarkImagePath = await UploadImage(viewModel.SideMarkImageFile, viewModel.Id, viewModel.SideMarkImagePath, viewModel.CreatedUtc);

            viewModel.RemarkImagePath = await UploadImage(viewModel.RemarkImageFile, viewModel.Id, viewModel.RemarkImagePath, viewModel.CreatedUtc);

            GarmentPackingListModel garmentPackingListModel = MapToModel(viewModel);
            var invoice = _invoiceRepository.ReadAll();
            GarmentShippingInvoiceModel shippingInvoice = (from a in invoice
                                                           where a.InvoiceNo == garmentPackingListModel.InvoiceNo
                                                           select a).FirstOrDefault();

            if (shippingInvoice != null)
            {
                var invoiceItem = await _invoiceRepository.ReadByIdAsync(shippingInvoice.Id);

                GarmentShippingInvoiceModel shippingInvoiceItem = invoiceItem;

                if (shippingInvoiceItem != null)
                {
                    shippingInvoiceItem.InvoiceDate = garmentPackingListModel.Date;

                    await _invoiceRepository.UpdateAsync(shippingInvoiceItem.Id, shippingInvoiceItem);
                }
            }
            foreach (var item in garmentPackingListModel.Items)
            {
                foreach (var detail in item.Details)
                {
                    detail.SetNetNetWeight(detail.NetNetWeight == 0 ? 0.9 * detail.NetWeight : detail.NetNetWeight, _identityProvider.Username, UserAgent);
                }
            }

            var totalNnw = garmentPackingListModel.Items
                           .SelectMany(i => i.Details.Where(d => d.IsDeleted == false).Select(d => new { d.Carton1, d.Carton2, totalNetNetWeight = d.CartonQuantity * d.NetNetWeight }))
                           .GroupBy(g => new { g.Carton1, g.Carton2 }, (key, value) => value.First().totalNetNetWeight).Sum();

            garmentPackingListModel.SetNetNetWeight(totalNnw, _identityProvider.Username, UserAgent);

            return(await _packingListRepository.UpdateAsync(id, garmentPackingListModel));
        }