예제 #1
0
		public PriceExtra AddPriceExtra(int productId, int priceExtraCategoryId)
		{
			Argument.Require(productId > 0, "Product identifier is required.");
			Argument.Require(priceExtraCategoryId > 0, "Price extra category id is required.");

			var priceExtra = new PriceExtra
			{
				PriceExtraCategoryId = priceExtraCategoryId,
				ProductId = productId,
			};

			using (var storage = new Storage())
			{
				var existingExtra = storage
					.PriceExtras
					.SingleOrDefault(pe => pe.ProductId == productId && pe.PriceExtraCategoryId == priceExtraCategoryId);

				if (null == existingExtra)
				{
					priceExtra.PriceExtraId = Convert.ToInt32(storage.InsertWithIdentity(priceExtra));
				}
				else
				{
					priceExtra.PriceExtraId = existingExtra.PriceExtraId;
				}
			}

			return priceExtra;
		}
예제 #2
0
		public void StorageShouldCreateManufacturers()
		{
			using (var storage = new Storage())
			{
				var result = storage.InsertWithIdentity(new Manufacturer
				{
					IsPrimary = true,
					Name = "Severstahl",
				});

				var result2 = storage.InsertWithIdentity(new Manufacturer
				{
					IsPrimary = true,
					Name = "Severstahl2",
				});

				Debug.WriteLine(result);
				Debug.WriteLine(result2);

				Assert.AreEqual(2, storage.Manufacturers.ToList().Count);
			}
		}
예제 #3
0
		public Product CreateProduct(int manufacturerId, int rawMaterialId, string size, decimal thickness)
		{
			Argument.Require(manufacturerId > 0, "Manufacturer id is required.");
			Argument.Require(rawMaterialId > 0, "Raw material id is required.");
			Argument.NotNullOrEmpty(size, "Product size is required.");
			Argument.Require(thickness > 0, "Product thickness is required.");

			var product = new Product
			{
				ManufacturerId = manufacturerId,
				RawMaterialId = rawMaterialId,
				Name = size,
				Thickness = thickness,
			};

			using (var storage = new Storage())
			{
				product.ProductId = Convert.ToInt32(storage.InsertWithIdentity(product));
			}

			return product;
		}
예제 #4
0
		public void Seed(Storage storage, int plantCode)
		{
			storage.Insert(new Manufacturer { Name = "ЧерМК", IsPrimary = true });
			storage.Insert(new Manufacturer { Name = "НЛМК", IsPrimary = true });
			storage.Insert(new Manufacturer { Name = "ММК", IsPrimary = true });
			//storage.Insert(new Manufacturer { Name = "(1) КТЗ", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) РязТЗ", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) БТЗ", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) ОМК", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) СЗТЗ", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) ТПК Союз", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) Машпрофиль", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) Профиль А", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(1) БИС", IsPrimary = false });

			storage.Insert(new Manufacturer { Name = "(2) ВестМет", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(2) Промизделия", IsPrimary = false });
			storage.Insert(new Manufacturer { Name = "(2) ТЭМПО", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(2) ОМК", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(2) ТМК", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(2) Уралтрубпром", IsPrimary = false });
			//storage.Insert(new Manufacturer { Name = "(2) Исаевский ТЗ", IsPrimary = false });

			storage.Insert(new PriceExtraCategory { Name = "Себестоимость" });
			storage.Insert(new PriceExtraCategory { Name = "Доставка материала" });
			storage.Insert(new PriceExtraCategory { Name = "Передел" });
			storage.Insert(new PriceExtraCategory { Name = "Доставка до Москвы" });

			var allManufacturers = storage
				.Manufacturers
				.ToList();

			var primaryManufacturers = allManufacturers.Where(m => m.IsPrimary);
			var nonPrimaryManufacturers = allManufacturers.Where(m => !m.IsPrimary);

			var materialThickness = EnumerateThickness(plantCode);

			foreach (var thickness in materialThickness)
			{
				foreach (var rollType in new [] {RollType.Cold, RollType.Hot })
				{
					foreach (var alloyType in new[] {AlloyType.LowAlloy, AlloyType.Regular })
					{
						var materialType = new RawMaterialType
						{
							AlloyType = alloyType,
							RollType = rollType,
							Thickness = thickness,
						};

						SetMaterialTypeName(materialType);

						var materialTypeId = storage.InsertWithIdentity(materialType);

						foreach (var primaryManufacturer in primaryManufacturers)
						{
							var rawMaterialId = storage.InsertWithIdentity(
								new RawMaterial
								{
									ManufacturerId = primaryManufacturer.ManufacturerId,
									RawMaterialTypeId = Convert.ToInt32(materialTypeId),
								});

							foreach (var productName in EnumerateProductNames(plantCode, rollType, alloyType))
							{
								storage.Insert(
									new Product
									{
										ManufacturerId = primaryManufacturer.ManufacturerId,
										RawMaterialId = Convert.ToInt32(rawMaterialId),
										Name = productName,
										Thickness = thickness,
									});


								foreach (var nonPrimaryManufacturer in nonPrimaryManufacturers)
								{
									storage.Insert(
										new Product
										{
											ManufacturerId = nonPrimaryManufacturer.ManufacturerId,
											RawMaterialId = Convert.ToInt32(rawMaterialId),
											Name = productName,
											Thickness = thickness,
										});
								}
								
							}
						}
					}
				}
			}
		}