Exemplo n.º 1
0
 public UnitOfWork(GoCafeContext context)
 {
     Account  = new AccountRepository(context);
     Product  = new ProductRepository(context);
     Category = new CategoryRepository(context);
     Bill     = new BillRepository(context);
     InfoBill = new InfoBillRepository(context);
     _context = context;
 }
Exemplo n.º 2
0
        public static void Initialize(GoCafeContext context)
        {
            context.Database.EnsureCreated();

            if (context.Accounts.Any())
            {
                return;
            }

            context.Accounts.AddRange(
                new Account
            {
                Username    = "******",
                Fullname    = "abvdasdasd",
                Phone       = "0123456789",
                Dateofbirth = DateTime.Parse("1999-10-02"),
                Password    = "******",
                UserRole    = "Nhân viên",
                Status      = "Hoạt động"
            },

                new Account
            {
                Username    = "******",
                Fullname    = "Ghost busters",
                Phone       = "0123456789",
                Dateofbirth = DateTime.Parse("1999-10-02"),
                Password    = "******",
                UserRole    = "Quản trị viên",
                Status      = "Hoạt động"
            },
                new Account
            {
                Username    = "******",
                Fullname    = "Trương Phạm Nhật Tiến",
                Phone       = "0123456789",
                Dateofbirth = DateTime.Parse("1999-10-02"),
                Password    = "******",
                UserRole    = "Nhân viên",
                Status      = "Khoá"
            }
                );
            if (context.Products.Any())
            {
                return;
            }
            var category = new List <Category>()
            {
                new Category {
                    CategoryId   = 1,
                    CategoryName = "cafe"
                },
                new Category {
                    CategoryId   = 2,
                    CategoryName = "Sua"
                }
            };

            context.Products.AddRange(
                new Product
            {
                Id          = 1,
                ProductName = "Espreso",
                Price       = 50000,
                Category    = category[0]
            },
                new Product
            {
                Id          = 2,
                ProductName = "Trà sữa trân châu",
                Price       = 50000,
                Category    = category[1]
            }
                );

            context.SaveChanges();
        }