コード例 #1
0
        public async Task TryToApplyFinancial_ShouldNotApply()
        {
            string errorMessagePrefix = "ContractService TryToApplyFinancial(long contractId) method does not work properly.";

            var context = HealthInsDbContextInMemoryFactory.InitializeContext();

            this.contractService = new ContractService(context);

            await SeedData(context);

            var actualResults = this.contractService.GetById(1);
            var contract      = context.Contracts.SingleOrDefault(c => c.Id == 1);

            var moneyIn = new MoneyIn()
            {
                Contract = contract,
                Status   = Data.Models.Financial.Enums.Status.Pending
            };

            context.Add(moneyIn);
            await context.SaveChangesAsync();

            var result = contractService.TryToApplyFinancial(1);

            Assert.True(moneyIn.Status == Data.Models.Financial.Enums.Status.Pending, errorMessagePrefix);
        }
コード例 #2
0
ファイル: MoneyInService.cs プロジェクト: kgyorev/HealthIns
        public async Task <bool> Create(MoneyInServiceModel moneyInServiceModel)
        {
            MoneyIn  moneyIn  = AutoMapper.Mapper.Map <MoneyIn>(moneyInServiceModel);
            Contract contract = this.context.Contracts.SingleOrDefault(p => p.Id == moneyInServiceModel.ContractId);

            moneyIn.Contract   = contract;
            moneyIn.RecordDate = DateTime.Now;
            moneyIn.Status     = HealthIns.Data.Models.Financial.Enums.Status.Pending;
            context.MoneyIns.Add(moneyIn);
            int result = await context.SaveChangesAsync();

            return(result > 0);
        }
コード例 #3
0
        public async Task <bool> TryToApplyFinancial(long contractId)
        {
            Premium pendingPremium = this.context.Premiums.OrderBy(p => p.StartDate).FirstOrDefault(p => p.Contract.Id == contractId && p.Status == Data.Models.Financial.Enums.Status.Pending);
            MoneyIn pendingMoneyIn = this.context.MoneyIns.OrderBy(p => p.RecordDate).FirstOrDefault(p => p.Contract.Id == contractId && p.Status == Data.Models.Financial.Enums.Status.Pending);

            if (pendingPremium != null && pendingMoneyIn != null)
            {
                pendingPremium.Status  = Data.Models.Financial.Enums.Status.Paid;
                pendingPremium.MoneyIn = pendingMoneyIn;
                pendingMoneyIn.Status  = Data.Models.Financial.Enums.Status.Paid;
                int result = await context.SaveChangesAsync();

                return(result > 0);
            }
            return(false);
        }