Пример #1
0
 public void Update(API.User user)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         dataGateway.UpdateEntity(user);
     }
 }
Пример #2
0
        public async Task <Guid> Create(API.User user, string password, string[] groups, CancellationToken cancellation)
        {
            if (await Connection.ExistsAsync <DAL.Login>(l => l.EmailOrUserName == user.EmailOrUserName && l.DeletedUtc == null, cancellation))
            {
                throw new InvalidOperationException(Resources.USER_ALREADY_EXISTS);
            }

            Guid[] groupIds = (await Connection.SelectAsync <DAL.Group>(grp => Sql.In(grp.Name, groups.Distinct()), cancellation))
                              .Select(grp => grp.Id)
                              .ToArray();
            if (groupIds.Length != groups.Length)
            {
                throw new InvalidOperationException(Resources.INVALID_GROUP);
            }

            using (IBulkedDbConnection bulk = Connection.CreateBulkedDbConnection())
            {
                var loginEntry = new DAL.Login
                {
                    EmailOrUserName = user.EmailOrUserName,
                    PasswordHash    = HashPassword(password, GenerateSalt())
                };
                bulk.Insert(loginEntry);
                Debug.Assert(loginEntry.Id != Guid.Empty);

                var userEntry = new DAL.User
                {
                    LoginId  = loginEntry.Id,
                    FullName = user.FullName
                };
                bulk.Insert(userEntry);
                Debug.Assert(userEntry.Id != Guid.Empty);

                //
                // Don't use InsertAll() since it gives the same Id for each entry
                //

                foreach (Guid groupId in groupIds)
                {
                    var ug = new DAL.UserGroup
                    {
                        GroupId = groupId,
                        UserId  = userEntry.Id
                    };
                    bulk.Insert(ug);
                    Debug.Assert(ug.Id != Guid.Empty);
                }

                await bulk.FlushAsync(cancellation);

                return(userEntry.Id);
            }
        }
Пример #3
0
        public async Task QueryByCredentials_ShouldReturnTheProperEntry()
        {
            await UserRepository.Create(new API.User {
                FullName = "cica1", EmailOrUserName = "******"
            }, "mica1", Array.Empty <string>());

            API.User user = null;
            Assert.DoesNotThrowAsync(async() => user = await UserRepository.QueryByCredentials("*****@*****.**", "mica1"));

            Assert.That(user, Is.Not.Null);
            Assert.That(user.EmailOrUserName, Is.EqualTo("*****@*****.**"));
            Assert.That(user.FullName, Is.EqualTo("cica1"));
        }
Пример #4
0
 public async Task <Guid> Create(API.User user, string pw, string[] groups) => await UserRepository
 .Create(Mapper.Map <DAL.API.User>(user), pw, groups, RequestContext.Cancellation);