コード例 #1
0
        public virtual async Task <string> Create(GarmentPackingListViewModel viewModel)
        {
            viewModel.Status = GarmentPackingListStatusEnum.CREATED.ToString();

            GarmentPackingListModel garmentPackingListModel = MapToModel(viewModel);

            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);

            garmentPackingListModel.StatusActivities.Add(new GarmentPackingListStatusActivityModel(_identityProvider.Username, UserAgent, garmentPackingListModel.Status));

            await _packingListRepository.InsertAsync(garmentPackingListModel);

            garmentPackingListModel.SetShippingMarkImagePath(await UploadImage(viewModel.ShippingMarkImageFile, garmentPackingListModel.Id, garmentPackingListModel.ShippingMarkImagePath, garmentPackingListModel.CreatedUtc), _identityProvider.Username, UserAgent);
            garmentPackingListModel.SetSideMarkImagePath(await UploadImage(viewModel.SideMarkImageFile, garmentPackingListModel.Id, garmentPackingListModel.SideMarkImagePath, garmentPackingListModel.CreatedUtc), _identityProvider.Username, UserAgent);
            garmentPackingListModel.SetRemarkImagePath(await UploadImage(viewModel.RemarkImageFile, garmentPackingListModel.Id, garmentPackingListModel.RemarkImagePath, garmentPackingListModel.CreatedUtc), _identityProvider.Username, UserAgent);
            await _packingListRepository.SaveChanges();

            return(garmentPackingListModel.InvoiceNo);
        }
コード例 #2
0
        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);

            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));
        }
        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));
        }