当前位置: 首页>>代码示例>>C#>>正文


C# ProductRepository.SaveOrUpdate方法代码示例

本文整理汇总了C#中ProductRepository.SaveOrUpdate方法的典型用法代码示例。如果您正苦于以下问题:C# ProductRepository.SaveOrUpdate方法的具体用法?C# ProductRepository.SaveOrUpdate怎么用?C# ProductRepository.SaveOrUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ProductRepository的用法示例。


在下文中一共展示了ProductRepository.SaveOrUpdate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrepareProducts

        private void PrepareProducts()
        {
            var productRepository = new ProductRepository();

            _finishGood1 = new Product { ProductType = ProductType.FinishGood, Name = "F1", DrawingNumber = "6606"};
            _finishGood2 = new Product { ProductType = ProductType.FinishGood, Name = "F2", DrawingNumber = "9393"};
            _rawMaterial1 = new Product { ProductType = ProductType.RawMaterial,Name = "R1"};
            _rawMaterial2 = new Product { ProductType = ProductType.RawMaterial,Name = "R2"};

            productRepository.SaveOrUpdate(_finishGood1);
            productRepository.SaveOrUpdate(_finishGood2);
            productRepository.SaveOrUpdate(_rawMaterial1);
            productRepository.SaveOrUpdate(_rawMaterial2);

            FlushAndClearSession();
        }
开发者ID:JohnCai,项目名称:LonggongMM,代码行数:16,代码来源:RecipeRepositoryTest.cs

示例2: ProcessRequest

        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);
        }
开发者ID:bbcCorp,项目名称:Linq2Sql,代码行数:79,代码来源:UpdateProduct.ashx.cs


注:本文中的ProductRepository.SaveOrUpdate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。