Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(PaymentsEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }
            await this.paymentsService.EditAsync(model);

            return(this.RedirectToAction("All"));
        }
Ejemplo n.º 3
0
        //public async Task<PaymentsEditViewModel> EditAsync(int? id)
        //{
        //    return await this.dbContext.Payments.Where(x => x.Id == id).Select(x => new PaymentsEditViewModel
        //    {
        //        Id = x.Id,
        //        Date = x.Date,
        //        LawCaseId = x.LawCaseId,
        //        PaymentSource = x.PaymentSource.ToString(),
        //        Value = x.Value,
        //    }).FirstOrDefaultAsync();
        //}

        public async Task EditAsync(PaymentsEditViewModel model)
        {
            var payment = new Payment
            {
                Id            = model.Id,
                Date          = model.Date,
                LawCaseId     = model.LawCaseId,
                PaymentSource = Enum.Parse <PaymentSource>(model.PaymentSource, true),
                Value         = model.Value,
            };

            this.dbContext.Update(payment);
            await this.dbContext.SaveChangesAsync();
        }
 protected override void OnAddClickedCommand()
 {
     EditViewModelInstance             = new PaymentsEditViewModel(Repository, PaymentsViewRepository);
     EditViewModelInstance.CloseEvent += () => EditViewModelInstance = null;
 }