OL.Demo.WebForm/Model/ProductRepository.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OL.Demo.WebForm.Model
{
    public class ProductRepository
    {
        static List<Product> listProduct;

        static ProductRepository()
        {
            listProduct = new List<Product>();
            listProduct.Add(new Model.Product { ID = "1", Name = "特仑苏牛奶", Price = 5.5m });
            listProduct.Add(new Model.Product { ID = "2", Name = "苹果", Price = 7.8m });
            listProduct.Add(new Model.Product { ID = "3", Name = "巧克力", Price = 7m });
            listProduct.Add(new Model.Product { ID = "4", Name = "面条", Price = 4.5m });
            listProduct.Add(new Model.Product { ID = "5", Name = "米", Price = 3.9m });
            listProduct.Add(new Model.Product { ID = "6", Name = "猪肉", Price = 9.8m });
            listProduct.Add(new Model.Product { ID = "7", Name = "盐", Price = 2m });
        }

        /// <summary>
        /// 获取产品列表
        /// </summary>
        /// <returns></returns>
        public static List<Product> GetProductList()
        {
            return listProduct;
        }

        public static Product GetProduct(string id)
        {
            var list = listProduct.Where(x => x.ID == id).ToList();
            if (list.Count() > 0)
            {
                var tmpModel = list[0];
                return tmpModel;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 添加产品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool AddProduct(Product model)
        {
            listProduct.Add(model);
            return true;
        }

        /// <summary>
        /// 修改产品
        /// </summary>
后面还有 39 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。