public void DeleteOrder(string id)
 {
     try
     {
         int orderWithIdToDelete = 0;
         if (int.TryParse(id, out orderWithIdToDelete))
         {
             using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
             {
                 var fetchedOrderToDelete = context.Orders.Where(o => o.orderID == orderWithIdToDelete).FirstOrDefault();
                 if (fetchedOrderToDelete != null)
                 {
                     context.Orders.Remove(fetchedOrderToDelete);
                     context.SaveChanges();
                 }
                 else
                 {
                     throw new WebFaultException <Error>(new Error("Order with ID " + id + " not found.", ""), System.Net.HttpStatusCode.NotFound);
                 }
             }
         }
     }
     catch (WebFaultException <Error> ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw new WebFaultException <Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void UpdateCustomer(Customer customer)
 {
     try
     {
         using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
         {
             var fetchedCustomerToUpdate = context.Customers.Where(o => o.custID == customer.custID).FirstOrDefault();
             if (fetchedCustomerToUpdate != null)
             {
                 fetchedCustomerToUpdate.firstName   = customer.firstName;
                 fetchedCustomerToUpdate.lastName    = customer.lastName;
                 fetchedCustomerToUpdate.phoneNumber = customer.phoneNumber;
                 context.SaveChanges();
             }
             else
             {
                 throw new WebFaultException <Error>(new Error("Customer with ID " + customer.custID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
             }
         }
     }
     catch (Exception ex)
     {
         throw new WebFaultException <Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void DeleteCart(string orderId, string prodId)
 {
     try
     {
         int orderIdToDelete = 0;
         int prodIdToDelete  = 0;
         if (int.TryParse(orderId, out orderIdToDelete) && int.TryParse(prodId, out prodIdToDelete))
         {
             using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
             {
                 var fetchedCartToDelete = context.Carts.Where(o => o.orderID == orderIdToDelete && o.prodID == prodIdToDelete).FirstOrDefault();
                 if (fetchedCartToDelete != null)
                 {
                     context.Carts.Remove(fetchedCartToDelete);
                     context.SaveChanges();
                 }
                 else
                 {
                     throw new WebFaultException <Error>(new Error("Cart with order ID " + orderId + " and product ID " + prodId + " not found.", ""), System.Net.HttpStatusCode.NotFound);
                 }
             }
         }
     }
     catch (WebFaultException <Error> ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw new WebFaultException <Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void AddProduct(Product product)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         context.Products.Add(product.GenerateDbModel());
         context.SaveChanges();
     }
 }
 public void AddOrder(Order order)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         context.Orders.Add(order.GenerateDbModel());
         context.SaveChanges();
     }
 }
 public void AddOrder(Order order)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         context.Orders.Add(order.GenerateDbModel());
         context.SaveChanges();
     }
 }
 public void AddCustomer(Customer customer)
 {
     try
     {
         using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
         {
             context.Customers.Add(customer.GenerateDbModel());
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new WebFaultException<Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void AddCustomer(Customer customer)
 {
     try
     {
         using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
         {
             context.Customers.Add(customer.GenerateDbModel());
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw new WebFaultException <Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void UpdateCart(Cart cart)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         var fetchedCartToUpdate = context.Carts.Where(o => o.orderID == cart.orderID && o.prodID == cart.prodID).FirstOrDefault();
         if (fetchedCartToUpdate != null)
         {
             fetchedCartToUpdate.quantity = cart.quantity;
             context.SaveChanges();
         }
         else
         {
             throw new WebFaultException <Error>(new Error("Cart with order ID " + cart.orderID + " and product ID " + cart.prodID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
         }
     }
 }
 public void UpdateOrder(Order order)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         var fetchedOrderToUpdate = context.Orders.Where(o => o.orderID == order.orderID).FirstOrDefault();
         if (fetchedOrderToUpdate != null)
         {
             fetchedOrderToUpdate.custID    = order.custID;
             fetchedOrderToUpdate.orderDate = order.orderDate;
             fetchedOrderToUpdate.poNumber  = order.poNumber;
             context.SaveChanges();
         }
         else
         {
             throw new WebFaultException <Error>(new Error("Order with ID " + order.orderID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
         }
     }
 }
 public void UpdateProduct(Product product)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         var fetchedProductToUpdate = context.Products.Where(o => o.prodID == product.prodID).FirstOrDefault();
         if (fetchedProductToUpdate != null)
         {
             fetchedProductToUpdate.prodName   = product.prodName;
             fetchedProductToUpdate.price      = product.price;
             fetchedProductToUpdate.prodWeight = product.prodWeight;
             fetchedProductToUpdate.inStock    = product.inStock;
             context.SaveChanges();
         }
         else
         {
             throw new WebFaultException <Error>(new Error("Product with ID " + product.prodID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
         }
     }
 }
 public void AddCart(Cart cart)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         var product = context.Products.Where(o => o.prodID == cart.prodID).FirstOrDefault();
         if (product == null)
         {
             throw new WebFaultException <Error>(new Error("Product with ID " + cart.prodID + " does not exist.", ""), System.Net.HttpStatusCode.BadRequest);
         }
         else if (product.inStock == false)
         {
             throw new WebFaultException <Error>(new Error("Product with ID " + cart.prodID + " not in stock.", ""), System.Net.HttpStatusCode.BadRequest);
         }
         else
         {
             context.Carts.Add(cart.GenerateDbModel());
             context.SaveChanges();
         }
     }
 }
        public void AddCart(Cart cart)
        {
            using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
            {
                var product = context.Products.Where(o => o.prodID == cart.prodID).FirstOrDefault();
                if (product == null)
                {
                    throw new WebFaultException<Error>(new Error("Product with ID " + cart.prodID + " does not exist.",""), System.Net.HttpStatusCode.BadRequest);
                }
                else if (product.inStock == false)
                {
                    throw new WebFaultException<Error>(new Error("Product with ID " + cart.prodID + " not in stock.", ""), System.Net.HttpStatusCode.BadRequest);
                }
                else
                {

                    context.Carts.Add(cart.GenerateDbModel());
                    context.SaveChanges();
                }

            }
        }
 public void DeleteOrder(string id)
 {
     try
     {
         int orderWithIdToDelete = 0;
         if (int.TryParse(id, out orderWithIdToDelete))
         {
             using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
             {
                 var fetchedOrderToDelete = context.Orders.Where(o => o.orderID == orderWithIdToDelete).FirstOrDefault();
                 if (fetchedOrderToDelete != null)
                 {
                     context.Orders.Remove(fetchedOrderToDelete);
                     context.SaveChanges();
                 }
                 else
                 {
                     throw new WebFaultException<Error>(new Error("Order with ID " + id + " not found.", ""), System.Net.HttpStatusCode.NotFound);
                 }
             }
         }
     }
     catch (WebFaultException<Error> ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw new WebFaultException<Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void UpdateCart(Cart cart)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         var fetchedCartToUpdate = context.Carts.Where(o => o.orderID == cart.orderID && o.prodID == cart.prodID).FirstOrDefault();
         if (fetchedCartToUpdate != null)
         {
             fetchedCartToUpdate.quantity = cart.quantity;
             context.SaveChanges();
         }
         else
         {
             throw new WebFaultException<Error>(new Error("Cart with order ID " + cart.orderID + " and product ID " + cart.prodID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
         }
     }
 }
 public void UpdateCustomer(Customer customer)
 {
     try
     {
         using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
         {
             var fetchedCustomerToUpdate = context.Customers.Where(o => o.custID == customer.custID).FirstOrDefault();
             if (fetchedCustomerToUpdate != null)
             {
                 fetchedCustomerToUpdate.firstName = customer.firstName;
                 fetchedCustomerToUpdate.lastName = customer.lastName;
                 fetchedCustomerToUpdate.phoneNumber = customer.phoneNumber;
                 context.SaveChanges();
             }
             else
             {
                 throw new WebFaultException<Error>(new Error("Customer with ID " + customer.custID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
             }
         }
     }
     catch (Exception ex)
     {
         throw new WebFaultException<Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void UpdateOrder(Order order)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         var fetchedOrderToUpdate = context.Orders.Where(o => o.orderID == order.orderID).FirstOrDefault();
         if (fetchedOrderToUpdate != null)
         {
             fetchedOrderToUpdate.custID = order.custID;
             fetchedOrderToUpdate.orderDate = order.orderDate;
             fetchedOrderToUpdate.poNumber = order.poNumber;
             context.SaveChanges();
         }
         else
         {
             throw new WebFaultException<Error>(new Error("Order with ID " + order.orderID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
         }
     }
 }
 public void UpdateProduct(Product product)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         var fetchedProductToUpdate = context.Products.Where(o => o.prodID == product.prodID).FirstOrDefault();
         if (fetchedProductToUpdate != null)
         {
             fetchedProductToUpdate.prodName = product.prodName;
             fetchedProductToUpdate.price = product.price;
             fetchedProductToUpdate.prodWeight = product.prodWeight;
             fetchedProductToUpdate.inStock = product.inStock;
             context.SaveChanges();
         }
         else
         {
             throw new WebFaultException<Error>(new Error("Product with ID " + product.prodID + " not found.", ""), System.Net.HttpStatusCode.NotFound);
         }
     }
 }
 public void DeleteCart(string orderId, string prodId)
 {
     try
     {
         int orderIdToDelete = 0;
         int prodIdToDelete = 0;
         if (int.TryParse(orderId, out orderIdToDelete) && int.TryParse(prodId, out prodIdToDelete))
         {
             using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
             {
                 var fetchedCartToDelete = context.Carts.Where(o => o.orderID == orderIdToDelete && o.prodID == prodIdToDelete).FirstOrDefault();
                 if (fetchedCartToDelete != null)
                 {
                     context.Carts.Remove(fetchedCartToDelete);
                     context.SaveChanges();
                 }
                 else
                 {
                     throw new WebFaultException<Error>(new Error("Cart with order ID " + orderId + " and product ID " + prodId + " not found.", ""), System.Net.HttpStatusCode.NotFound);
                 }
             }
         }
     }
     catch (WebFaultException<Error> ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw new WebFaultException<Error>(new Error("Unexpected exception!", ex.Message), System.Net.HttpStatusCode.InternalServerError);
     }
 }
 public void AddProduct(Product product)
 {
     using (var context = new Models.CrazyMelvinsShoppingEmporiumDbEntities())
     {
         context.Products.Add(product.GenerateDbModel());
         context.SaveChanges();
     }
 }