private int CreateProductInternal(ProductCreateParameters parameters) { var product = _entities.Products.Create <DbModel.Product>(); if (parameters.ProductModel != null) { product.ProductModelID = CreateProductModel(parameters.ProductModel); } if (parameters.ProductSubcategoryId.HasValue) { var subcategory = _entities.ProductSubcategories.FirstOrDefault(x => x.ProductSubcategoryID == parameters.ProductSubcategoryId.Value); if (subcategory == null) { throw new ArgumentException($"Subcategory with id '{parameters.ProductSubcategoryId}' is not found.", nameof(parameters.ProductSubcategoryId)); } product.ProductSubcategoryID = parameters.ProductSubcategoryId.Value; } product.Name = parameters.Name; product.ProductNumber = parameters.ProductNumber; product.Class = parameters.Class; product.Color = parameters.Color; product.DaysToManufacture = parameters.DaysToManufacture; product.ReorderPoint = parameters.ReorderPoint; product.MakeFlag = parameters.MakeFlag; product.FinishedGoodsFlag = parameters.FinishedGoodsFlag; product.SafetyStockLevel = parameters.SafetyStockLevel; product.StandardCost = parameters.StandardCost; product.ListPrice = parameters.ListPrice; product.ProductLine = parameters.ProductLine; product.Style = parameters.Style; product.SellStartDate = parameters.SellStartDate; product.SellEndDate = parameters.SellEndDate; product.DiscontinuedDate = parameters.DiscontinuedDate; product.Size = parameters.Size; product.SizeUnitMeasureCode = parameters.SizeUnitMeasureCode; product.Weight = parameters.Weight; product.WeightUnitMeasureCode = parameters.WeightUnitMeasureCode; return(product.ProductID); }
public int CreateProduct(ProductCreateParameters parameters) { if (parameters == null) { throw new ArgumentException("Parameters is required", nameof(parameters)); } using (var transaction = _entities.Database.BeginTransaction()) { try { var result = CreateProductInternal(parameters); transaction.Commit(); return(result); } catch { transaction.Rollback(); throw; } } }