コード例 #1
0
        public async void Insert()
        {
            try
            {
                using (var db = new EliteContext(dbFullPath))
                {
                    //await db.Database.EnsureDeletedAsync();
                    await db.Database.EnsureCreatedAsync();

                    await db.Database.MigrateAsync(); // We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated.

                    ////  User user = new User() { iduser = 1, username = "******", password = "******" ,
                    //     address ="1 huke lane", email="nadalaga2002" };

                    List <User> objuser = new List <User>()
                    {
                        user
                    };
                    await db.Users.AddRangeAsync(objuser);

                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
コード例 #2
0
        public async Task <List <User> > Get()
        {
            try
            {
                using (var db = new EliteContext(dbFullPath))
                {
                    return(await db.Users.ToListAsync());
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            return(null);
        }
コード例 #3
0
        public async Task <User> CheckLogin(string name, string password)
        {
            try
            {
                using (var db = new EliteContext(dbFullPath))
                {
                    return(await db.Users.Where(a => a.username == name && a.password == password).FirstOrDefaultAsync());
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            return(null);
        }
コード例 #4
0
        public async Task <int> Insert()
        {
            int result = 0;

            try
            {
                using (var db = new EliteContext(dbFullPath))
                {
                    //await db.Database.EnsureDeletedAsync();
                    await db.Database.EnsureCreatedAsync();

                    await db.Database.MigrateAsync(); // We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated.

                    //Add A few order
                    Order order = new Order()
                    {
                        name = "T-shirt", description = "Nice shirt", image = "Images/Image1.png"
                    };

                    List <Order> objOrder = new List <Order>()
                    {
                        order
                    };
                    await db.Orders.AddRangeAsync(objOrder);

                    await db.SaveChangesAsync();

                    Order order1 = new Order()
                    {
                        name = "Dress", description = "Nice dress", image = "Images/Image2.png"
                    };

                    List <Order> objOrder1 = new List <Order>()
                    {
                        order1
                    };
                    await db.Orders.AddRangeAsync(objOrder1);

                    await db.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            return(result);
        }