Exemple #1
0
    public string InsertCart(Cart cart)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            db.Carts.Add(cart);
            db.SaveChanges();

            return(cart.DateParchased + " was succesfully inserted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
 public Product GetProduct(int id)
 {
     try
     {
         using (NikovBikeShopDBEntities db = new NikovBikeShopDBEntities())
         {
             Product product = db.Products.Find(id);
             return product;
         }
     }
     catch (Exception)
     {
         return null;
     }
 }
    public string InsertProduct(Product product)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            db.Products.Add(product);
            db.SaveChanges();

            return product.Name + " was succesfully inserted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
 public Product GetProduct(int id)
 {
     try
     {
         using (NikovBikeShopDBEntities db = new NikovBikeShopDBEntities())
         {
             Product product = db.Products.Find(id);
             return(product);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
    public string InsertCart(Cart cart)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            db.Carts.Add(cart);
            db.SaveChanges();

            return cart.DateParchased + " was succesfully inserted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
    public string InsertProduct(Product product)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            db.Products.Add(product);
            db.SaveChanges();

            return(product.Name + " was succesfully inserted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
 public List <Product> GetAllProducts()
 {
     try
     {
         using (NikovBikeShopDBEntities db = new NikovBikeShopDBEntities())
         {
             List <Product> products = (from x in db.Products select x).ToList();
             return(products);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
    public string DeleteProduct(int id)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            Product product = db.Products.Find(id);

            db.Products.Attach(product);
            db.Products.Remove(product);
            db.SaveChanges();

            return product.Name + " was succesfully deleted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
    public List <Product> GetProductsByType(int typeId)
    {
        try
        {
            using (NikovBikeShopDBEntities db = new NikovBikeShopDBEntities())
            {
                List <Product> productsByType = (from x in db.Products
                                                 where x.TypeId == typeId
                                                 select x).ToList();

                return(productsByType);
            }
        }
        catch (Exception)
        {
            return(null);
        }
    }
Exemple #10
0
    public string DeleteCart(int id)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            Cart cart = db.Carts.Find(id);

            db.Carts.Attach(cart);
            db.Carts.Remove(cart);
            db.SaveChanges();

            return(cart.DateParchased + " was succesfully deleted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
    public string DeleteProduct(int id)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            Product product            = db.Products.Find(id);

            db.Products.Attach(product);
            db.Products.Remove(product);
            db.SaveChanges();

            return(product.Name + " was succesfully deleted");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
    public string DeleteCart(int id)
    { 
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();
            Cart cart = db.Carts.Find(id);

            db.Carts.Attach(cart);
            db.Carts.Remove(cart);
            db.SaveChanges();

            return cart.DateParchased + " was succesfully deleted";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
    public string UpdateProductType(int id, ProductType productType)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();

            //Fetch object from db
            ProductType p = db.ProductTypes.Find(id);

            p.Name = productType.Name;

            db.SaveChanges();
            return(productType.Name + " was succesfully updated");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
    public string UpdateProductType(int id, ProductType productType)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();

            //Fetch object from db
            ProductType p = db.ProductTypes.Find(id);

            p.Name = productType.Name;

            db.SaveChanges();
            return productType.Name + " was succesfully updated";

        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
Exemple #15
0
    public string UpdateCart(int id, Cart cart)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();

            //Fetch object from db
            Cart p = db.Carts.Find(id);

            p.DateParchased = cart.DateParchased;
            p.ClientId      = cart.ClientId;
            p.Amount        = cart.Amount;
            p.IsInCart      = cart.IsInCart;
            p.ProductId     = cart.ProductId;

            db.SaveChanges();
            return(cart.DateParchased + " was succesfully updated");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
    public string UpdateProduct(int id, Product product)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();

            //Fetch object from db
            Product p = db.Products.Find(id);

            p.Name        = product.Name;
            p.Price       = product.Price;
            p.TypeId      = product.TypeId;
            p.Description = product.Description;
            p.Image       = product.Image;

            db.SaveChanges();
            return(product.Name + " was succesfully updated");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
    public string UpdateProduct(int id, Product product)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();

            //Fetch object from db
            Product p = db.Products.Find(id);

            p.Name = product.Name;
            p.Price = product.Price;
            p.TypeId = product.TypeId;
            p.Description = product.Description;
            p.Image = product.Image;

            db.SaveChanges();
            return product.Name + " was succesfully updated";

        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
    public string UpdateCart(int id, Cart cart)
    {
        try
        {
            NikovBikeShopDBEntities db = new NikovBikeShopDBEntities();

            //Fetch object from db
            Cart p = db.Carts.Find(id);

            p.DateParchased= cart.DateParchased;
            p.ClientId = cart.ClientId;
            p.Amount = cart.Amount;
            p.IsInCart = cart.IsInCart;
            p.ProductId = cart.ProductId;

            db.SaveChanges();
            return cart.DateParchased + " was succesfully updated";

        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
    public List<Product> GetProductsByType(int typeId)
    {
        try
        {
            using (NikovBikeShopDBEntities db = new NikovBikeShopDBEntities())
            {
                List<Product> productsByType = (from x in db.Products
                    where x.TypeId == typeId
                    select x).ToList();

                return productsByType;
            }
        }
        catch (Exception)
        {
            return null;
        }
    }
 public List<Product> GetAllProducts()
 {
     try
     {
         using (NikovBikeShopDBEntities db = new NikovBikeShopDBEntities())
         {
             List<Product> products = (from x in db.Products select x).ToList();
             return products;
         }
     }
     catch (Exception)
     {
         return null;
     }
 }