示例#1
0
    //Update qty from shopping cart page
    public void UpdateQuantity(int id, int quantity)
    {
        ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
        Cart cart = db.Carts.Find(id);

        cart.Quantity = quantity;

        //Save changes to database
        db.SaveChanges();
    }
    public string InsertCategory(Category category)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Categories.Add(category);
            db.SaveChanges();

            return category.Name + " was successfully inserted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
    public string InsertSupplier(Supplier supplier)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Suppliers.Add(supplier);
            db.SaveChanges();

            return(supplier.Name + " was successfully inserted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
    public string InsertSupplier(Supplier supplier)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Suppliers.Add(supplier);
            db.SaveChanges();

            return supplier.Name + " was successfully inserted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#5
0
    public string InsertCart(Cart cart)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Carts.Add(cart);
            db.SaveChanges();

            return cart.DataPurchased + " was successfully inserted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#6
0
    public string InsertOrder(Order order)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Orders.Add(order);
            db.SaveChanges();

            return order.ID.ToString();
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
    public string InsertProduct(Product product)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Products.Add(product);
            db.SaveChanges();

            return(product.Name + " was successfully inserted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#8
0
    public string InsertCart(Cart cart)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Carts.Add(cart);
            db.SaveChanges();

            return(cart.DataPurchased + " was successfully inserted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#9
0
    public string InsertOrder(Order order)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Orders.Add(order);
            db.SaveChanges();

            return(order.ID.ToString());
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#10
0
    public string InsertClient(Client client)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Clients.Add(client);
            db.SaveChanges();

            return client.Name + " was successfully inserted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#11
0
    public string InsertClient(Client client)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Clients.Add(client);
            db.SaveChanges();

            return(client.Name + " was successfully inserted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#12
0
    public string InsertCategory(Category category)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Categories.Add(category);
            db.SaveChanges();

            return(category.Name + " was successfully inserted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#13
0
	public string InsertProduct(Product product)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            db.Products.Add(product);
            db.SaveChanges();

            return product.Name + " was successfully inserted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#14
0
    //Mark all the added products as paid, after checkout
    public void MarkOrderAsPaid(List <Cart> carts)
    {
        ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

        if (carts != null)
        {
            foreach (Cart cart in carts)
            {
                Cart oldCart = db.Carts.Find(cart.ID);
                oldCart.DataPurchased = DateTime.Now;
                oldCart.IsInCart      = false;
            }
        }

        db.SaveChanges();
    }
示例#15
0
    //Update qty of same product from singleProduct page
    public string UpdateQty(int productId, int quantity, int clientId)
    {
        ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
        var cart = (from x in db.Carts
                    where x.ProductID == productId &&
                    x.IsInCart &&
                    x.ClientID == clientId
                    select x).FirstOrDefault();

        int oldQuantity = cart.Quantity;
        int newQuantity = oldQuantity + quantity;

        cart.Quantity = newQuantity;
        db.SaveChanges();

        return("Update Successfully!");
    }
示例#16
0
    public string DeleteProduct(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Product product             = db.Products.Find(id);

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

            return(product.Name + " was successfully deleted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#17
0
    public string DeleteOrder(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Order order = db.Orders.Find(id);

            db.Orders.Attach(order);
            db.Orders.Remove(order);
            db.SaveChanges();

            return order.ID + " was successfully delected!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#18
0
    public string DeleteClient(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Client client = db.Clients.Find(id);

            db.Clients.Attach(client);
            db.Clients.Remove(client);
            db.SaveChanges();

            return(client.Name + " was successfully deleted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#19
0
    public string DeleteProduct(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Product product = db.Products.Find(id);

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

            return product.Name +  " was successfully deleted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#20
0
    public string DeleteCategory(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Category category = db.Categories.Find(id);

            db.Categories.Attach(category);
            db.Categories.Remove(category);
            db.SaveChanges();

            return category.Name + " was successfully deleted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#21
0
    public string DeleteSupplier(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Supplier supplier           = db.Suppliers.Find(id);

            db.Suppliers.Attach(supplier);
            db.Suppliers.Remove(supplier);
            db.SaveChanges();

            return(supplier.Name + " was successfully delected!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#22
0
    public string DeleteSupplier(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Supplier supplier = db.Suppliers.Find(id);

            db.Suppliers.Attach(supplier);
            db.Suppliers.Remove(supplier);
            db.SaveChanges();

            return supplier.Name + " was successfully delected!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#23
0
    public string DeleteCart(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Cart cart = db.Carts.Find(id);

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

            return cart.DataPurchased + " was successfully deleted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#24
0
    public string DeleteCategory(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Category category           = db.Categories.Find(id);

            db.Categories.Attach(category);
            db.Categories.Remove(category);
            db.SaveChanges();

            return(category.Name + " was successfully deleted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#25
0
    public string DeleteClient(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Client client = db.Clients.Find(id);

            db.Clients.Attach(client);
            db.Clients.Remove(client);
            db.SaveChanges();

            return client.Name + " was successfully deleted!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#26
0
    public string DeleteCart(int id)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
            Cart cart = db.Carts.Find(id);

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

            return(cart.DataPurchased + " was successfully deleted!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#27
0
    public string UpdateCategory(int id, Category category)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Category p = db.Categories.Find(id);

            p.Name        = category.Name;
            p.Description = category.Description;

            db.SaveChanges();
            return(category.Name + " was successfully updated!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#28
0
    public string UpdateCategory(int id, Category category)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Category p = db.Categories.Find(id);

            p.Name = category.Name;
            p.Description = category.Description;
        
            db.SaveChanges();
            return category.Name + " was successfully updated!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#29
0
    public string UpdateSupplier(int id, Supplier supplier)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Supplier p = db.Suppliers.Find(id);

            p.Name         = supplier.Name;
            p.PhoneNumber  = supplier.PhoneNumber;
            p.EmailAddress = supplier.EmailAddress;

            db.SaveChanges();
            return(supplier.Name + " was successfully updated!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#30
0
    public string UpdateSupplier(int id, Supplier supplier)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Supplier p = db.Suppliers.Find(id);

            p.Name = supplier.Name;
            p.PhoneNumber = supplier.PhoneNumber;
            p.EmailAddress = supplier.EmailAddress;

            db.SaveChanges();
            return supplier.Name + " was successfully updated!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#31
0
    public string UpdateOrder(int id, Order order)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Order p = db.Orders.Find(id);

            p.ClientID = order.ClientID;
            p.Status = order.Status;
            p.TotalAmount = order.TotalAmount;
            p.OrderDate = order.OrderDate;

            db.SaveChanges();
            return order.ID + " was successfully updated!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#32
0
    public string UpdateOrder(int id, Order order)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Order p = db.Orders.Find(id);

            p.ClientID    = order.ClientID;
            p.Status      = order.Status;
            p.TotalAmount = order.TotalAmount;
            p.OrderDate   = order.OrderDate;

            db.SaveChanges();
            return(order.ID + " was successfully updated!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#33
0
    public string UpdateClient(int id, Client client)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Client p = db.Clients.Find(id);

            p.Name = client.Name;
            p.Password = client.Password;
            p.PhoneNumber = client.PhoneNumber;
            p.EmailAddress = client.EmailAddress;
            p.HomeAddress = client.HomeAddress;

            db.SaveChanges();
            return client.Name + " was successfully updated!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#34
0
    public string UpdateClient(int id, Client client)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

            //Fetch object from db
            Client p = db.Clients.Find(id);

            p.Name         = client.Name;
            p.Password     = client.Password;
            p.PhoneNumber  = client.PhoneNumber;
            p.EmailAddress = client.EmailAddress;
            p.HomeAddress  = client.HomeAddress;

            db.SaveChanges();
            return(client.Name + " was successfully updated!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#35
0
    public string UpdateProduct(int id, Product product)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

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

            p.Name        = product.Name;
            p.Price       = product.Price;
            p.CategoryID  = product.CategoryID;
            p.Description = product.Description;
            p.SupplierID  = product.SupplierID;
            p.Image       = product.Image;
            p.Color       = product.Color;
            db.SaveChanges();
            return(product.Name + " was successfully updated!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#36
0
    public string UpdateCart(int id, Cart cart)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

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

            p.ClientID      = cart.ClientID;
            p.ProductID     = cart.ProductID;
            p.Status        = cart.Status;
            p.TotalCost     = cart.TotalCost;
            p.IsInCart      = cart.IsInCart;
            p.DataPurchased = cart.DataPurchased;

            db.SaveChanges();
            return(cart.DataPurchased + " was successfully updated!");
        }
        catch (Exception e)
        {
            return("Error:" + e);
        }
    }
示例#37
0
    public string UpdateProduct(int id, Product product)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

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

            p.Name = product.Name;
            p.Price = product.Price;
            p.CategoryID = product.CategoryID;
            p.Description = product.Description;
            p.SupplierID = product.SupplierID;
            p.Image = product.Image;
            p.Color = product.Color;
            db.SaveChanges();
            return product.Name + " was successfully updated!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#38
0
    public string UpdateCart(int id, Cart cart)
    {
        try
        {
            ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

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

            p.ClientID = cart.ClientID;
            p.ProductID = cart.ProductID;
            p.Status = cart.Status;
            p.TotalCost = cart.TotalCost;
            p.IsInCart = cart.IsInCart;
            p.DataPurchased = cart.DataPurchased;

            db.SaveChanges();
            return cart.DataPurchased + " was successfully updated!";
        }
        catch (Exception e)
        {
            return "Error:" + e;
        }
    }
示例#39
0
    //Update qty from shopping cart page
    public void UpdateQuantity (int id, int quantity)
    {
        ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
        Cart cart = db.Carts.Find(id);
        cart.Quantity = quantity;

        //Save changes to database
        db.SaveChanges();
    }
示例#40
0
    //Update qty of same product from singleProduct page 
    public string UpdateQty (int productId, int quantity, int clientId)
    {
        ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();
        var cart = (from x in db.Carts
                      where x.ProductID == productId
                      && x.IsInCart
                      && x.ClientID == clientId
                      select x).FirstOrDefault();

        int oldQuantity = cart.Quantity;
        int newQuantity = oldQuantity + quantity;

        cart.Quantity = newQuantity;
        db.SaveChanges();

        return "Update Successfully!";
    }
示例#41
0
    //Mark all the added products as paid, after checkout 
    public void MarkOrderAsPaid(List<Cart> carts)
    {
        ZHUW15sqlserver1Entities db = new ZHUW15sqlserver1Entities();

        if(carts != null)
        {
            foreach(Cart cart in carts)
            {
                Cart oldCart = db.Carts.Find(cart.ID);
                oldCart.DataPurchased = DateTime.Now;
                oldCart.IsInCart = false;
            }

        }

        db.SaveChanges();
    }