/// <summary>
        /// 用户信息导入
        /// </summary>
        /// <returns></returns>
        public IActionResult ImportMemInfJob()
        {
            using var context = new SupermarketDbContext();

            StreamReader sr = new StreamReader("test.txt");

            string name, phone, password;

            for (int i = 0; i < 3; i++)
            {
                var member = new Member()
                {
                    Credit = 0
                };

                name        = sr.ReadLine();
                member.Name = name;

                phone        = sr.ReadLine();
                member.Phone = phone;

                password        = sr.ReadLine();
                member.Password = password;

                context.Member.Add(member);
                context.SaveChanges();
            }

            return(View());
        }
Example #2
0
        public static void SeedRoles(SupermarketDbContext context, RoleManager <ApplicationRole> roleManager)
        {
            var roles = new List <ApplicationRole>()
            {
                new ApplicationRole()
                {
                    Name           = ApplicationUser.Roles.admin,
                    NormalizedName = ApplicationUser.Roles.Admin
                },
                new ApplicationRole()
                {
                    Name           = ApplicationUser.Roles.storeKeeper,
                    NormalizedName = ApplicationUser.Roles.StoreKeeper
                },
                new ApplicationRole()
                {
                    Name           = ApplicationUser.Roles.manager,
                    NormalizedName = ApplicationUser.Roles.Manager
                },
            };

            roles.ForEach(role => {
                var dbRole = context.Roles.FirstOrDefault(r => r.Name == role.Name);

                if (dbRole == null)
                {
                    context.Roles.Add(role);
                }
            });

            context.SaveChanges();
        }
Example #3
0
        public static void SeedProducts(SupermarketDbContext context)
        {
            var    faker    = new Faker();
            string product1 = faker.Commerce.ProductName();
            string product2 = faker.Commerce.ProductName();
            string product3 = faker.Commerce.ProductName();
            string product4 = faker.Commerce.ProductName();

            var category  = context.Categories.FirstOrDefault(p => p.Name == "Electronics");
            var category2 = context.Categories.FirstOrDefault(p => p.Name == "Toiletries");
            var category3 = context.Categories.FirstOrDefault(p => p.Name == "Miscellaneous");
            var category4 = context.Categories.FirstOrDefault(p => p.Name == "Fashion");

            var products = new List <Product>()
            {
                new Product()
                {
                    Name              = product1,
                    QuantityInStock   = faker.Random.Number(1, 9),
                    UnitOfMeasurement = EUnitOfMeasurement.Kilogram,
                    CategoryId        = category.Id
                },
                new Product()
                {
                    Name              = product2,
                    QuantityInStock   = faker.Random.Number(2, 12),
                    UnitOfMeasurement = EUnitOfMeasurement.Kilogram,
                    CategoryId        = category2.Id
                },
                new Product()
                {
                    Name              = product3,
                    QuantityInStock   = faker.Random.Number(3, 13),
                    UnitOfMeasurement = EUnitOfMeasurement.Gram,
                    CategoryId        = category3.Id
                },
                new Product()
                {
                    Name              = product4,
                    QuantityInStock   = faker.Random.Number(5, 15),
                    UnitOfMeasurement = EUnitOfMeasurement.Kilogram,
                    CategoryId        = category4.Id
                }
            };

            products.ForEach(product =>
            {
                var dbProduct = context.Products.FirstOrDefault(p => p.Name == product.Name);
                if (dbProduct == null)
                {
                    context.Products.Add(product);
                }
            });

            context.SaveChanges();
        }
        public IActionResult MemberDisplay(string phonetail)
        {
            using var context = new SupermarketDbContext();

            var members = new List <Member>();

            members = context.Member.Where(x => x.Phone.Contains(phonetail)).ToList();

            return(View("MemberDisplay", members));
        }
        /// <summary>
        /// 会员消费信息统计
        /// </summary>
        /// <param name="memberid"></param>
        /// <returns></returns>
        public IActionResult MemberStatistics(int memberid)
        {
            using var context = new SupermarketDbContext();

            var gooditems = new List <MemberGoodMapping>();

            gooditems = context.MemberGoodMapping.Where(x => x.MemberId.Equals(memberid)).ToList();

            return(View("memberstatistics", gooditems));
        }
        /// <summary>
        /// 查询会员消费记录
        /// </summary>
        /// <param name="memberid"></param>
        /// <returns></returns>
        public IActionResult EnquiryShopJob(int memberid)
        {
            using var context = new SupermarketDbContext();

            var shopItems = new List <MemberGoodMapping>();

            shopItems = context.MemberGoodMapping.Where(x => x.MemberId.Equals(memberid)).ToList();

            return(View("EnquiryShopJob", shopItems));
        }
        /// <summary>
        /// 会员制度管理
        /// </summary>
        /// <param name="viplevelid"></param>
        /// <param name="levelrateafter"></param>
        /// <returns></returns>
        public IActionResult VipManageJob(int viplevelid, double levelrateafter)
        {
            using var context = new SupermarketDbContext();

            var levelitems = context.Level.FirstOrDefault(x => x.Id.Equals(viplevelid));

            levelitems.DiscountRate = levelrateafter;

            context.SaveChanges();

            return(View());
        }
        /// <summary>
        /// 会员等级修改
        /// </summary>
        /// <param name="memberid"></param>
        /// <param name="levelafter"></param>
        /// <returns></returns>
        public IActionResult MemberLevelChange(int memberid, int levelafter)
        {
            using var context = new SupermarketDbContext();

            var levelitems = context.MemberLevelMapping.FirstOrDefault(x => x.MemberId.Equals(memberid));

            levelitems.LevelId = levelafter;

            context.SaveChanges();

            return(View());
        }
        /// <summary>
        /// 修改会员消费记录
        /// </summary>
        /// <param name="memberid"></param>
        /// <param name="goodid"></param>
        /// <param name="quantity"></param>
        /// <returns></returns>
        public IActionResult AmendShopJob(int memberid, int goodid, int quantity)
        {
            using var context = new SupermarketDbContext();

            var gooditems = context.MemberGoodMapping.FirstOrDefault(x => x.MemberId.Equals(memberid));

            gooditems.GoodId   = goodid;
            gooditems.Quantity = quantity;

            context.SaveChanges();

            return(View());
        }
        public IActionResult MemAmendJob(string name, string phone, string password, string nameafter, string phoneafter, string passwordafter)
        {
            using var context = new SupermarketDbContext();

            var members = context.Member.FirstOrDefault(x => x.Phone.Contains(phone));

            members.Name     = nameafter;
            members.Phone    = phoneafter;
            members.Password = passwordafter;

            context.SaveChanges();

            return(View());
        }
        /// <summary>
        /// 注销会员
        /// </summary>
        /// <param name="phonetail"></param>
        /// <returns></returns>
        public IActionResult DeleteByOneString(string phonetail)
        {
            using var context = new SupermarketDbContext();

            var members = context.Member.FirstOrDefault(x => x.Phone.Contains(phonetail));
            var id      = members.Id;
            var mem2    = context.MemberLevelMapping.FirstOrDefault(x => x.MemberId.Equals(id));
            var mem3    = context.Statistics.FirstOrDefault(x => x.MemberId.Equals(id));

            context.Remove(mem2);
            context.Remove(mem3);
            context.Remove(members);
            context.SaveChanges();

            return(View());
        }
        public IActionResult MemberJob(string name, string phone, string password)
        {
            using var context = new SupermarketDbContext();
            var member = new Member()
            {
                Credit = 0
            };

            member.Name     = name;
            member.Phone    = phone;
            member.Password = password;

            context.Member.Add(member);
            context.SaveChanges();

            return(View());
        }
        /// <summary>
        /// 增加会员消费记录
        /// </summary>
        /// <param name="memberid"></param>
        /// <param name="goodid"></param>
        /// <param name="quantity"></param>
        /// <returns></returns>
        public IActionResult RecordShopJob(int memberid, int goodid, int quantity)
        {
            using var context = new SupermarketDbContext();
            var shopitems = new MemberGoodMapping()
            {
                Id         = Guid.NewGuid().ToString(),
                CreateTime = DateTime.Now.ToString()
            };

            shopitems.MemberId = memberid;
            shopitems.GoodId   = goodid;
            shopitems.Quantity = quantity;



            //var find1 = context.Good.FirstOrDefault(x => x.Id.Equals(goodid));
            //find1.Price

            context.MemberGoodMapping.Add(shopitems);
            context.SaveChanges();

            return(View());
        }
Example #14
0
        public static void SeedCategories(SupermarketDbContext context)
        {
            var categories = new List <Category>()
            {
                new Category()
                {
                    Id   = Guid.NewGuid(),
                    Name = "Electronics"
                },
                new Category()
                {
                    Id   = Guid.NewGuid(),
                    Name = "Toiletries"
                },
                new Category()
                {
                    Id   = Guid.NewGuid(),
                    Name = "Miscellaneous"
                },
                new Category()
                {
                    Id   = Guid.NewGuid(),
                    Name = "Fashion"
                }
            };

            categories.ForEach(category => {
                var dbCategory = context.Categories.FirstOrDefault(r => r.Name == category.Name);
                if (dbCategory == null)
                {
                    context.Categories.Add(category);
                }
            });

            context.SaveChanges();
        }
Example #15
0
 public SendTem(SupermarketDbContext context)
 {
     _context = context;
 }
Example #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 /// <param name="hostingEnvironment"></param>
 public OrderController(SupermarketDbContext context, IHostingEnvironment hostingEnvironment)
 {
     _context            = context;
     _hostingEnvironment = hostingEnvironment;
 }
Example #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public WinnerController(SupermarketDbContext context)
 {
     _context = context;
 }
Example #18
0
 public BasketRepository(SupermarketDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
Example #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public LotteryController(SupermarketDbContext context)
 {
     _context = context;
 }
Example #20
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public AddressController(SupermarketDbContext context)
 {
     _context = context;
 }
Example #21
0
 /// <summary>
 /// 数据库连接
 /// </summary>
 /// <param name="context"></param>
 public GoodsController(SupermarketDbContext context)
 {
     _context = context;
 }
Example #22
0
 public Token(SupermarketDbContext context)
 {
     _context = context;
 }
Example #23
0
 /// <summary>
 /// 配置数据库与文件流参数
 /// </summary>
 /// <param name="context"></param>
 /// <param name="env"></param>
 public GoodsKindController(SupermarketDbContext context, IHostingEnvironment env)
 {
     _context = context;
     _Env     = env;
 }
Example #24
0
 /// <summary>
 /// 初始化方法
 /// </summary>
 /// <param name="context"></param>
 public DbInitializer(SupermarketDbContext context)
 {
     _context = context;
     //context.Database.EnsureCreated();//如果数据库不存在,那么它会创建,但不做任何事
 }
Example #25
0
        public static void SeedUsers(SupermarketDbContext context, UserManager <ApplicationUser> userManager)
        {
            string password = "******";
            var    faker    = new Faker();
            var    email    = faker.Person.Email;
            var    email2   = faker.Person.Email;
            var    email3   = faker.Person.Email;
            var    email4   = faker.Person.Email;

            var users = new List <ApplicationUser>()
            {
                new ApplicationUser
                {
                    UserName       = email,
                    Email          = email,
                    EmailConfirmed = true,
                    FullName       = faker.Person.FullName
                },
                new ApplicationUser
                {
                    UserName       = email2,
                    Email          = email2,
                    EmailConfirmed = true,
                    FullName       = faker.Person.FullName
                },
                new ApplicationUser
                {
                    UserName       = email3,
                    Email          = email3,
                    EmailConfirmed = true,
                    FullName       = faker.Person.FullName
                },
                new ApplicationUser
                {
                    UserName       = email4,
                    Email          = email4,
                    EmailConfirmed = true,
                    FullName       = faker.Person.FullName
                }
            };

            users.ForEach(user => {
                var dbUser = context.Users.FirstOrDefault(u => u.Email == user.Email);
                if (dbUser == null)
                {
                    var result = userManager.CreateAsync(user, password).Result;
                    if (!result.Succeeded)
                    {
                        Console.WriteLine("User Save Error: " + result.Errors.First().Description);
                    }
                    else
                    {
                        Console.WriteLine($"User { user.UserName } created");
                    }
                    if (user.UserName.Contains("admin"))
                    {
                        result = userManager.AddToRoleAsync(user, ApplicationUser.Roles.Admin).Result;
                    }
                    else if (user.UserName.Contains("manager"))
                    {
                        result = userManager.AddToRoleAsync(user, ApplicationUser.Roles.Manager).Result;
                    }
                    else if (user.UserName.Contains("storeKeeper"))
                    {
                        result = userManager.AddToRoleAsync(user, ApplicationUser.Roles.StoreKeeper).Result;
                    }
                    if (!result.Succeeded)
                    {
                        Console.WriteLine("User to Role Error: " + result.Errors.First().Description);
                    }
                }
            });
        }
Example #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public LoginController(SupermarketDbContext context)
 {
     _context = context;
 }
Example #27
0
 public ProductRepository(SupermarketDbContext context) : base(context)
 {
 }
Example #28
0
 public BaseRepository(SupermarketDbContext context)
 {
     _context = context;
 }
Example #29
0
 /// <summary>
 /// 数据库连接
 /// </summary>
 /// <param name="context"></param>
 public AppCartController(SupermarketDbContext context)
 {
     _context = context;
 }
Example #30
0
 public CategoryRepository(SupermarketDbContext context) : base(context)
 {
 }