Beispiel #1
0
 partial void DeleteProduct(Product instance);
Beispiel #2
0
 partial void UpdateProduct(Product instance);
Beispiel #3
0
 partial void InsertProduct(Product instance);
Beispiel #4
0
		private void detach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Supplier = null;
		}
Beispiel #5
0
		private void attach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.Supplier = this;
		}
Beispiel #6
0
        public void ProcessRequest(HttpContext context)
        {
            String output;

            try
            {
                var formCollection = context.Request.Form;

                Product prod = new Product();
                String prodID = formCollection["id"];

                if (prodID.Equals("_empty"))
                {
                    prod.ProductID = 0;
                }
                else
                {
                    prod.ProductID = Convert.ToInt32(prodID);
                }

                var operation = formCollection["oper"];

                using (ProductRepository repo = new ProductRepository())
                {

                    if (operation.Equals("add") || operation.Equals("edit"))
                    {

                        prod.ProductName = formCollection["ProductName"];
                        prod.SupplierID = Convert.ToInt32(formCollection["SupplierID"]);
                        prod.UnitPrice = Convert.ToDecimal(formCollection["UnitPrice"]);
                        prod.UnitsInStock = Convert.ToSByte(formCollection["UnitsInStock"]);
                        prod.UnitsOnOrder = Convert.ToSByte(formCollection["UnitsOnOrder"]);

                        if (logger.IsDebugEnabled)
                        {
                            logger.Debug("Received request for operation: " + operation + " for Product ID: " + prod.ProductID);

                            logger.Debug(prod);
                        }

                        repo.SaveOrUpdate(prod);
                    }
                    else if (operation.Equals("del"))
                    {

                        if (logger.IsDebugEnabled)
                        {
                            logger.Debug("Received request to delete Product ID: " + prod.ProductID);

                            logger.Debug(prod);
                        }
                        repo.Delete(prod);

                    }

                }

                output = "Operation successful.";
            }
            catch (Exception ex)
            {
                if (logger.IsDebugEnabled)
                {
                    output = ex.Message;
                }
                else
                {
                    output = "Oops! We encountered an error while performing the requested operation!";

                }

                logger.Error(ex);
                throw new Exception(output);
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(output);
        }