Esempio n. 1
0
    public string InsertPurchase(Purchase purchase)
    {
        try
        {
            TshirtDBEntities db = new TshirtDBEntities();
            db.Purchases.Add(purchase);
            db.SaveChanges();

            return(purchase.Date + " was succesfully added!");
        }
        catch (Exception e)
        {
            return("Error " + e);
        }
    }
Esempio n. 2
0
 public Product GetProduct(int id)
 {
     try
     {
         using (TshirtDBEntities db = new TshirtDBEntities())
         {
             Product p = db.Products.Find(id);
             return(p);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Esempio n. 3
0
    public string InsertProduct(Product product)
    {
        try
        {
            TshirtDBEntities db = new TshirtDBEntities();
            db.Products.Add(product);
            db.SaveChanges();

            return(product.Name + " was succesfully added!");
        }
        catch (Exception e)
        {
            return("Error " + e);
        }
    }
Esempio n. 4
0
    public string InsertSize(Size size)
    {
        try
        {
            TshirtDBEntities db = new TshirtDBEntities();
            db.Sizes.Add(size);
            db.SaveChanges();

            return(size.Name + " was succesfully added!");
        }
        catch (Exception e)
        {
            return("Error " + e);
        }
    }
Esempio n. 5
0
 public List <Product> GetAllProducts()
 {
     try
     {
         using (TshirtDBEntities db = new TshirtDBEntities())
         {
             List <Product> products = (from x in db.Products
                                        select x).ToList();
             return(products);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Esempio n. 6
0
    public string DeletePurchase(int id)
    {
        try
        {
            TshirtDBEntities db = new TshirtDBEntities();
            Purchase         p  = db.Purchases.Find(id);

            db.Purchases.Attach(p);
            db.Purchases.Remove(p);
            db.SaveChanges();
            return(p.Date + " was succesfully deleted!");
        }
        catch (Exception e)
        {
            return("Error " + e);
        }
    }
Esempio n. 7
0
 public List <Product> GetProductsByType(int typeId)
 {
     try
     {
         using (TshirtDBEntities db = new TshirtDBEntities())
         {
             List <Product> products = (from x in db.Products
                                        where x.TypeID == typeId
                                        select x).ToList();
             return(products);
         }
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Esempio n. 8
0
    public string UpdateSize(int id, Size size)
    {
        try
        {
            TshirtDBEntities db = new TshirtDBEntities();
            Size             p  = db.Sizes.Find(id);

            p.Name = size.Name;
            db.SaveChanges();

            return(size.Name + " was succesfully updated!");
        }
        catch (Exception e)
        {
            return("Error " + e);
        }
    }
Esempio n. 9
0
    public string UpdatePurchase(int id, Purchase purchase)
    {
        try
        {
            TshirtDBEntities db = new TshirtDBEntities();
            Purchase         p  = db.Purchases.Find(id);

            p.Date      = purchase.Date;
            p.Amount    = purchase.Amount;
            p.IsInCart  = purchase.IsInCart;
            p.ProductID = purchase.ProductID;
            db.SaveChanges();
            return(purchase.Date + " was succesfully updated!");
        }
        catch (Exception e)
        {
            return("Error " + e);
        }
    }
Esempio n. 10
0
    public string UpdateProduct(int id, Product product)
    {
        try
        {
            TshirtDBEntities db = new TshirtDBEntities();
            Product          p  = db.Products.Find(id);

            p.Name        = product.Name;
            p.Price       = product.Price;
            p.Image       = product.Image;
            p.Description = product.Description;
            p.TypeID      = product.TypeID;
            db.SaveChanges();

            return(product.Name + " was succesfully updated!");
        }
        catch (Exception e)
        {
            return("Error " + e);
        }
    }