コード例 #1
0
        public VehicleInventoryViewModel GetVehicleInventoryReport()
        {
            VehicleInventoryViewModel report = new VehicleInventoryViewModel();

            report.UsedInventory = new List <InventoryReport>();
            report.NewInventory  = new List <InventoryReport>();
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = _connection;

                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "GetUsedInventoryReport";
                cmd.CommandType = CommandType.StoredProcedure;

                conn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        InventoryReport current = new InventoryReport();

                        current.Count      = (int)dr["Count"];
                        current.Year       = (int)dr["Year"];
                        current.MakeName   = dr["MakeName"].ToString();
                        current.ModelName  = dr["ModelName"].ToString();
                        current.TotalStock = (decimal)dr["Stock"];

                        report.UsedInventory.Add(current);
                    }
                }
            }
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = _connection;

                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "GetNewInventoryReport";
                cmd.CommandType = CommandType.StoredProcedure;

                conn.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        InventoryReport current = new InventoryReport();

                        current.Count      = (int)dr["Count"];
                        current.Year       = (int)dr["Year"];
                        current.MakeName   = dr["MakeName"].ToString();
                        current.ModelName  = dr["ModelName"].ToString();
                        current.TotalStock = (decimal)dr["Stock"];

                        report.NewInventory.Add(current);
                    }
                }
            }
            return(report);
        }
コード例 #2
0
        public VehicleInventoryViewModel GetVehicleInventoryReport()
        {
            VehicleInventoryViewModel report = new VehicleInventoryViewModel();

            report.NewInventory  = new List <InventoryReport>();
            report.UsedInventory = new List <InventoryReport>();

            MakeRepoMock makeRepo = new MakeRepoMock();
            var          makes    = makeRepo.GetAll();

            ModelRepoMock modelRepo = new ModelRepoMock();
            var           models    = modelRepo.GetAll();

            foreach (var v in _vehicles)
            {
                InventoryReport r = new InventoryReport()
                {
                    Count      = 1,
                    MakeName   = makes.FirstOrDefault(x => x.MakeId == v.MakeId).Name,
                    ModelName  = models.FirstOrDefault(x => x.ModelId == v.ModelId).ModelName,
                    TotalStock = v.SalePrice,
                    Year       = v.Year
                };
                if (v.Type == "New")
                {
                    report.NewInventory.Add(r);
                }
                else
                {
                    report.UsedInventory.Add(r);
                }
            }
            return(report);
        }