public ProductDetailsViewModel ShowUpdatedProduct(int id, UpdateProductViewModel userModel) { var dalModel = new ProductsDALModel(); //dalModel.ProductID = userModel.ProductID; dalModel.ProductID = userModel.ProductID; dalModel.ProductName = userModel.ProductName; //dalModel.SupplierID = userModel.SupplierID; //dalModel.CategoryID = userModel.CategoryID; dalModel.QuantityPerUnit = userModel.QuantityPerUnit; dalModel.UnitPrice = userModel.UnitPrice; dalModel.UnitsInStock = userModel.UnitsInStock; dalModel.UnitsOnOrder = userModel.UnitsOnOrder; dalModel.ReorderLevel = userModel.ReorderLevel; dalModel.Discontinued = userModel.Discontinued; _productStore.UpdateProduct(dalModel, id); var productDetails = new ProductDetailsViewModel(); productDetails.ProductName = dalModel.ProductName; productDetails.SupplierID = dalModel.SupplierID; productDetails.CategoryID = dalModel.CategoryID; productDetails.QuantityPerUnit = dalModel.QuantityPerUnit; productDetails.UnitPrice = dalModel.UnitPrice; productDetails.UnitsInStock = dalModel.UnitsInStock; productDetails.UnitsOnOrder = dalModel.UnitsOnOrder; productDetails.ReorderLevel = dalModel.ReorderLevel; productDetails.Discontinued = dalModel.Discontinued; return(productDetails); }
private ProductsDALModel MapToDALProduct(AddProductViewModel src) { var productsDALModel = new ProductsDALModel(); productsDALModel.ProductName = src.ProductName; productsDALModel.UnitPrice = src.UnitPrice; productsDALModel.UnitsInStock = src.UnitsInStock; return(productsDALModel); }
public ProductsViewModel AddProduct(AddProductViewModel userEnteredModel) { var dalModel = new ProductsDALModel(); dalModel.ProductName = userEnteredModel.ProductName; _productStore.InsertNewProduct(dalModel); var dalProducts = _productStore.SelectAllProducts(); return(MapProductViewModel(dalProducts)); }
private ProductsDALModel MapToProductDALModel(AddProductViewModel model) { var dalProduct = new ProductsDALModel(); dalProduct.ProductName = model.ProductName; dalProduct.UnitPrice = model.UnitPrice; dalProduct.UnitsInStock = model.UnitsInStock; dalProduct.Discontinued = false; //dalProduct.ProductID = Guid.NewGuid().ToString().Substring(0, 5); return(dalProduct); }
private Product MapProduct(ProductsDALModel item) { var product = new Product(); product.ProductName = item.ProductName; product.ProductID = item.ProductID; product.SupplierID = item.SupplierID; product.CategoryID = item.CategoryID; product.QuantityPerUnit = item.QuantityPerUnit; product.UnitPrice = item.UnitPrice; product.UnitsInStock = item.UnitsInStock; product.UnitsOnOrder = item.UnitsOnOrder; product.ReorderLevel = item.ReorderLevel; product.Discontinued = item.Discontinued; return(product); }
public bool InsertNewProduct(ProductsDALModel dalModel) { var sql = $@"INSERT INTO Products (ProductName) Values(@{nameof(dalModel.ProductName)})"; using (var connection = new SqlConnection(_config.ConnectionString)) { var result = connection.Execute(sql, dalModel); if (result == 1) { return(true); } else { return(false); } } }
public bool DeleteProduct(ProductsDALModel modelToDelete, int ID) { var sql = $@"DELETE FROM Products where ProductID = @ProductID"; using (var connection = new SqlConnection(_config.ConnectionString)) { var result = connection.Execute(sql, modelToDelete); //return true; if (result == 1) { return(true); } else { return(false); } } }
public bool UpdateProduct(ProductsDALModel modelToUpdate, int ID) { var sql = @"UPDATE Products SET ProductName = @ProductName, QuantityPerUnit = @QuantityPerUnit, UnitPrice = @UnitPrice, UnitsInStock = @UnitsInStock, UnitsOnOrder = @UnitsOnOrder, ReorderLevel = @ReorderLevel, Discontinued = @Discontinued WHERE ProductID = @ProductID"; using (var connection = new SqlConnection(_config.ConnectionString)) { var result = connection.Execute(sql, modelToUpdate); if (result == 1) { return(true); } else { return(false); } } }