public static void Seed(EshopDbContext context)
        {
            context.ProductStates.RemoveRange(context.ProductStates);
            context.SaveChanges();

            var productStates = new List <ProductState>();

            productStates.Add(new ProductState()
            {
                Id   = new Guid("403d3f4d-3dcf-4516-8720-fc5f9db11b1d"),
                Name = "New",
                Code = 0
            });

            productStates.Add(new ProductState()
            {
                Id   = new Guid("c44cd351-69ea-4e20-80be-aecaa6d377dc"),
                Name = "In Catalog",
                Code = 1
            });

            productStates.Add(new ProductState()
            {
                Id   = new Guid("a7055d5f-d404-4756-94f9-9bd7271626ad"),
                Name = "Archived",
                Code = 2
            });

            context.ProductStates.AddRange(productStates);
            context.SaveChanges();
        }
Пример #2
0
 public ProductService(EshopDbContext context, IStorageService storageService,
                       ICategoryService categoryService)
 {
     _context         = context;
     _storageService  = storageService;
     _categoryService = categoryService;
 }
        public static void Seed(EshopDbContext context)
        {
            context.Vendors.RemoveRange(context.Vendors);
            context.SaveChanges();

            // init seed data
            Random random = new Random();

            var vendors = new List <Vendor>();

            for (int i = 0; i < 250; i++)
            {
                var dic = LoremNET.Lorem.Words(1).ToUpper();
                vendors.Add(new Vendor()
                {
                    Id        = Guid.NewGuid(),
                    Name      = LoremNET.Lorem.Words(2),
                    Director  = LoremNET.Lorem.Words(2),
                    Ico       = (int)LoremNET.Lorem.Number(123456789, 99999999),
                    Dic       = dic.Length > 12 ? dic.Substring(0, 11) : dic,
                    ContactId = ContactSeeder.GenerateContact(context)
                });
            }

            context.Vendors.AddRange(vendors);
            context.SaveChanges();
        }
Пример #4
0
 public UserService(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager,
                    IConfiguration configuration, EshopDbContext context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     //_roleManager = roleManager;
     _configuration = configuration;
     _context       = context;
 }
        public static void MapUserRole(EshopDbContext context, Guid userId, Guid roleId)
        {
            var userRole = new UserRole()
            {
                Id     = Guid.NewGuid(),
                UserId = userId,
                RoleId = roleId
            };

            context.UserRoles.Add(userRole);
        }
Пример #6
0
        public static void Seed(EshopDbContext context)
        {
            context.OrderStates.RemoveRange(context.OrderStates);
            context.SaveChanges();

            var orderStates = new List <OrderState>();

            orderStates.Add(new OrderState()
            {
                Id   = new Guid("251bffe2-9397-4424-97f9-95059b3d2262"),
                Name = "New",
                Code = 0
            });

            orderStates.Add(new OrderState()
            {
                Id   = new Guid("67aaa8f5-bb86-4dd2-bb8c-369a803fddbf"),
                Name = "Processing",
                Code = 1
            });

            orderStates.Add(new OrderState()
            {
                Id   = new Guid("60b720b7-6e0d-4139-8de6-ef6f111c690e"),
                Name = "Pending Payment",
                Code = 2
            });

            orderStates.Add(new OrderState()
            {
                Id   = new Guid("0b9bf938-8376-49b3-94fb-4e444522d507"),
                Name = "Canceled",
                Code = 3
            });

            orderStates.Add(new OrderState()
            {
                Id   = new Guid("c5f9d229-1c83-428a-8e88-9afac4cc0147"),
                Name = "Complete",
                Code = 4
            });

            context.OrderStates.AddRange(orderStates);
            context.SaveChanges();
        }
Пример #7
0
        public static Guid GenerateContact(EshopDbContext context)
        {
            Random random = new Random();

            var contact = new Contact()
            {
                Id        = Guid.NewGuid(),
                Telephone = (int)LoremNET.Lorem.Number(600000001, 799999999),
                Address1  = LoremNET.Lorem.Words(random.Next(1, 3)),
                Address2  = LoremNET.Lorem.Words(random.Next(0, 3)),
                Psc       = (int)LoremNET.Lorem.Number(10000, 49999),
                City      = LoremNET.Lorem.Words(1),
                State     = LoremNET.Lorem.Words(1)
            };

            context.Contacts.Add(contact);

            return(contact.Id);
        }
        public static void Seed(EshopDbContext context)
        {
            context.Roles.RemoveRange(context.Roles);
            context.UserRoles.RemoveRange(context.UserRoles);
            context.SaveChanges();

            var roles = new List <Role>();

            roles.Add(new Role()
            {
                Id   = new Guid("9d8329f1-82f5-4cbb-ba4b-955211457707"),
                Name = "Administrator",
                Code = "Admin"
            });

            roles.Add(new Role()
            {
                Id   = new Guid("4e7f583f-d4f1-4d7a-833e-693fbf99b6e9"),
                Name = "Manager",
                Code = "Manager"
            });

            roles.Add(new Role()
            {
                Id   = new Guid("7446d1fb-a305-440c-b6d9-53769dc1e08a"),
                Name = "Seller",
                Code = "Seller"
            });

            roles.Add(new Role()
            {
                Id   = new Guid("7bf2bcb3-9eb0-4e0d-a88b-9a6937bdee85"),
                Name = "Customer",
                Code = "Customer"
            });

            context.Roles.AddRange(roles);
            context.SaveChanges();
        }
 public CatalogController(EshopDbContext dbContext)
 {
     this.db = dbContext;
 }
Пример #10
0
 public StatisticService(EshopDbContext context, IOrderService orderSevice)
 {
     _context      = context;
     _orderService = orderSevice;
 }
Пример #11
0
 public LanguageService(EshopDbContext context)
 {
     _context = context;
 }
Пример #12
0
 public SlideService(EshopDbContext context)
 {
     this._context = context;
 }
Пример #13
0
 public BaseRepository(EshopDbContext context)
 {
     _context = context;
 }
Пример #14
0
        public static void Seed(EshopDbContext context)
        {
            context.Products.RemoveRange(context.Products);
            context.SaveChanges();

            // init seed data
            Random       random = new Random();
            const string chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";

            var vendors = context.Vendors.ToList();

            var products = new List <Product>();

            // Category 1 - GUID 25320c5e-f58a-4b1f-b63a-8ee07a840bdf
            for (int i = 0; i < 10; i++)
            {
                products.Add(new Product()
                {
                    Id             = Guid.NewGuid(),
                    Name           = LoremNET.Lorem.Words(2),
                    Description    = LoremNET.Lorem.Words(random.Next(4, 10)),
                    Price          = random.NextDouble() * (10.2 - 2550.4) + 2550.4,
                    CategoryId     = new Guid("25320c5e-f58a-4b1f-b63a-8ee07a840bdf"),
                    ProductStateId = new Guid("c44cd351-69ea-4e20-80be-aecaa6d377dc"),
                    VendorId       = vendors[random.Next(0, 249)].Id,
                    ProductNumber  = LoremNET.Lorem.Words(1),
                    ProductCode    = LoremNET.Lorem.Words(1),
                    StockCount     = random.Next(0, 100)
                });
            }

            // Category 1.1 - GUID a3749477-f823-4124-aa4a-fc9ad5e79cd6
            for (int i = 0; i < 20; i++)
            {
                products.Add(new Product()
                {
                    Id             = Guid.NewGuid(),
                    Name           = LoremNET.Lorem.Words(2),
                    Description    = LoremNET.Lorem.Words(random.Next(4, 10)),
                    Price          = random.NextDouble() * (10.2 - 255.4) + 10.2 * -1,
                    CategoryId     = new Guid("a3749477-f823-4124-aa4a-fc9ad5e79cd6"),
                    VendorId       = vendors[random.Next(0, 249)].Id,
                    ProductStateId = new Guid("c44cd351-69ea-4e20-80be-aecaa6d377dc"),
                    ProductNumber  = LoremNET.Lorem.Words(1),
                    ProductCode    = LoremNET.Lorem.Words(1),
                    StockCount     = random.Next(0, 100)
                });
            }

            // Category 2 - GUID 60188a2b-2784-4fc4-8df8-8919ff838b0b
            for (int i = 0; i < 10000; i++)
            {
                products.Add(new Product()
                {
                    Id             = Guid.NewGuid(),
                    Name           = LoremNET.Lorem.Words(2),
                    Description    = LoremNET.Lorem.Words(random.Next(4, 10)),
                    Price          = random.NextDouble() * (10.2 - 255.4) + 10.2 * -1,
                    CategoryId     = new Guid("60188a2b-2784-4fc4-8df8-8919ff838b0b"),
                    ProductStateId = new Guid("c44cd351-69ea-4e20-80be-aecaa6d377dc"),
                    VendorId       = vendors[random.Next(0, 249)].Id,
                    ProductNumber  = LoremNET.Lorem.Words(1),
                    ProductCode    = LoremNET.Lorem.Words(1),
                    StockCount     = random.Next(0, 100)
                });
            }

            context.Products.AddRange(products);
            context.SaveChanges();
        }
Пример #15
0
 public CategoryService(EshopDbContext eshopDbContext)
 {
     _context = eshopDbContext;
 }
        public static void Seed(EshopDbContext context)
        {
            context.Users.RemoveRange(context.Users);
            context.SaveChanges();

            // init seed data
            Random random = new Random();

            var users = new List <User>();
            var user  = new User()
            {
                Id        = new Guid("c5e75dd1-1661-424d-8745-e9a002563c27"),
                Username  = "******",
                Password  = PasswordHasher.CreateHash("admin123", "AN>1w`YqLNgY})adEzwyQI&qblGW}[5%9MH9de'Ov:R(}U?g/au!>#Mtxk=>@d"),
                Email     = "*****@*****.**",
                Firstname = "Jarmil",
                Lastname  = "Prdel",
                ContactId = ContactSeeder.GenerateContact(context)
            };

            users.Add(user);

            RolesSeeder.MapUserRole(context, user.Id, new Guid("9d8329f1-82f5-4cbb-ba4b-955211457707")); // administrator
            RolesSeeder.MapUserRole(context, user.Id, new Guid("4e7f583f-d4f1-4d7a-833e-693fbf99b6e9")); // manager
            RolesSeeder.MapUserRole(context, user.Id, new Guid("7446d1fb-a305-440c-b6d9-53769dc1e08a")); // seller


            // other dashboard managers
            for (int i = 0; i < 10; i++)
            {
                user = new User()
                {
                    Id        = Guid.NewGuid(),
                    Username  = LoremNET.Lorem.Words(1),
                    Email     = LoremNET.Lorem.Email(),
                    Password  = PasswordHasher.CreateHash("Test123", "AN>1w`YqLNgY})adEzwyQI&qblGW}[5%9MH9de'Ov:R(}U?g/au!>#Mtxk=>@d"),
                    Firstname = LoremNET.Lorem.Words(1),
                    Lastname  = LoremNET.Lorem.Words(1),
                    ContactId = ContactSeeder.GenerateContact(context)
                };
                users.Add(user);

                RolesSeeder.MapUserRole(context, user.Id, new Guid("4e7f583f-d4f1-4d7a-833e-693fbf99b6e9")); // manager
            }

            // customers
            for (int i = 0; i < 4000; i++)
            {
                var customer = new User()
                {
                    Id        = Guid.NewGuid(),
                    Username  = LoremNET.Lorem.Words(1),
                    Email     = LoremNET.Lorem.Email(),
                    Password  = PasswordHasher.CreateHash("Test123", "AN>1w`YqLNgY})adEzwyQI&qblGW}[5%9MH9de'Ov:R(}U?g/au!>#Mtxk=>@d"),
                    Firstname = LoremNET.Lorem.Words(1),
                    Lastname  = LoremNET.Lorem.Words(1),
                    ContactId = ContactSeeder.GenerateContact(context)
                };
                users.Add(customer);

                RolesSeeder.MapUserRole(context, customer.Id, new Guid("7bf2bcb3-9eb0-4e0d-a88b-9a6937bdee85")); // customer
            }

            context.Users.AddRange(users);
            context.SaveChanges();
        }
        public static void Seed(EshopDbContext context)
        {
            context.Categories.RemoveRange(context.Categories);
            context.SaveChanges();

            // init seed data

            var categories = new List <Category>();
            var category1  = new Category()
            {
                Id   = new Guid("25320c5e-f58a-4b1f-b63a-8ee07a840bdf"),
                Name = "Category 1",
            };

            categories.Add(category1);

            categories.Add(new Category()
            {
                Id       = new Guid("a3749477-f823-4124-aa4a-fc9ad5e79cd6"),
                Name     = "Category 1.1",
                ParentId = category1.Id
            });

            categories.Add(new Category()
            {
                Id       = Guid.NewGuid(),
                Name     = "Category 1.2",
                ParentId = category1.Id
            });

            categories.Add(new Category()
            {
                Id       = Guid.NewGuid(),
                Name     = "Category 1.3",
                ParentId = category1.Id
            });

            var category2 = new Category()
            {
                Id   = new Guid("60188a2b-2784-4fc4-8df8-8919ff838b0b"),
                Name = "Category 2"
            };

            categories.Add(category2);

            categories.Add(new Category()
            {
                Id       = Guid.NewGuid(),
                Name     = "Category 2.1",
                ParentId = category2.Id
            });

            categories.Add(new Category()
            {
                Id       = Guid.NewGuid(),
                Name     = "Category 2.2",
                ParentId = category2.Id
            });

            categories.Add(new Category()
            {
                Id   = Guid.NewGuid(),
                Name = "Category 3",
            });

            categories.Add(new Category()
            {
                Id   = Guid.NewGuid(),
                Name = "Category 4",
            });

            context.Categories.AddRange(categories);
            context.SaveChanges();
        }
Пример #18
0
 public OrderService(EshopDbContext context, IProductService productService)
 {
     _context        = context;
     _productService = productService;
 }
 public VendorRepository(EshopDbContext context, IConfiguration configuration, IPropertyMappingService propertyMappingService)
     : base(context)
 {
     _configuration          = configuration;
     _propertyMappingService = propertyMappingService;
 }
Пример #20
0
 public BaseRepository(EshopDbContext context)
 {
     _context = context;
     _dbSet   = context.Set <TEntity>();
 }
Пример #21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, EshopDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //dbContext.EnsureSeedDataForContext();
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        // global exception handling
                        var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>();
                        if (exceptionHandlerFeature != null)
                        {
                            var logger = loggerFactory.CreateLogger("Global exception logger");
                            logger.LogError(500, exceptionHandlerFeature.Error, exceptionHandlerFeature.Error.Message);

                            // in case we have exceptionHandlerFeature we are able to send exception message
                            context.Response.StatusCode = 500;
                            await context.Response.WriteAsync(exceptionHandlerFeature.Error.Message);
                        }
                        else
                        {
                            // for all non handled exceptions send status code 500
                            context.Response.StatusCode = 500;
                            await context.Response.WriteAsync("An unexpected fault happened. Try again later.");
                        }
                    });
                });
            }

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Eshop API V1");
            });

            //TODO: move this into separate automapper config file
            AutoMapper.Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Log, LogDto>();
                cfg.CreateMap <LogViewModel, CollectionResourceParameters>();
                cfg.CreateMap <RegisterViewModel, User>();
                cfg.CreateMap <User, UserDto>()
                .ForMember(dest => dest.Telephone, opt => opt.MapFrom(src => src.Contact.Telephone))
                .ForMember(dest => dest.Address1, opt => opt.MapFrom(src => src.Contact.Address1))
                .ForMember(dest => dest.Address2, opt => opt.MapFrom(src => src.Contact.Address2))
                .ForMember(dest => dest.Psc, opt => opt.MapFrom(src => src.Contact.Psc))
                .ForMember(dest => dest.City, opt => opt.MapFrom(src => src.Contact.City))
                .ForMember(dest => dest.State, opt => opt.MapFrom(src => src.Contact.State));
                cfg.CreateMap <Product, ProductDto>()
                .ForMember(dest => dest.CategoryId, opt => opt.MapFrom(src => src.Category.Id))
                .ForMember(dest => dest.CategoryName, opt => opt.MapFrom(src => src.Category.Name))
                .ForMember(dest => dest.VendorId, opt => opt.MapFrom(src => src.Vendor.Id))
                .ForMember(dest => dest.VendorName, opt => opt.MapFrom(src => src.Vendor.Name))
                .ForMember(dest => dest.State, opt => opt.MapFrom(src => src.ProductState.Name));
                cfg.CreateMap <Vendor, VendorDto>();
                cfg.CreateMap <Category, CategoryDto>();
                cfg.CreateMap <Category, CategoryToCreateViewModel>();
            });

            app.UseCors(x => x.WithExposedHeaders("X-Pagination")
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        .AllowAnyOrigin()); // ("AllowAll");

            app.UseAuthentication();

            app.UseDefaultFiles();
            app.UseStaticFiles();

            app.UseMvc();
        }
 public LoggerRepository(EshopDbContext context)
     : base(context)
 {
 }