Beispiel #1
0
 public UserRepository(UserManager <ApplicationUser> userManager,
                       BlogHostingDbContext context, SignInManager <ApplicationUser> signInManager)
 {
     _userManager   = userManager;
     _context       = context;
     _signInManager = signInManager;
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            var services = new ServiceCollection();

            ConfigureServices(services);
            serviceProvider = services.BuildServiceProvider();

            var optionsBuilder = new DbContextOptionsBuilder <BlogHostingDbContext>();

            optionsBuilder
            .UseLazyLoadingProxies()
            .UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=aspnet-BlogHosting-123BCBEF-17A2-4F0F-8B69-F13F4F2ADE44;Trusted_Connection=True;MultipleActiveResultSets=true");

            //var userManager = serviceProvider.GetRequiredService<UserManager<ApplicationUser>>();
            var signInManager = serviceProvider.GetRequiredService <SignInManager <DAL.Interface.DTO.ApplicationUser> >();

            using (var context = new BlogHostingDbContext(optionsBuilder.Options))
            {
                var rep = new UserRepository(serviceProvider.GetRequiredService <UserManager <DAL.Interface.DTO.ApplicationUser> >(), context, signInManager);

                var service = new AuthenticateService(rep);

                //var user =  service.GetUserByUsernamee("User1");

                //Console.WriteLine(user.FirstName);
            }
        }
Beispiel #3
0
        public static void DetachLocal <T>(this BlogHostingDbContext context, T t, int entryId) where T : class
        {
            var local = context.Set <T>()
                        .Local
                        .FirstOrDefault(entry => entry.GetType().GetProperties()
                                        .Single(p => p.Name.EndsWith("Id"))
                                        .GetValue(entry).Equals(entryId));

            if (local != null)
            {
                context.Entry(local).State = EntityState.Detached;
            }

            context.Entry(t).State = EntityState.Modified;
        }
Beispiel #4
0
 public BlogRepository(BlogHostingDbContext context)
 {
     _context = context;
 }