Ejemplo n.º 1
0
 public ProductsService(
     EShopDbContext context,
     IWebHostEnvironment env)
 {
     _env     = env;
     _context = context;
 }
Ejemplo n.º 2
0
 public AccountService(UserManager <User> userManager, SignInManager <User> signInManager, IConfiguration config, EShopDbContext eShopDbContext)
 {
     this.userManager    = userManager;
     this.signInManager  = signInManager;
     this.eShopDbContext = eShopDbContext;
     this.config         = config;
 }
Ejemplo n.º 3
0
        public async Task <List <Product> > LoadName(string prefix)
        {
            var context = new EShopDbContext();

            context.Configuration.ProxyCreationEnabled = false;
            return(await context.Products.AsNoTracking().Where(x => x.ProductName.Contains(prefix)).ToListAsync());
        }
Ejemplo n.º 4
0
        public ProductService(EShopDbContext context, IStorageService storageService) // phải refrnece từ tầng data để lấy EShopDBContext
        {
            _context = context;                                                       // thằng Di nó sẽ tự tiêm vào đây cho chúng ta và

            // tiêm thằng storService
            _storageService = storageService;
        }
Ejemplo n.º 5
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.UseEnvironment("Testing");

            builder.ConfigureServices(services =>
            {
                services.AddEntityFrameworkInMemoryDatabase();

                var provider = services
                               .AddEntityFrameworkInMemoryDatabase()
                               .BuildServiceProvider();

                services.AddDbContext <EShopDbContext>(options =>
                {
                    options.UseInMemoryDatabase($"InMemoryDbForTesting-{Guid.NewGuid()}");
                    options.UseInternalServiceProvider(provider);
                });

                var serviceProvider = services.BuildServiceProvider();

                var scope = serviceProvider.CreateScope();

                var scopedServices = scope.ServiceProvider;

                Context = scopedServices.GetRequiredService <EShopDbContext>();

                Context.Database.EnsureCreated();

                SeedData.Seed(Context);
            });
        }
Ejemplo n.º 6
0
 public CommanderController(
     ICommanderService commander,
     EShopDbContext context
     )
 {
     _commander = commander;
     _context   = context;
 }
Ejemplo n.º 7
0
 public SpaceshipController(
     EShopDbContext context,
     ISpaceshipService spaceshipService
     )
 {
     _context          = context;
     _spaceshipService = spaceshipService;
 }
Ejemplo n.º 8
0
 public BlogService(EShopDbContext context,
                    IStorageService storageService,
                    UserManager <UserApp> userManager)
 {
     _context        = context;
     _storageService = storageService;
     _userManager    = userManager;
 }
Ejemplo n.º 9
0
        public override void OnActionExecuting(ActionExecutingContext ctx)
        {
            // Lấy địa chỉ action được yêu cầu
            var AbsoluteUri = HttpContext.Current.Request.Url.AbsoluteUri;

            /*
             * 1. Không kiểm tra ngoài vùng Admin và Home/Login
             */
            if (!AbsoluteUri.Contains("/admin/") || AbsoluteUri.Contains("/admin/home/login"))
            {
                return;
            }

            /*
             * 2. Bắt buộc phải đăng nhập khi vào bất kỳ trang nào của Admin
             */
            if (XSession.Master == null)
            {
                ctx.Controller.ViewData.ModelState.AddModelError("", "Vui lòng đăng nhập!");
                XSession.ReturnUrl = AbsoluteUri;
                ctx.Result         = new RedirectResult("/admin/home/login");
                return;
            }

            // Lấy tên action được truy cập và đổi sang chữ thường để phù hợp với CSDL
            var actionName = (ctx.ActionDescriptor.ControllerDescriptor.ControllerName + "/" + ctx.ActionDescriptor.ActionName).ToLower();

            using (var dbc = new EShopDbContext())
            {
                /*
                 * 3. Không kiểm tra những action không nhập vào WebActions
                 */
                if (!dbc.WebActions.Any(a => a.Name == actionName))
                {
                    return;
                }
                // Vai trò của Master đăng nhập
                var rolesOfMaster = dbc.MasterRoles
                                    .Where(mr => mr.MasterId == XSession.Master.Id)
                                    .Select(mr => mr.RoleId)
                                    .ToList();
                // Vai trò cho phép truy cập actionName
                var rolesAllow = dbc.ActionRoles
                                 .Where(ar => ar.WebAction.Name == actionName)
                                 .Select(ar => ar.RoleId)
                                 .ToList();

                /*
                 * 4. Kiểm tra Master có được cấp quyền sử dụng actionName này hay không
                 */
                if (!rolesOfMaster.Any(roleId => rolesAllow.Contains(roleId)))
                {
                    ctx.Controller.ViewData.ModelState.AddModelError("", "Bạn không được cấp quyền để thực hiện chức năng này!");
                    XSession.ReturnUrl = AbsoluteUri;
                    ctx.Result         = new RedirectResult("/admin/home/login");
                }
            }
        }
Ejemplo n.º 10
0
 public void Dispose()
 {
     if (context == null)
     {
         return;
     }
     context.Dispose();
     context = null;
 }
Ejemplo n.º 11
0
 public UserService(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager
                    , RoleManager <AppRole> roleManager, IConfiguration config, EShopDbContext context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _roleManager   = roleManager;
     _config        = config;
     _context       = context;
 }
Ejemplo n.º 12
0
 public void Dispose()
 {
     if (_context == null)
     {
         return;
     }
     _context.Dispose();
     _context = null;
 }
Ejemplo n.º 13
0
 public ProductController
 (
     IProductService productService,
     EShopDbContext context,
     IWebHostEnvironment env
 )
 {
     _productService = productService;
     _context        = context;
     _env            = env;
 }
Ejemplo n.º 14
0
 public UserService(UserManager <UserApp> userManager,
                    SignInManager <UserApp> signInManager,
                    RoleManager <RoleApp> roleManager,
                    IConfiguration configuration,
                    EShopDbContext context,
                    IStorageService storageService)
 {
     _userManager    = userManager;
     _signInManager  = signInManager;
     _roleManager    = roleManager;
     _configuration  = configuration;
     _storageService = storageService;
     _context        = context;
 }
 public AuthService(UserManager <AppUser> userManager, EShopDbContext context,
                    SignInManager <AppUser> signInManager,
                    RoleManager <AppRole> roleManager,
                    IConfiguration config, ILogger <AuthService> logger,
                    IEmailService emailService, UrlEncoder urlEncoder)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _context       = context;
     _roleManager   = roleManager;
     _config        = config;
     _logger        = logger;
     _emailService  = emailService;
     _urlEncoder    = urlEncoder;
 }
Ejemplo n.º 16
0
        public static async Task <ApiResult <bool> > SaveChangeAsyncNotImage(EShopDbContext _context)
        {
            try
            {
                var change = await _context.SaveChangesAsync();

                if (change > 0)
                {
                    return(new ApiResultSuccess <bool>());
                }
                else
                {
                    return(new ApiResultErrors <bool>("Faild"));
                }
            }
            catch (Exception ex)
            {
                return(new ApiResultErrors <bool>(ex.InnerException.Message));
            }
        }
Ejemplo n.º 17
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            Database.SetInitializer(new DropCreateDatabaseIfModelChanges <EShopDbContext>());

            ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());

            using (var context = new EShopDbContext())
            {
                var ur = context.Users.Count();
                if (ur == 0)
                {
                    var user1 = new User()
                    {
                        LoginName = "Elvin",
                        Password  = "******",
                        Email     = "*****@*****.**",
                        Position  = PositionEnum.Admin,
                        Status    = StatusEnum.Active
                    };
                    var user2 = new User()
                    {
                        LoginName = "Zamir",
                        Password  = "******",
                        Email     = "*****@*****.**",
                        Position  = PositionEnum.Admin,
                        Status    = StatusEnum.Active
                    };
                    context.Users.Add(user1);
                    context.Users.Add(user2);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 18
0
        public override void OnActionExecuting(ActionExecutingContext ctx)
        {
            var uri = ctx.HttpContext.Request.Url.AbsoluteUri;

            if (!uri.Contains("/Admin/") || uri.Contains("/Admin/Home"))
            {
                return;
            }

            var Master = HttpContext.Current.Session["Master"] as Master;

            if (Master == null)
            {
                HttpContext.Current.Session["ReturnUrl"] = HttpContext.Current.Request.Url.AbsoluteUri;
                ctx.Result = new RedirectResult("/Admin/Home/Login?Reason=Chua dang nhap");
                return;
            }

            var action = (ctx.ActionDescriptor.ControllerDescriptor.ControllerName + "/" + ctx.ActionDescriptor.ActionName).ToLower();

            using (var dbc = new EShopDbContext())
            {
                if (!dbc.WebActions.Any(wa => wa.Name == action))
                {
                    return;
                }

                var RoleIds = dbc.MasterRoles
                              .Where(mr => mr.MasterId == Master.Id)
                              .Select(mr => mr.RoleId);

                if (dbc.ActionRoles
                    .Any(ar => ar.WebAction.Name == action && RoleIds.Contains(ar.RoleId)))
                {
                    return;
                }

                HttpContext.Current.Session["ReturnUrl"] = HttpContext.Current.Request.Url.AbsoluteUri;
                ctx.Result = new RedirectResult("/Admin/Home/Login?Reason=Chua cap quyen");
            }
        }
Ejemplo n.º 19
0
        public static async Task <ApiResult <bool> > SaveChangeAsyncImage(EShopDbContext context, string imagePath, IStorageService storageService)
        {
            try
            {
                var change = await context.SaveChangesAsync();

                if (change > 0)
                {
                    await storageService.DeleteFileAsync(imagePath);

                    return(new ApiResultSuccess <bool>());
                }
                else
                {
                    return(new ApiResultErrors <bool>("Update faild"));
                }
            }
            catch (Exception ex)
            {
                return(new ApiResultErrors <bool>(ex.InnerException.Message));
            }
        }
Ejemplo n.º 20
0
        public UnitOfWork(EShopDbContext context,
                          IGenericRepository <Order> OrderRepository,
                          IGenericRepository <Slide> SlideRepository,
                          IGenericRepository <Category> CategoryRepository,
                          IGenericRepository <CategoryTranslation> CategoryTranslationRepository,
                          IGenericRepository <Product> ProductRepository,
                          IGenericRepository <ProductTranslation> ProductTranslationRepository,
                          IGenericRepository <ProductImage> ProductImageRepository,
                          IGenericRepository <ProductInCategory> ProductInCategoryRepository,
                          IGenericRepository <Language> LanguageRepository

                          )
        {
            this.context                       = context;
            this.OrderRepository               = OrderRepository;
            this.SlideRepository               = SlideRepository;
            this.CategoryRepository            = CategoryRepository;
            this.CategoryTranslationRepository = CategoryTranslationRepository;
            this.ProductRepository             = ProductRepository;
            this.ProductTranslationRepository  = ProductTranslationRepository;
            this.ProductImageRepository        = ProductImageRepository;
            this.ProductInCategoryRepository   = ProductInCategoryRepository;
            this.LanguageRepository            = LanguageRepository;
        }
Ejemplo n.º 21
0
 public SlideService(EShopDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 22
0
 public RatingService(EShopDbContext eShopDbContext)
 {
     this.eShopDbContext = eShopDbContext;
 }
Ejemplo n.º 23
0
 public CategoryService(EShopDbContext eShopDbContext)
 {
     this.eShopDbContext = eShopDbContext;
 }
Ejemplo n.º 24
0
 public OrderService(EShopDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 25
0
 public SapceshipServices(
     EShopDbContext context
     )
 {
     _context = context;
 }
Ejemplo n.º 26
0
        public static void Initialize(EShopDbContext context)
        {
            context.Database.Migrate();

            //Seed data here if necessary
        }
Ejemplo n.º 27
0
 public GeneralRepository(EShopDbContext DbContext)
 {
     this.DbContext = DbContext;
 }
Ejemplo n.º 28
0
 public LanguageService(EShopDbContext context,
                        IConfiguration config)
 {
     _config  = config;
     _context = context;
 }
Ejemplo n.º 29
0
 public PublishProductService(EShopDbContext context)
 {
     _context = context;
 }
Ejemplo n.º 30
0
 public CommentService(EShopDbContext context)
 {
     _context = context;
 }