コード例 #1
0
        public async Task ExecutorsEditTest()
        {
            var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                .UseInMemoryDatabase("testDb2");
            var dbContext = new ApplicationDbContext(optionBuilder.Options);

            var service = new ExecutorService(dbContext);

            var executor = new ExecutorsCreateViewModel
            {
                Name    = "Иван Хаджииванов",
                Address = "ул. Александровска 44",
                Number  = "832",
                Region  = "Русе",
            };

            await service.CreateAsync(executor);

            var executorEdited = new ExecutorsEditViewModel
            {
                Name    = "Иван Хаджииванов2",
                Address = "ул. Александровска 44-2",
                Number  = "832-2",
                Region  = "Русе2",
            };

            var result = service.EditAsync(executorEdited);

            Assert.NotNull(result);
            //Assert.Equal(2, result.Id);
        }
コード例 #2
0
        public async Task <IActionResult> Edit(ExecutorsEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }
            await this.executorService.EditAsync(model);

            return(this.RedirectToAction("All"));
        }
コード例 #3
0
        public async Task EditAsync(ExecutorsEditViewModel model)
        {
            var executor = new Executor
            {
                Id       = model.Id,
                Address  = model.Address,
                Email    = model.Email,
                Name     = model.Name,
                Number   = model.Number,
                Region   = model.Region,
                Telephon = model.Telephon,
            };

            this.dbContext.Update(executor);
            await this.dbContext.SaveChangesAsync();
        }