Пример #1
0
        public Task <int> UpdateAsync(int id, GarmentShippingVBPaymentModel model)
        {
            var modelToUpdate = _dbSet
                                .Include(i => i.Invoices)
                                .Include(i => i.Units)
                                .FirstOrDefault(s => s.Id == id);

            modelToUpdate.SetBillValue(model.BillValue, _identityProvider.Username, UserAgent);
            modelToUpdate.SetBuyerCode(model.BuyerCode, _identityProvider.Username, UserAgent);
            modelToUpdate.SetBuyerId(model.BuyerId, _identityProvider.Username, UserAgent);
            modelToUpdate.SetBuyerName(model.BuyerName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetEMKLCode(model.EMKLCode, _identityProvider.Username, UserAgent);
            modelToUpdate.SetEMKLId(model.EMKLId, _identityProvider.Username, UserAgent);
            modelToUpdate.SetEMKLInvoiceNo(model.EMKLInvoiceNo, _identityProvider.Username, UserAgent);
            modelToUpdate.SetEMKLName(model.EMKLName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetForwarderCode(model.ForwarderCode, _identityProvider.Username, UserAgent);
            modelToUpdate.SetForwarderId(model.ForwarderId, _identityProvider.Username, UserAgent);
            modelToUpdate.SetForwarderInvoiceNo(model.ForwarderInvoiceNo, _identityProvider.Username, UserAgent);
            modelToUpdate.SetForwarderName(model.ForwarderName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetIncomeTaxId(model.IncomeTaxId, _identityProvider.Username, UserAgent);
            modelToUpdate.SetIncomeTaxName(model.IncomeTaxName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetIncomeTaxRate(model.IncomeTaxRate, _identityProvider.Username, UserAgent);
            modelToUpdate.SetVatValue(model.VatValue, _identityProvider.Username, UserAgent);
            modelToUpdate.SetVBDate(model.VBDate, _identityProvider.Username, UserAgent);
            modelToUpdate.SetPaymentDate(model.PaymentDate, _identityProvider.Username, UserAgent);
            modelToUpdate.SetPaymentType(model.PaymentType, _identityProvider.Username, UserAgent);

            foreach (var invoiceToUpdate in modelToUpdate.Invoices)
            {
                var invoice = model.Invoices.FirstOrDefault(m => m.Id == invoiceToUpdate.Id);
                if (invoice == null)
                {
                    invoiceToUpdate.FlagForDelete(_identityProvider.Username, UserAgent);
                }
            }

            foreach (var invoice in model.Invoices.Where(w => w.Id == 0))
            {
                invoice.FlagForCreate(_identityProvider.Username, UserAgent);
                modelToUpdate.Invoices.Add(invoice);
            }

            foreach (var unitToUpdate in modelToUpdate.Units)
            {
                var unit = model.Units.FirstOrDefault(m => m.Id == unitToUpdate.Id);
                unitToUpdate.SetBillValue(unitToUpdate.BillValue, _identityProvider.Username, UserAgent);
                if (unit == null)
                {
                    unitToUpdate.FlagForDelete(_identityProvider.Username, UserAgent);
                }
            }

            foreach (var unit in model.Units.Where(w => w.Id == 0))
            {
                unit.FlagForCreate(_identityProvider.Username, UserAgent);
                modelToUpdate.Units.Add(unit);
            }

            return(_dbContext.SaveChangesAsync());
        }
Пример #2
0
        private GarmentShippingVBPaymentModel MapToModel(GarmentShippingVBPaymentViewModel viewModel)
        {
            var units = (viewModel.units ?? new List <GarmentShippingVBPaymentUnitViewModel>()).Select(i =>
            {
                i.unit = i.unit ?? new Unit();
                return(new GarmentShippingVBPaymentUnitModel(i.unit.Id, i.unit.Code, i.unit.Name, i.billValue)
                {
                    Id = i.Id
                });
            }).ToList();

            var invoices = (viewModel.invoices ?? new List <GarmentShippingVBPaymentInvoiceViewModel>()).Select(i =>
            {
                return(new GarmentShippingVBPaymentInvoiceModel(i.invoiceId, i.invoiceNo)
                {
                    Id = i.Id
                });
            }).ToList();

            viewModel.emkl      = viewModel.emkl ?? new EMKL();
            viewModel.forwarder = viewModel.forwarder ?? new Forwarder();
            viewModel.buyer     = viewModel.buyer ?? new Buyer();
            viewModel.incomeTax = viewModel.incomeTax ?? new IncomeTax();
            viewModel.vbNo      = GenerateNo(viewModel);
            GarmentShippingVBPaymentModel garmentPackingListModel = new GarmentShippingVBPaymentModel(viewModel.vbNo, viewModel.vbDate, viewModel.paymentType, viewModel.buyer.Id, viewModel.buyer.Code,
                                                                                                      viewModel.buyer.Name, viewModel.emkl.Id, viewModel.emkl.Name, viewModel.emkl.Code, viewModel.forwarder.id, viewModel.forwarder.code, viewModel.forwarder.name, viewModel.emklInvoiceNo,
                                                                                                      viewModel.forwarderInvoiceNo, viewModel.billValue, viewModel.vatValue, viewModel.paymentDate, viewModel.incomeTax.id, viewModel.incomeTax.name, viewModel.incomeTax.rate,
                                                                                                      units, invoices);

            return(garmentPackingListModel);
        }
Пример #3
0
        public async Task <int> Create(GarmentShippingVBPaymentViewModel viewModel)
        {
            GarmentShippingVBPaymentModel garmentShippingVBPaymentModel = MapToModel(viewModel);

            int Created = await _repository.InsertAsync(garmentShippingVBPaymentModel);

            return(Created);
        }
Пример #4
0
        public Task <int> InsertAsync(GarmentShippingVBPaymentModel model)
        {
            model.FlagForCreate(_identityProvider.Username, UserAgent);

            foreach (var invoice in model.Invoices)
            {
                invoice.FlagForCreate(_identityProvider.Username, UserAgent);
            }

            foreach (var unit in model.Units)
            {
                unit.FlagForCreate(_identityProvider.Username, UserAgent);
            }

            _dbSet.Add(model);

            return(_dbContext.SaveChangesAsync());
        }
Пример #5
0
        public void Read_Success()
        {
            var model = new GarmentShippingVBPaymentModel("", DateTimeOffset.Now, "", 1, "", "", 1, "", "", 1, "", "", "", "", 1, 1, DateTimeOffset.Now, 1, "", 1, new List <GarmentShippingVBPaymentUnitModel>(), new List <GarmentShippingVBPaymentInvoiceModel>());

            var repoMock = new Mock <IGarmentShippingVBPaymentRepository>();

            repoMock.Setup(s => s.ReadAll())
            .Returns(new List <GarmentShippingVBPaymentModel>()
            {
                model
            }.AsQueryable());

            var service = GetService(GetServiceProvider(repoMock.Object).Object);

            var result = service.Read(1, 25, "{}", "{}", null);

            Assert.NotEmpty(result.Data);
        }
Пример #6
0
        public async Task ReadById_Success()
        {
            var units = new HashSet <GarmentShippingVBPaymentUnitModel> {
                new GarmentShippingVBPaymentUnitModel(1, "", "", 1)
            };
            var invoices = new HashSet <GarmentShippingVBPaymentInvoiceModel> {
                new GarmentShippingVBPaymentInvoiceModel(1, "")
            };
            var model = new GarmentShippingVBPaymentModel("", DateTimeOffset.Now, "", 1, "", "", 1, "", "", 1, "", "", "", "", 1, 1, DateTimeOffset.Now, 1, "", 1, units, invoices);

            var repoMock = new Mock <IGarmentShippingVBPaymentRepository>();

            repoMock.Setup(s => s.ReadByIdAsync(It.IsAny <int>()))
            .ReturnsAsync(model);

            var service = GetService(GetServiceProvider(repoMock.Object).Object);

            var result = await service.ReadById(1);

            Assert.NotNull(result);
        }
Пример #7
0
        private GarmentShippingVBPaymentViewModel MapToViewModel(GarmentShippingVBPaymentModel model)
        {
            var vm = new GarmentShippingVBPaymentViewModel()
            {
                Active            = model.Active,
                Id                = model.Id,
                CreatedAgent      = model.CreatedAgent,
                CreatedBy         = model.CreatedBy,
                CreatedUtc        = model.CreatedUtc,
                DeletedAgent      = model.DeletedAgent,
                DeletedBy         = model.DeletedBy,
                DeletedUtc        = model.DeletedUtc,
                IsDeleted         = model.IsDeleted,
                LastModifiedAgent = model.LastModifiedAgent,
                LastModifiedBy    = model.LastModifiedBy,
                LastModifiedUtc   = model.LastModifiedUtc,

                vbNo  = model.VBNo,
                buyer = new Buyer
                {
                    Id   = model.BuyerId,
                    Code = model.BuyerCode,
                    Name = model.BuyerName,
                },
                paymentDate = model.PaymentDate,
                billValue   = model.BillValue,
                emkl        = new EMKL
                {
                    Id   = model.EMKLId,
                    Code = model.EMKLCode,
                    Name = model.EMKLName
                },
                emklInvoiceNo = model.EMKLInvoiceNo,
                forwarder     = new Forwarder
                {
                    id   = model.ForwarderId,
                    code = model.ForwarderCode,
                    name = model.ForwarderName
                },
                forwarderInvoiceNo = model.ForwarderInvoiceNo,
                incomeTax          = new IncomeTax
                {
                    id   = model.IncomeTaxId,
                    rate = model.IncomeTaxRate,
                    name = model.IncomeTaxName
                },
                paymentType = model.PaymentType,
                vatValue    = model.VatValue,
                vbDate      = model.VBDate,

                units = model.Units.Select(i => new GarmentShippingVBPaymentUnitViewModel
                {
                    Active            = i.Active,
                    Id                = i.Id,
                    CreatedAgent      = i.CreatedAgent,
                    CreatedBy         = i.CreatedBy,
                    CreatedUtc        = i.CreatedUtc,
                    DeletedAgent      = i.DeletedAgent,
                    DeletedBy         = i.DeletedBy,
                    DeletedUtc        = i.DeletedUtc,
                    IsDeleted         = i.IsDeleted,
                    LastModifiedAgent = i.LastModifiedAgent,
                    LastModifiedBy    = i.LastModifiedBy,
                    LastModifiedUtc   = i.LastModifiedUtc,

                    unit = new Unit
                    {
                        Id   = i.UnitId,
                        Code = i.UnitCode,
                        Name = i.UnitName,
                    },
                    billValue   = i.BillValue,
                    vbPaymentId = i.VBPaymentId
                }).ToList(),

                invoices = model.Invoices.Select(i => new GarmentShippingVBPaymentInvoiceViewModel
                {
                    Active            = i.Active,
                    Id                = i.Id,
                    CreatedAgent      = i.CreatedAgent,
                    CreatedBy         = i.CreatedBy,
                    CreatedUtc        = i.CreatedUtc,
                    DeletedAgent      = i.DeletedAgent,
                    DeletedBy         = i.DeletedBy,
                    DeletedUtc        = i.DeletedUtc,
                    IsDeleted         = i.IsDeleted,
                    LastModifiedAgent = i.LastModifiedAgent,
                    LastModifiedBy    = i.LastModifiedBy,
                    LastModifiedUtc   = i.LastModifiedUtc,

                    vbPaymentId = i.VBPaymentId,
                    invoiceId   = i.InvoiceId,
                    invoiceNo   = i.InvoiceNo
                }).ToList()
            };

            return(vm);
        }
Пример #8
0
        public async Task <int> Update(int id, GarmentShippingVBPaymentViewModel viewModel)
        {
            GarmentShippingVBPaymentModel garmentShippingVBPaymentModel = MapToModel(viewModel);

            return(await _repository.UpdateAsync(id, garmentShippingVBPaymentModel));
        }