Example #1
0
        public async Task <int> Create(GarmentShippingInsuranceDispositionViewModel viewModel)
        {
            GarmentShippingInsuranceDispositionModel model = MapToModel(viewModel);

            int Created = await _repository.InsertAsync(model);

            return(Created);
        }
Example #2
0
        public Task <int> InsertAsync(GarmentShippingInsuranceDispositionModel model)
        {
            model.FlagForCreate(_identityProvider.Username, UserAgent);

            foreach (var item in model.Items)
            {
                item.FlagForCreate(_identityProvider.Username, UserAgent);
            }

            _dbSet.Add(model);

            return(_dbContext.SaveChangesAsync());
        }
        public void Should_Success_Get_InsuranceViewModel()
        {
            var items = new HashSet <GarmentShippingInsuranceDispositionItemModel> {
                new GarmentShippingInsuranceDispositionItemModel(DateTimeOffset.Now, "", "", 1, 1, "", "", 1, 1, 1, 1, 1, 1, 1), new GarmentShippingInsuranceDispositionItemModel(DateTimeOffset.Now, "", "", 2, 2, "", "", 2, 2, 2, 2, 2, 2, 2)
            };
            var model = new GarmentShippingInsuranceDispositionModel("", "", DateTimeOffset.Now, "", 1, "", "", 1, "", items);

            var repoMock = new Mock <IGarmentShippingInsuranceDispositionRepository>();

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

            var service = GetService(GetServiceProvider(repoMock.Object).Object);
            var result  = service.GetInsurance(It.IsAny <int>());

            Assert.NotNull(result);
        }
        public void Read_Success()
        {
            var model = new GarmentShippingInsuranceDispositionModel("", "", DateTimeOffset.Now, "", 1, "", "", 1, "", new List <GarmentShippingInsuranceDispositionItemModel>());

            var repoMock = new Mock <IGarmentShippingInsuranceDispositionRepository>();

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

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

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

            Assert.NotEmpty(result.Data);
        }
Example #5
0
        private GarmentShippingInsuranceDispositionModel MapToModel(GarmentShippingInsuranceDispositionViewModel viewModel)
        {
            var items = (viewModel.items ?? new List <GarmentShippingInsuranceDispositionItemViewModel>()).Select(i =>
            {
                i.BuyerAgent = i.BuyerAgent ?? new BuyerAgent();
                return(new GarmentShippingInsuranceDispositionItemModel(i.policyDate, i.policyNo, i.invoiceNo, i.invoiceId, i.BuyerAgent.Id, i.BuyerAgent.Code, i.BuyerAgent.Name, i.amount, i.currencyRate, i.amount2A, i.amount2B, i.amount2C, i.amount1A, i.amount1B)
                {
                    Id = i.Id
                });
            }).ToList();


            viewModel.insurance = viewModel.insurance ?? new Insurance();


            GarmentShippingInsuranceDispositionModel garmentShippingInvoiceModel = new GarmentShippingInsuranceDispositionModel(GenerateNo(viewModel), viewModel.policyType, viewModel.paymentDate.GetValueOrDefault(), viewModel.bankName, viewModel.insurance.Id, viewModel.insurance.Name, viewModel.insurance.Code, viewModel.rate, viewModel.remark, items);

            return(garmentShippingInvoiceModel);
        }
Example #6
0
        public Task <int> UpdateAsync(int id, GarmentShippingInsuranceDispositionModel model)
        {
            var modelToUpdate = _dbSet
                                .Include(i => i.Items)
                                .FirstOrDefault(s => s.Id == id);

            modelToUpdate.SetBankName(model.BankName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetInsuranceCode(model.InsuranceCode, _identityProvider.Username, UserAgent);
            modelToUpdate.SetInsuranceId(model.InsuranceId, _identityProvider.Username, UserAgent);
            modelToUpdate.SetInsuranceName(model.InsuranceName, _identityProvider.Username, UserAgent);
            modelToUpdate.SetPaymentDate(model.PaymentDate, _identityProvider.Username, UserAgent);
            modelToUpdate.SetRate(model.Rate, _identityProvider.Username, UserAgent);
            modelToUpdate.SetRemark(model.Remark, _identityProvider.Username, UserAgent);

            foreach (var itemToUpdate in modelToUpdate.Items)
            {
                var item = model.Items.FirstOrDefault(i => i.Id == itemToUpdate.Id);
                if (item != null)
                {
                    itemToUpdate.SetAmount(item.Amount, _identityProvider.Username, UserAgent);
                    itemToUpdate.SetCurrencyRate(item.CurrencyRate, _identityProvider.Username, UserAgent);
                    itemToUpdate.SetPolicyDate(item.PolicyDate, _identityProvider.Username, UserAgent);
                    itemToUpdate.SetPolicyNo(item.PolicyNo, _identityProvider.Username, UserAgent);
                }
                else
                {
                    itemToUpdate.FlagForDelete(_identityProvider.Username, UserAgent);
                }
            }

            foreach (var item in model.Items.Where(w => w.Id == 0))
            {
                modelToUpdate.Items.Add(item);
            }

            return(_dbContext.SaveChangesAsync());
        }
Example #7
0
        public void GenerateExcel_Success()
        {
            var items = new List <GarmentShippingInsuranceDispositionItemModel>
            {
                new GarmentShippingInsuranceDispositionItemModel(DateTimeOffset.Now, "001", "DL/210001", 1, 1, "", "", 1, 1, 1, 1, 1, 1, 1)
                {
                    InsuranceDispositionId = 1
                },
                new GarmentShippingInsuranceDispositionItemModel(DateTimeOffset.Now, "002", "DL/210002", 2, 2, "", "", 2, 2, 2, 2, 2, 2, 2)
                {
                    InsuranceDispositionId = 1
                },
            };

            var model = new GarmentShippingInsuranceDispositionModel("001", "Kargo", DateTimeOffset.Now, "", 1, "", "", 1, "", items)
            {
                Id = 1
            };

            var repoMock = new Mock <IGarmentShippingInsuranceDispositionRepository>();

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

            repoMock.Setup(s => s.ReadItemAll())
            .Returns(items.AsQueryable());

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

            var result = service.GenerateExcel(null, DateTime.MinValue, DateTime.Now, 7);

            Assert.NotNull(result);
        }
Example #8
0
        private GarmentShippingInsuranceDispositionViewModel MapToViewModel(GarmentShippingInsuranceDispositionModel model)
        {
            var vm = new GarmentShippingInsuranceDispositionViewModel()
            {
                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,

                bankName      = model.BankName,
                dispositionNo = model.DispositionNo,
                insurance     = new Insurance
                {
                    Id   = model.InsuranceId,
                    Code = model.InsuranceCode,
                    Name = model.InsuranceName
                },
                paymentDate = model.PaymentDate,
                policyType  = model.PolicyType,

                rate   = model.Rate,
                remark = model.Remark,
                items  = (model.Items ?? new List <GarmentShippingInsuranceDispositionItemModel>()).Select(i => new GarmentShippingInsuranceDispositionItemViewModel
                {
                    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,
                    amount            = i.Amount,
                    currencyRate      = i.CurrencyRate,
                    BuyerAgent        = new BuyerAgent
                    {
                        Id   = i.BuyerAgentId,
                        Code = i.BuyerAgentCode,
                        Name = i.BuyerAgentName
                    },
                    insuranceDispositionId = i.InsuranceDispositionId,
                    invoiceId  = i.InvoiceId,
                    invoiceNo  = i.InvoiceNo,
                    policyDate = i.PolicyDate,
                    policyNo   = i.PolicyNo,
                    amount1A   = i.Amount1A,
                    amount1B   = i.Amount1B,
                    amount2A   = i.Amount2A,
                    amount2B   = i.Amount2B,
                    amount2C   = i.Amount2C
                }).ToList(),
            };

            return(vm);
        }
Example #9
0
        public async Task <int> Update(int id, GarmentShippingInsuranceDispositionViewModel viewModel)
        {
            GarmentShippingInsuranceDispositionModel model = MapToModel(viewModel);

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