コード例 #1
0
        public void ATW(Toy toy, int?id)     //Add to wishlist
        {
            var  WT = RWT(toy, id);
            bool a  = ToyExist(toy, WT);

            if (a) // if exists dont add
            {
                WT = new Wishlist
                {
                    //WishlistId = LastRecordW() + 1,
                    Email  = WID,
                    ToysId = toy.ToysId
                };
                db.Wishlist.Add(WT);
                db.SaveChanges();
            }
            ;
        }
コード例 #2
0
        public bool ToyExist(Toy t, Wishlist w) //checks if exist returns true or false, wishlist is for the email check and toy for the toysid finder
        {
            var a = from B in db.Wishlist where B.ToysId == t.ToysId && B.Email == w.Email select B;

            //var b = from B in db.Wishlist where B.ToysId == t.ToysId && w.WishlistId == B.WishlistId select B;
            try
            {
                var b = a.First().ToysId;
                var c = a.First().Email;
                if (b != t.ToysId && c != w.Email)                      //als het niet bestaat dan returnt dit een error dus try-catch implementeren om de error te handelen
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(true);
            }
        }
コード例 #3
0
        public void ATC(Toy toy, int?id)     //Add to cart
        {
            var CT = RCT(toy, id);

            //var CT = db.Cart.SingleOrDefault(
            //    c => c.CartId == SCID && c.ToyId == toy.ToysId);
            if (CT == null)
            {
                CT = new Cart
                {
                    RecordId    = LastRecord() + 1, //0,
                    ToyId       = toy.ToysId,
                    CartId      = SCID,
                    Count       = 1,
                    DateCreated = DateTime.Now
                };
                db.Cart.Add(CT);
            }
            else
            {
                CT.Count++;
            }
            db.SaveChanges();
        }