Exemple #1
0
        public async Task <bool> RegisterUserAsync(User user)
        {
            try
            {
                dataContext.Roles.Add(new Role {
                    RoleName = "Administrator"
                });
                dataContext.Roles.Add(new Role {
                    RoleName = "RegularUser"
                });
                dataContext.SaveChanges();

                if (user == null)
                {
                    return(false);
                }
                var password = user.PasswordHash;
                user.PasswordHash = Encryption.Encryption.MD5Hash(password);
                user.Id           = $"HYG - {new Random().Next(1111111,9999999)}";

                await hygieaManager.AddUserAsync(user);

                await roleServices.AddUserToRole("RegularUser", user.Id);

                await utilitiesServices.RegistrationSuccessEmail(user.Id);

                return(true);
            }
            catch { return(false); }
        }