Example #1
0
        public async Task ExecutorCasessEditTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb2");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var service = new ExecutorsCasesService(dbContext);

            var executorCases = new ExecutorsCasesCreateViewModel
            {
                ExecutorCaseNumber = 123,
                Year = 2020,
            };

            await service.CreateAsync(executorCases);

            var ExecutorCasesEdited = new ExecutorsCasesEditViewModel
            {
                ExecutorCaseNumber = 12333,
                Year = 2015,
            };

            var result = service.EditAsync(ExecutorCasesEdited);

            Assert.NotNull(result);
            //Assert.Equal(2, result.Id);
        }
        public async Task <IActionResult> Create(ExecutorsCasesCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }
            await this.executorsCasesService.CreateAsync(model);

            return(this.RedirectToAction("All"));
        }
        public IActionResult Create()
        {
            var viewModel = new ExecutorsCasesCreateViewModel
            {
                Executors = this.executorsCasesService.GetAllExecutors(),
                LawCases  = this.executorsCasesService.GetAllLawCases(),
            };

            return(this.View(viewModel));
        }
        public async Task CreateAsync(ExecutorsCasesCreateViewModel model)
        {
            var executorsCase = new ExecutorCase
            {
                LawCaseId          = model.LawCaseId,
                ExecutorId         = model.ExecutorId,
                ExecutorCaseNumber = model.ExecutorCaseNumber,
                Year = model.Year,
            };

            await this.dbContext.ExecutorCases.AddAsync(executorsCase);

            await this.dbContext.SaveChangesAsync();
        }