コード例 #1
0
 public static void SaveCart(Cart cart)
 {
     using (var db = new ESDbContext())
     {
         Cart c  = db.Cart.Where(x => x.UserName == cart.UserName).FirstOrDefault();
         Item it = new Item();
         if (cart.Items != null)
         {
             if (cart.Items.Sum(x => x.Quantity) != 0)
             {
                 foreach (var item in cart.Items)
                 {
                     if (c.Items.Where(x => x.ProductId == item.ProductId).Any())
                     {
                         c.Items.Where(x => x.ProductId == item.ProductId).FirstOrDefault().Quantity = cart.Items.Where(x => x.ProductId == item.ProductId).FirstOrDefault().Quantity;
                     }
                     else
                     {
                         it.ProductId = item.ProductId;
                         it.Quantity  = item.Quantity;
                         c.Items.Add(it);
                     }
                 }
             }
             else
             {
                 foreach (var item in c.Items)
                 {
                     item.Quantity = 0;
                 }
             }
             db.SaveChanges();
         }
     }
 }
コード例 #2
0
 public static void AddCode(ActCode code)
 {
     using (var db = new ESDbContext())
     {
         db.ActCode.Add(code);
         db.SaveChanges();
     }
 }
コード例 #3
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
 public static void UpdateCoin(string UN, int CN)
 {
     using (var db = new ESDbContext())
     {
         User u = db.User.Where(x => x.Name == UN).FirstOrDefault();
         u.coin = CN;
         db.SaveChanges();
     }
 }
コード例 #4
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
 public static void AddNewUser(string UN, string PW, string CPW, string EM)
 {
     using (var db = new ESDbContext())
     {
         User newuser = new User(UN, PW, CPW, EM);
         db.User.Add(newuser);
         db.SaveChanges();
     }
 }
コード例 #5
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
 public static void AddCoin(string UN, int num)
 {
     using (var db = new ESDbContext())
     {
         User u = db.User.Where(x => x.Name == UN).FirstOrDefault();
         u.coin += num;
         db.SaveChanges();
     }
 }
コード例 #6
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
 public static void UpdateLastLogin(string UN)
 {
     using (var db = new ESDbContext())
     {
         User u = db.User.Where(x => x.Name == UN).FirstOrDefault();
         u.lastlogin = DateTime.Today;
         db.SaveChanges();
     }
 }
コード例 #7
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
 public static void UpdatePref(string UN, int Pre)
 {
     using (var db = new ESDbContext())
     {
         User u = db.User.Where(x => x.Name == UN).FirstOrDefault();
         u.Preference = Pre;
         db.SaveChanges();
     }
 }
コード例 #8
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static List <string> GetAllUserN()
        {
            List <string> UNList = new List <string>();

            using (var db = new ESDbContext())
            {
                UNList = db.User.Select(x => x.Name).ToList();
            }
            return(UNList);
        }
コード例 #9
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static List <string> GetAllEmail()
        {
            List <string> EMList = new List <string>();

            using (var db = new ESDbContext())
            {
                EMList = db.User.Select(x => x.EmailAdd).ToList();
            }
            return(EMList);
        }
コード例 #10
0
        public static Product GetProductsById(int ProductId)
        {
            Product p = new Product();

            using (var db = new ESDbContext())
            {
                p = db.Product.Where(x => x.Id == ProductId).FirstOrDefault();
            }
            return(p);
        }
コード例 #11
0
        public static List <Product> GetAllProducts()
        {
            List <Product> PList = new List <Product>();

            using (var db = new ESDbContext())
            {
                PList = db.Product.ToList();
            }
            return(PList);
        }
コード例 #12
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static string GetClickhist(string username)
        {
            string Chist;

            using (var db = new ESDbContext())
            {
                User u = db.User.Where(x => x.Name == username).FirstOrDefault();
                Chist = u.ClickHist;
            }
            return(Chist);
        }
コード例 #13
0
        public static List <ActCode> GetCodebyUserId(int uid)
        {
            List <ActCode> codelist = new List <ActCode>();

            using (var db = new ESDbContext())
            {
                codelist = db.ActCode.Include("product").Where(x => x.UserId == uid).ToList();
            }

            return(codelist);
        }
コード例 #14
0
        public static Product GetProductsByCat(int cat)
        {
            Product p = new Product();

            using (var db = new ESDbContext())
            {
                var            rand = new Random();
                List <Product> Lp   = db.Product.Where(x => x.Cat == cat).ToList();
                p = Lp[rand.Next(Lp.Count)];
            }
            return(p);
        }
コード例 #15
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static int GetPreference(string username)
        {
            int Pre = 0;

            using (var db = new ESDbContext())
            {
                if (db.User.Where(x => x.Name == username).Any())
                {
                    Pre = db.User.Where(x => x.Name == username).FirstOrDefault().Preference;
                }
            }
            return(Pre);
        }
コード例 #16
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static int GetId(string username)
        {
            int id = 0;

            using (var db = new ESDbContext())
            {
                if (db.User.Where(x => x.Name == username).Any())
                {
                    id = db.User.Where(x => x.Name == username).FirstOrDefault().Id;
                }
            }
            return(id);
        }
コード例 #17
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static int GetCoinNum(string username)
        {
            int cn = 0;

            using (var db = new ESDbContext())
            {
                if (db.User.Where(x => x.Name == username).Any())
                {
                    cn = db.User.Where(x => x.Name == username).FirstOrDefault().coin;
                }
            }
            return(cn);
        }
コード例 #18
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static string GetPassword(string username)
        {
            string pw = "";

            using (var db = new ESDbContext())
            {
                if (db.User.Where(x => x.Name == username).Any())
                {
                    pw = db.User.Where(x => x.Name == username).FirstOrDefault().Password;
                }
            }
            return(pw);
        }
コード例 #19
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static DateTime GetLastLogin(string username)
        {
            DateTime dt = DateTime.Today.Date.AddDays(-30);

            using (var db = new ESDbContext())
            {
                if (db.User.Where(x => x.Name == username).Any())
                {
                    dt = db.User.Where(x => x.Name == username).FirstOrDefault().lastlogin;
                }
            }
            return(dt);
        }
コード例 #20
0
ファイル: UserData.cs プロジェクト: ShawnWon/Eshop2cloud2
        public static void UpdateClick(string UN, int wishId)
        {
            using (var db = new ESDbContext())
            {
                User u = db.User.Where(x => x.Name == UN).FirstOrDefault();

                string s       = u.ClickHist;
                var    numbers = s.Split(',').Select(Int32.Parse).ToList();
                numbers[wishId - 1] += 1; //wish button indexed from 1 to 8, list indexed from 0 to 7
                var result = string.Join(", ", numbers);
                u.ClickHist = result;

                //cloud edition update preference directly without talk to python model
                u.Preference = wishId;

                db.SaveChanges();
            }
        }
コード例 #21
0
        public static Cart GetCart(string username)
        {
            Cart cart = new Cart();

            using (var db = new ESDbContext())
            {
                if (db.Cart.Where(x => x.UserName == username).Any())
                {
                    cart = db.Cart.Include("Items.product").Where(x => x.UserName == username).FirstOrDefault();
                }
                else
                {
                    cart.UserName = username;
                    cart.Items    = new List <Item>();
                    db.Cart.Add(cart);
                    db.SaveChanges();
                }
            }
            return(cart);
        }
コード例 #22
0
        protected override void Seed(ESDbContext context)
        {
            List <User> users = new List <User>();

            users.Add(new User("JonSnow", "44f2ea859b70f5356621e259f6167bac", "44f2ea859b70f5356621e259f6167bac", "*****@*****.**"));       //I know nothing
            users.Add(new User("SheldonCopper", "2f3e13074e3731eeff15f3da4918ebc8", "2f3e13074e3731eeff15f3da4918ebc8", "*****@*****.**")); //Bazzinga
            users.Add(new User("Sabina", "9b2b9ff87951a8ce6a157864ad935843", "9b2b9ff87951a8ce6a157864ad935843", "*****@*****.**"));        //I hate kitsch
            users.Add(new User("Cosimo", "f7502cc1466096dacd7e6ea60afd5915", "f7502cc1466096dacd7e6ea60afd5915", "*****@*****.**"));        //I live in tree
            users.Add(new User("Gatsby", "12bbbc83f7f249e8acb572184d3b68f3", "12bbbc83f7f249e8acb572184d3b68f3", "*****@*****.**"));        //Greenlight
            foreach (User u in users)
            {
                context.User.Add(u);
            }

            List <Product> products = new List <Product>();

            //1,Spirit,2,Material,3,Relation,4,Personel,0,Others
            products.Add(new Product("Jean Valjean Diary", "Do you hear the people sing?", 30, "24601.jpg", 5));
            products.Add(new Product("Colonel's Goldfish", "It's raining in Macondo", 50, "Goldfish.jpg", 1));
            products.Add(new Product("T|D voucher", "Ask Shawn with this voucher, he will assure you a truth or a dare.", 200, "tod.jpg", 0));
            products.Add(new Product("Sabina's hat", "My enemy is kitsch", 20, "hat.jpg", 8));
            products.Add(new Product("Lord of Rings", "The one to rule them all.", 44, "ring.jpg", 3));
            products.Add(new Product("Gatsby's greenlight", "So we beat on, boats against the current...", 10, "greenlight.bmp", 6));
            products.Add(new Product("Ralph's conch", "Maybe there is a beast...", 30, "conch.jpg", 1));
            products.Add(new Product("The Iron Throne", "Win or die in Westero.", 66, "Throne.jpg", 3));
            products.Add(new Product("Cosimo's tree", "Disappear into the sky", 70, "tree.jpg", 1));
            products.Add(new Product("Dragon Ball", "Collect total 7 to summon dragon.", 10, "dragonball.jpg", 0));
            products.Add(new Product("OP Strawhat", "The hat Gold D Roger passed to Luffy.", 30, "strawhat.jpg", 5));
            products.Add(new Product("Aladdin's Lamp", "Genie will grant you three wishes", 100, "aladdin.jpg", 0));
            products.Add(new Product("Sheldon's Spot", "The center of Sheldon't universe", 55, "spot.jpg", 7));
            products.Add(new Product("Andy's Rock Hammer", "The salvation lies within.", 65, "hammer.jpg", 5));
            products.Add(new Product("Little Prince's Rose", "You are my one unique rose .", 35, "rose.jpg", 6));
            products.Add(new Product("Sherlock's items", "It's my business to know what other people don't know.", 50, "sherlock.jpg", 7));
            products.Add(new Product("Cleopatra's eye shadow ", "I will not be triumphed over.", 10, "cleopatra.jpg", 8));
            products.Add(new Product("Happy Prince's lead heart", "You must kiss me on the lips, for I love you..", 80, "happyprince.jpg", 1));
            products.Add(new Product("Monte Cristo's treasure", "All human wisdom is contained in these two words - Wait and Hope.", 70, "cristo.jpg", 2));
            products.Add(new Product("Sandiago's fishboat", "A man can be destroyed but not defeated.", 50, "oldman.jpg", 4));
            products.Add(new Product("Carmen's scarlet skirt", "Carmen will always be free.", 20, "carmen.jpg", 8));

            products.Add(new Product("Marguerite's camelias ", "The end of this adventure becomes simply a matter of curiosity.", 15, "camelias.jpg", 8));
            products.Add(new Product("Peekay's remote control", "Which god shall I believe?", 35, "remote.jpg", 5));
            products.Add(new Product("Heart of Ocean", "My heart will go on...", 50, "heartofocean.jpg", 6));
            products.Add(new Product("Chihiro's train ticket", "Someday, we are getting on that train.", 5, "ticket.jpg", 5));
            products.Add(new Product("Bridget Jones's diary", "I like you, just as you are.", 10, "bjdiary.jpg", 6));
            products.Add(new Product("Goose that laid Golden egg", "Will you cook me?", 15, "goose.jpg", 2));
            products.Add(new Product("Jack's magic beans", "Exchange for your cow, deal or not?", 25, "bean.jpg", 2));
            products.Add(new Product("Cinderella's crystal shoe", "Always believe in a little magic", 7, "shoe.jpg", 8));
            products.Add(new Product("K3's music video", "Chit Kyout Yoon Shar", 50, "k3.jpg", 1));
            products.Add(new Product("Hulk's pants", "Hulk is angery!", 10, "hulk.jpg", 3));
            products.Add(new Product("Bertrand Russell's teapot", "Do not fear to be eccentric in opinion.", 66, "teapot.jpg", 7));
            products.Add(new Product("Issac Newton's apple", "By standing on the shoulders of giants", 5, "newton.jpg", 7));
            products.Add(new Product("Lasso of Truth", "Now I know that only love can truly save the world.", 44, "lasso.jpg", 3));
            products.Add(new Product("Leon's potted plant", "I hope you are not lying, Leon.", 20, "leon.jpg", 6));
            products.Add(new Product("Amelia's travelling Gnome", "You don't have bones of glass.", 5, "gnome.jpg", 4));

            foreach (Product p in products)
            {
                context.Product.Add(p);
            }
            context.SaveChanges();

            List <ActCode> LA = new List <ActCode>();

            LA.Add(new ActCode(1, 1, Guid.NewGuid(), DateTime.Today.Date.AddYears(-1)));
            LA.Add(new ActCode(1, 2, Guid.NewGuid(), DateTime.Today.Date.AddYears(-1)));
            LA.Add(new ActCode(1, 3, Guid.NewGuid(), DateTime.Today.Date.AddDays(-50)));
            LA.Add(new ActCode(1, 4, Guid.NewGuid(), DateTime.Today.Date.AddDays(-50)));
            LA.Add(new ActCode(1, 5, Guid.NewGuid(), DateTime.Today.Date));
            foreach (ActCode a in LA)
            {
                context.ActCode.Add(a);
            }

            context.SaveChanges();


            base.Seed(context);
        }