Exemplo n.º 1
0
        private void SeedProducts(ListItDataContext context)
        {
            foreach (var user in context.Users)
            {
                int randomNumber = Faker.NumberFaker.Number(0, 5);

                for (int i = 0; i < randomNumber; i++)
                {
                    var product = new Product
                    {
                        UserId      = user.Id,
                        Active      = Faker.BooleanFaker.Boolean(),
                        Amount      = Faker.NumberFaker.Number(10, 2000).ToString(),
                        CategoryId  = Faker.NumberFaker.Number(1, context.Categories.Count()),
                        Condition   = Faker.NumberFaker.Number(1, 6),
                        Description = Faker.TextFaker.Sentences(2),
                        Name        = Faker.TextFaker.Sentence(),
                        Posted      = Faker.DateTimeFaker.DateTime(DateTime.Now.AddYears(-1), DateTime.Now)
                    };

                    context.Products.Add(product);
                }
            }

            context.SaveChanges();
        }
Exemplo n.º 2
0
        private void SeedUsers(ListItDataContext context)
        {
            var userStore = new UserStore <User>(context);

            using (var manager = new UserManager <User>(userStore))
            {
                for (int i = 0; i < 3; i++)
                {
                    var randomEmail = Faker.InternetFaker.Email();

                    manager.Create(new User
                    {
                        BirthDate   = Faker.DateTimeFaker.BirthDay(),
                        Email       = randomEmail,
                        FirstName   = Faker.NameFaker.FirstName(),
                        LastName    = Faker.NameFaker.LastName(),
                        PhoneNumber = Faker.PhoneFaker.Phone(),
                        UserName    = randomEmail,
                        ZipCode     = Faker.LocationFaker.ZipCode()
                    }, "password123");
                }
            }

            context = new ListItDataContext();
        }
Exemplo n.º 3
0
        public UsersController()
        {
            db = new ListItDataContext();
            var store = new UserStore <User>(db);

            _userManager = new UserManager <User>(store);
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

            var db    = new ListItDataContext();
            var store = new UserStore <User>(db);

            using (var manager = new UserManager <User>(store))
            {
                var user = manager.Find(context.UserName, context.Password);

                if (user == null)
                {
                    context.SetError("invalid_grant", "Incorrect username or password");
                    return;
                }
            }

            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
            identity.AddClaim(new Claim(ClaimTypes.Role, "user"));

            context.Validated(identity);
        }
Exemplo n.º 5
0
        private void SeedCategories(ListItDataContext context)
        {
            context.Categories.AddOrUpdate(
                c => c.Name,
                new Category {
                Name = "Antique"
            },
                new Category {
                Name = "Appliances"
            },
                new Category {
                Name = "Bikes"
            },
                new Category {
                Name = "Boats"
            },
                new Category {
                Name = "Cars"
            },
                new Category {
                Name = "Books"
            },
                new Category {
                Name = "Phones"
            },
                new Category {
                Name = "Trailers"
            },
                new Category {
                Name = "Video Games"
            },
                new Category {
                Name = "Electronics"
            },
                new Category {
                Name = "Wanted"
            },
                new Category {
                Name = "Other"
            }
                );

            context.SaveChanges();
        }