Example #1
0
 public async Task<User> AddUserAsync(User user)
 {
     using (var uow = this.GetIoCManager() .DefualtContainer.Resolve<IUnitOfWork>())
     {
         var repo = uow.GetRepository<User>();
         repo.Add(user);
         await uow.SubmitAsync();
         this.ResolveLogger()?.Debug?.Log("User Added"); 
     }
     return user;
 }
Example #2
0
        public async Task RemoveUserAsync(User user)
        {
            using (var uow = this.GetIoCManager().DefualtContainer.Resolve<IUnitOfWork>())
            {
                var repo = uow.GetRepository<User>();
                await repo.AttachAndMarkChangesOrAddAsync(user);
                repo.Remove(user);
                await uow.SubmitAsync();
            }

        }
Example #3
0
        public async Task<User> UpdateUserAsync(User user)
        {
            using (var uow = this.GetIoCManager().DefualtContainer.Resolve<IUnitOfWork>())
            {
                var repo = uow.GetRepository<User>();
                var target = await repo
                    .Entities.Where(x => x.Id == user.Id)
                    .SingleAsync();
                Mapper.DynamicMap(user, target);
                await uow.SubmitAsync();
                return target;
            }

        }
Example #4
0
		public async Task Connect()
		{
			using (var uow = IoCManager.Instance.DefualtContainer.Resolve<IUnitOfWork>())
			{
				Assert.IsNotNull(uow, "UOW解析失败");
				Assert.IsNotNull(uow.GetUOWCore(), "UOW内部的DbContext解析失败");
				var u = new User() { Name = "Test" };
				var repo = uow.GetRepository<User>();
				var count = await repo.Entities.CountAsync();
				repo.Add(u);
				await uow.SubmitAsync();
				Assert.AreNotEqual(0, u.Id);
				repo.Remove(u);
				await uow.SubmitAsync();
				Assert.AreEqual(await repo.Entities.CountAsync(), count);
			}
		}
Example #5
0
		public async Task CreateAUserAndAGroup()
		{
			var u = new User()
			{
				Name = "User" + Guid.NewGuid().ToString()
			};

			var g = new Group()
			{
				Name = "Group" + Guid.NewGuid().ToString()
			};

			var userService = IoCManager.Instance.DefualtContainer.Resolve<IUserService>();
			var groupService = IoCManager.Instance.DefualtContainer.Resolve<IGroupService>();
			g.Users = g.Users ?? new HashSet<User>();
			u = await userService.AddUserAsync(u);
			g.Users.Add(u);
			g = await groupService.AddGroupAsync(g);

			var u2 = await userService.GetUserAsync(u.Id);
			Assert.AreEqual(u2.GroupId.Value, g.Id);

		}