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


C# ProductRepository.Create方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            using (var context = new DatabaseContext())
            {
                ICustomerRepository customers = new CustomerRepository(context);
                IProductRepository products = new ProductRepository(context);

                var github = new Customer() { IsActive = true, Name = "GitHub" };
                var microsoft = new Customer() {IsActive = true, Name = "Microsoft"};
                var apple = new Customer() { IsActive = false, Name = "Apple" };

                customers.Create(github);
                customers.Create(microsoft);
                customers.Create(apple);

                var windows = new Product()
                {
                    CustomerId = microsoft.Id,
                    Description = "The best OS!",
                    Name = "Windows 10",
                    Sku = "AWESOME1"
                };

                var sourceControl = new Product()
                {
                    CustomerId = github.Id,
                    Description = "The best hosted source control solution!",
                    Name = "GitHub Enterprise",
                    Sku = "AWESOME2"
                };

                var iphone = new Product()
                {
                    CustomerId = apple.Id,
                    Description = "The best phone ever created!",
                    Name = "iPhone 6S",
                    Sku = "AWESOME3"
                };

                products.Create(windows);
                products.Create(sourceControl);
                products.Create(iphone);

                foreach (var customer in customers.All.WhereIsActive().ToList())
                {
                    Console.WriteLine(customer.Name);
                }

                foreach (var customer in customers.GetAllWithProducts().WhereNameBeginsWith("Git").WhereIsActive().ToList())
                {
                    Console.WriteLine(customer.Name);

                    foreach (var product in customer.Products)
                    {
                        Console.WriteLine("-- {0}", product.Name);
                    }
                }
            }
        }
开发者ID:beingawesome,项目名称:Patterns,代码行数:59,代码来源:Program.cs

示例2: Get

        public IHttpActionResult Get(int id)
        {
            try
            {
                Product product;
                var productRepository = new ProductRepository();
                if (id > 0)
                {
                    var products = productRepository.Retrieve();
                    product = products.FirstOrDefault(p => p.ProductId == id);
                    if (product == null)
                    {
                        return NotFound();
                    }
                }
                else
                {
                    product = productRepository.Create();
                }
                return Ok(product);
            }
            catch (Exception ex)
            {

                return InternalServerError(ex);
            }
        }
开发者ID:nandotech,项目名称:umgbeta,代码行数:27,代码来源:ProductsController.cs

示例3: Get

        // GET: api/Products/5
        public IHttpActionResult Get(int id)
        {
            ProductRepository repo = new ProductRepository();
            Product product;

            if (id == 0)
            {
                product = repo.Create();
            }
            else
            {
                product = repo.Retrieve().FirstOrDefault(p => p.ProductId == id);
                if (product == null)
                {
                    return NotFound();
                }
            }

            return Ok(product);
        }
开发者ID:yanivps,项目名称:WebApi-Angular-APM,代码行数:21,代码来源:ProductsController.cs

示例4: Create

        public ActionResult Create(Product product)
        {
            try
            {
                var poductRep = new ProductRepository();

                if (poductRep.Create(product))
                    return RedirectToAction("Index");
            }
            catch
            {
            }

            var rep = new SubcategoryRepository();
            var viewModel = new CreateProductViewModel();

            viewModel.subcategories = rep.Table;
            viewModel.product = product;

            return View(viewModel);
        }
开发者ID:kioltk,项目名称:ColonitShopMVC,代码行数:21,代码来源:ProductController.cs

示例5: Create

        public ActionResult Create([Bind(Include = "Name, Description, Preco")]
            Product product, HttpPostedFileBase upload)
        {
            try
            {
                using (var reader = new BinaryReader(upload.InputStream))
                {
                    product.Photo = reader.ReadBytes(upload.ContentLength);
                }

                using (var productRep = new ProductRepository())
                {
                   productRep.Create(product);
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
开发者ID:fabiopsouza,项目名称:Learning.AspNetMVC,代码行数:22,代码来源:ProductController.cs

示例6: Get

        // GET: api/Products/5
        public IHttpActionResult Get(int id)
        {
            Product product;
            var productRepository = new ProductRepository();

            if (id > 0)
            {
                product = productRepository.Retrieve().FirstOrDefault(p => p.ProductId == id);

                if (product == null)
                {
                    return NotFound();
                }
            }
            else
            {
                //Object is initialized with default values
                product = productRepository.Create();
            }

            return Ok(product);
        }
开发者ID:alexandrupero,项目名称:product-management,代码行数:23,代码来源:ProductsController.cs


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