public async Task Update_ChildrenAction_Test()
        {
            //Arrange
            await UsingDbContext(async context =>
            {
                context.Region.Add(new Region
                {
                    Name         = "beijing",
                    FullName     = "beijing",
                    Code         = "00001",
                    Level        = 1,
                    MyCustomData = "beijing"
                });
                await context.SaveChangesAsync();

                context.Region.Add(new Region
                {
                    Name     = "xicheng",
                    FullName = "beijing-xicheng",
                    Code     = "00001.00001",
                    Level    = 2,
                    ParentId = 1
                });
                await context.SaveChangesAsync();

                //Act
                var beijing  = context.Region.First(x => x.Name == "beijing");
                beijing.Name = "newbeijing";
                await _generalRegionTreeManager.UpdateAsync(beijing, x => { x.MyCustomData = x.Code; });
                await context.SaveChangesAsync();
            });

            UsingDbContext(context =>
            {
                //Assert
                var xicheng = context.Region.First(x => x.Name == "xicheng");
                xicheng.MyCustomData.ShouldBe("00001.00001");
            });
        }
Ejemplo n.º 2
0
        public async Task Update_Name_Child_FullName_ShouldBe_Update_Test()
        {
            await UsingDbContextAsync(async context =>
            {
                //Arrange
                context.Region.Add(new Region
                {
                    Name     = "beijing",
                    FullName = "beijing",
                    Code     = "00001",
                    Level    = 1
                });
                await context.SaveChangesAsync();

                context.Region.Add(new Region
                {
                    Name     = "xicheng",
                    FullName = "beijing-xicheng",
                    Code     = "00001.00001",
                    Level    = 2,
                    ParentId = 1
                });
                await context.SaveChangesAsync();

                //Act
                var beijing  = context.Region.First(x => x.Name == "beijing");
                beijing.Name = "newbeijing";
                await _generalRegionTreeManager.UpdateAsync(beijing);
                await context.SaveChangesAsync();
            });

            UsingDbContext(context =>
            {
                //Assert
                var xicheng = context.Region.First(x => x.Name == "xicheng");
                xicheng.FullName.ShouldBe("newbeijing-xicheng");
            });
        }
Ejemplo n.º 3
0
        public async Task <MenuDto> CreateOrUpdateMenuForOutput(MenuDto input)
        {
            if (input.Id.HasValue)
            {
                var menu = await _menuRepository.GetAsync(input.Id.Value);

                ObjectMapper.Map(input, menu);
                await _menuTreeManager.UpdateAsync(menu);

                return(ObjectMapper.Map <MenuDto>(menu));
            }
            else
            {
                var menu = ObjectMapper.Map <Menu>(input);
                await _menuTreeManager.CreateAsync(menu);

                await CurrentUnitOfWork.SaveChangesAsync();

                return(ObjectMapper.Map <MenuDto>(menu));
            }
        }
 public async Task UpdateAsync(Warehouse warehouse)
 {
     await _generalWarehouseTreeManager.UpdateAsync(warehouse);
 }