public async Task PaymentEditTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var payment = new PaymentsInputViewModel
            {
                Date          = DateTime.UtcNow.Date,
                PaymentSource = "каса",
                Value         = 100
            };

            var service = new PaymentsService(dbContext);

            var paymentEdited = new PaymentsEditViewModel
            {
                Date          = DateTime.UtcNow.Date.AddDays(10),
                PaymentSource = "каса",
                Value         = 1000
            };

            await service.CreateAsync(payment);

            var result = service.EditAsync(paymentEdited);

            Assert.True(result.IsCompletedSuccessfully);
            Assert.NotNull(result);
        }
        public IActionResult Create()
        {
            var viewModel = new PaymentsInputViewModel
            {
                LawCases = this.paymentsService.AllLawCasesId()
            };

            return(this.View(viewModel));
        }
        public async Task <IActionResult> Create(PaymentsInputViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.paymentsService.CreateAsync(model);

            return(this.RedirectToAction("All"));
        }
Beispiel #4
0
        public async Task CreateAsync(PaymentsInputViewModel model)
        {
            var payment = new Payment
            {
                Date          = model.Date,
                LawCaseId     = model.LawCaseId,
                PaymentSource = Enum.Parse <PaymentSource>(model.PaymentSource, true),
                Value         = model.Value,
            };

            await this.dbContext.Payments.AddAsync(payment);

            await this.dbContext.SaveChangesAsync();
        }
Beispiel #5
0
        public IActionResult CreatePayment(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var payment = new PaymentsInputViewModel
            {
                LawCaseId = (int)id,
                Date      = DateTime.UtcNow.Date,
            };

            return(this.View(payment));
        }
Beispiel #6
0
        public async Task <IActionResult> CreatePayment(PaymentsInputViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await this.service.CreatePayment(model);

                    //return this.Redirect($"https://localhost:44342/DebitorsCases/Home/Details/{model.LawCaseId}");
                    return(this.RedirectToAction("AllPayments", new { id = model.LawCaseId }));
                }
                catch (Exception ex)
                {
                    this.ModelState.AddModelError(string.Empty, ex.Message);
                    this.ViewData["Message"] = "Възникна грешка.";
                }
            }
            return(this.View(model));
        }
Beispiel #7
0
        public async Task DebitorsCasesCreatePaymentTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb03");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var service = new DebitorsCasesService(dbContext);

            var model0 = new LawCase
            {
                AbNumber  = "13000300401",
                DebitorId = 11,
                Date      = DateTime.UtcNow.Date,
                Value     = 100,
            };

            dbContext.LawCases.Add(model0);
            await dbContext.SaveChangesAsync();

            var model = new PaymentsInputViewModel
            {
                Value         = 10,
                Date          = DateTime.UtcNow.Date,
                LawCaseId     = 1,
                PaymentSource = "каса",
            };
            await service.CreatePayment(model);

            var x      = dbContext.LawCases.Where(x => x.DebitorId == 11).Select(x => x.AbNumber).FirstOrDefault();
            var pay    = dbContext.Payments.Where(x => x.LawCaseId == 1).Select((x => x.Id)).FirstOrDefault();
            var result = service.CaseDetails(1);

            Assert.NotNull(result);
            Assert.Equal("13000300401", x);
            Assert.True(result.IsCompletedSuccessfully);
            //Assert.Equal(1, pay);
        }