Ejemplo n.º 1
0
        public Boolean DataAdd(user model)
        {
            var query = db.Users.Where(x => x.Email == model.Email).FirstOrDefault();

            if (query == null)
            {
                model.Role = "user";
                db.Users.Add(model);
                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public bool CartAdd(ClassLibrary1.Cart model)
        {
            var available = DB.Products.Where(x => x.productId == model.ProductID).FirstOrDefault();
            int stock     = available.ProductStock;

            if (stock > model.Quantity)
            {
                var check = DB.Carts.Where(x => x.ProductID == model.ProductID && x.UserID == model.UserID).FirstOrDefault();
                if (check == null)
                {
                    DB.Carts.Add(model);
                    DB.SaveChanges();
                    var    query  = DB.Carts.Where(x => x.ID == model.ID).FirstOrDefault();
                    var    query2 = DB.Products.Where(x => x.productId == model.ProductID).FirstOrDefault();
                    int    price1 = query2.ProductPrice;
                    string image  = query2.ProductImage;
                    string name   = query2.ProductName;
                    query.Price        = price1;
                    query.ProductImage = image;
                    query.ProductName  = name;
                    query.Total        = (query.Quantity * price1);
                    DB.SaveChanges();
                    return(true);
                }
                else
                {
                    check.Quantity = check.Quantity + model.Quantity;
                    check.Total    = check.Total + (model.Quantity * check.Price);
                    DB.SaveChanges();
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
 public bool saveAddress(ClassLibrary1.Address address)
 {
     DB.Addresses.Add(address);
     DB.SaveChanges();
     return(true);
 }
Ejemplo n.º 4
0
 public void ProductAdd(Product model)
 {
     db.Products.Add(model);
     db.SaveChanges();
 }