public void SeedData()
 {
     if (!_context.Users.Any())
     {
         var user1 = new User
         {
             CreateDate   = DateTime.Now,
             Email        = "*****@*****.**",
             FullName     = "مبین حسنی",
             IsActive     = true,
             IsAdmin      = true,
             UserName     = "******",
             SerialNumber = SerialNumberGenerator.Generate(),
             Password     = PasswordHasher.Hash("2397423974"),
         };
         var user2 = new User
         {
             CreateDate   = DateTime.Now,
             Email        = "*****@*****.**",
             FullName     = "مهدی حسنی",
             IsActive     = true,
             IsAdmin      = true,
             UserName     = "******",
             SerialNumber = SerialNumberGenerator.Generate(),
             Password     = PasswordHasher.Hash("2397423974"),
         };
         _context.Users.Add(user1);
         _context.Users.Add(user2);
         _context.SaveChanges();
     }
 }
Exemple #2
0
        public async Task <RegisterResultViewModel> CreateAsync(string userName, string password, string fullName)
        {
            var result       = new RegisterResultViewModel();
            var serialNumber = SerialNumberGenerator.Generate();
            var user         = _context.Users.Add(new User
            {
                CreateDate   = DateTime.Now,
                Email        = userName,
                FullName     = fullName,
                IsActive     = true,
                IsAdmin      = false,
                Password     = PasswordHasher.Hash(password),
                UserName     = userName,
                SerialNumber = serialNumber
            });

            if (await _context.SaveChangesAsync() > 0)
            {
                result.IsSuccess    = true;
                result.SerialNumber = serialNumber;
                result.UserId       = user.Entity.Id;
            }
            else
            {
                result.IsSuccess = false;
            }
            return(result);
        }
Exemple #3
0
        public void TestMethod1()
        {
            var g = new SerialNumberGenerator();

            for (int i = 0; i < 20; i++)
            {
                Console.WriteLine(g.Generate());
            }
        }