예제 #1
0
        public static async Task ClearDatabase(CursedAuthenticationContext context)
        {
            await context.Role.ClearIfAny();

            await context.UserData.ClearIfAny();

            await context.UserAuth.ClearIfAny();

            await context.SaveChangesAsync();
        }
예제 #2
0
        /// <summary>
        /// Add new user.
        /// </summary>
        /// <param name="model">User to be added</param>
        /// <returns>Added user data with correct key(Id) value</returns>
        public async Task <UserData> AddDataModelAsync(RegistrationModel model)
        {
            var userData = new UserData
            {
                Login    = model.Login,
                RoleName = model.RoleName
            };
            var userAuth = new UserAuth
            {
                Login        = model.Login,
                PasswordHash = genPasswordHash.GenerateHash(model.Password)
            };

            var entity = db.Add(userData);

            db.Add(userAuth);
            await db.SaveChangesAsync();

            return(entity.Entity);
        }