static void Main() { ProductOption productOption = new ProductOption { Name = "iPhone", Price = 500, Quantity = 4 }; using CrmDbContext db = new CrmDbContext(); ProductManagement productManager = new ProductManagement(db); Product product = productManager.CreateProduct(productOption); Console.WriteLine($"Id= {product.Id} Price= {product.Price} Quantityy= {product.Quantity}"); //CustomerOption custOpt = new CustomerOption //{ // FirstName = "Maria", // LastName = "Pentagiotissa", // Address = "Athens", // Email = "*****@*****.**", //}; //using CrmDbContext db = new CrmDbContext(); //CustomerManagement custManager = new CustomerManagement(db); ////testing the creation of a customer //Customer customer = custManager.CreateCustomer(custOpt); //Console.WriteLine($"Id= {customer.Id} Address= {customer.Address}"); ////testing reading a customer //Customer cx = custManager.FindCustomerById(2); //Console.WriteLine($"Id= {cx.Id} Address= {cx.Address}"); ////testing updating //CustomerOption custChangeAdress = new CustomerOption //{ // Address = "Lamia" //}; //Customer c2 = custManager.Update(custChangeAdress, 2); //Console.WriteLine($"Id= {cx.Id} Address= {cx.Address}"); ////testing deletion //bool result = custManager.DeleteCustomerById(2); //Console.WriteLine($"Result = {result}"); //Customer cx2 = custManager.FindCustomerById(2); //if (cx2 != null) //{ // Console.WriteLine( // $"Id= {cx2.Id} Name= {cx2.FirstName} Address= {cx2.Address}"); //} //else //{ // Console.WriteLine("not found"); //} }
private void btnCreate_Click(object sender, EventArgs e) { string DescripPrice = txtDescripPrice.Text; string PriceTag = txtPriceTag.Text; if (string.IsNullOrEmpty(DescripPrice.Trim())) { MetroMessageBox.Show(this, "La Descripción -" + DescripPrice + "- no es Valida. \n Favor Digite una Descripción Valida", "Error en Validación", MessageBoxButtons.OK, MessageBoxIcon.Error); txtDescripPrice.Focus(); return; } if (string.IsNullOrEmpty(PriceTag.Trim())) { MetroMessageBox.Show(this, "El Precio -" + PriceTag + "- no es Valido. \n Favor Digite un Precio Valido", "Error en Validación", MessageBoxButtons.OK, MessageBoxIcon.Error); txtDescripPrice.Focus(); return; } else { try { ObjPrice.Descrip_Price = DescripPrice; ObjPrice.Total_Product = Convert.ToDecimal(PriceTag); ObjPrice.CreateBy = pIdSession; ApiAccess.CreateProduct(ObjPrice); } catch (Exception) { throw; } CleanFields(); LoadDataGrid(); } }
public Product PostProduct(ProductOption prodOpt) { using CrmDbContext db = new CrmDbContext(); ProductManagement prodMangr = new ProductManagement(db); return(prodMangr.CreateProduct(prodOpt)); }
public void CreateProductException() { ProductManagement productManagement = new ProductManagement(); List <Product> products = new List <Product>(); var exception = Assert.Throws <System.Exception>(() => productManagement.CreateProduct(products)); Assert.Equal("Product details not available", exception.Message); }
private static ProductManagement CreateProduct(ProductOption prodOpt, CrmDbContext db) { ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prodOpt); Console.WriteLine( $"ProductName={product.ProductName} Price={product.Price} Quantity={product.Quantity} TotalCost={product.TotalCost}"); return(prodMangr); }
public void CreateProductFailureValidation() { ProductManagement productManagement = new ProductManagement(); productManagement.CreateProduct(); ProductRepository productRepository = new ProductRepository(); var result2 = productRepository.GetAllProducts(); Assert.True(result2.Count() == 21, "No of Product count is not matched"); }
public void CreateProductSuccessValidation() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); ProductRepository productRepository = new ProductRepository(); var result1 = productRepository.GetAllProducts(); Assert.True(result1.Count() == 22, "No of Product count is not matched"); }
public void ReadProductsSucces() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); //var productManagement = new ProductManagement(); var productsReaded = productManagement.GetAllProducts(); Assert.True(productsReaded); }
public void DeleteProductException() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); Product product2 = new Product() { Name = "SesameOil", Price = 89.50m, ProductId = -1, ProductInStock = 0, ManufacturerDetails = new Manufacturer() { ManufacturerName = "FRE", Place = "Nordstan", PhoneNumber = 764536267 } }; var throwException = Assert.Throws <System.Exception>(() => productManagement.RemoveProduct(product2)); Assert.Equal("ProductID should be a positive number", throwException.Message); }
public void DeleteProductFailureValidation() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); Product product2 = new Product() { Name = "Milk", Price = 42.89m, ProductId = 2000, ProductInStock = 10, ManufacturerDetails = new Manufacturer() { ManufacturerName = "TRT", Place = "Hjlmar", PhoneNumber = 764075849 } }; string result2 = productManagement.RemoveProduct(product2); Assert.Equal("Product id not exist", result2); }
public void UpdateProductException() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); Product product = new Product() { Name = "Salt", Price = 199.95m, ProductId = -1, ProductInStock = 11, ManufacturerDetails = new Manufacturer() { ManufacturerName = "EEE", Place = "Hjlmar", PhoneNumber = 764586231 } }; var throwException = Assert.Throws <System.Exception>(() => productManagement.UpdateProduct(product)); Assert.Equal("ProductID should be a positive number", throwException.Message); }
public void UpdateProductSucces() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); Product product1 = new Product() { Name = "Salt", Price = 199.95m, ProductId = 654, ProductInStock = 11, ManufacturerDetails = new Manufacturer() { ManufacturerName = "EEE", Place = "Hjlmar", PhoneNumber = 764586231 } }; string result = productManagement.UpdateProduct(product1); Assert.Equal("Product Name and Price are updated successfully", result); }
public void DeleteProductFailureValidationWithoutPassingtheProductId() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); Product product2 = new Product() { Name = "SesameOil", Price = 89.50m, ProductInStock = 0, ManufacturerDetails = new Manufacturer() { ManufacturerName = "FRE", Place = "Nordstan", PhoneNumber = 764536267 } }; string result3 = productManagement.RemoveProduct(product2); Assert.Equal("Please provide the valid ProductId", result3); }
public void DeleteProductSuccessValidation() { ProductManagement productManagement = new ProductManagement(); List <Product> products = BindProducts(); productManagement.CreateProduct(products); Product product2 = new Product() { Name = "SesameOil", Price = 89.50m, ProductId = 809, ProductInStock = 0, ManufacturerDetails = new Manufacturer() { ManufacturerName = "FRE", Place = "Nordstan", PhoneNumber = 764536267 } }; string result1 = productManagement.RemoveProduct(product2); Assert.Equal("Product item is removed successfully", result1); }
public ActionResult CreateUpdateProduct(EditProductDTO dto) { if (dto == null) { throw new NullReferenceException("DTO cannot be null"); } var validationIds = new List <string>(); var validationMessage = Validate(dto, out validationIds); if (!validationMessage.Any()) { if (dto.IsCreating) { ProductManagement.CreateProduct(dto); } else { ProductManagement.UpdateProduct(dto); } var products = ProductManagement.GetProductsIncludeHidden(); var categories = CategoryManagement.GetAllCategory(); var totalProductPage = (int)Math.Ceiling(((double)products.Count() / (double)pageSize)); return(Json(new { products = ApplyPaging(products, 1).Select(x => ConvertToProductDTO(x, categories)), passed = !validationMessage.Any(), validationIds, validationMessage = string.Join("</br>", validationMessage), totalProductPage })); } return(Json(new { passed = !validationMessage.Any(), validationIds, validationMessage = string.Join("</br>", validationMessage) })); }
public static void RunBasketCRUD() { //connect to the DB using CrmDbContext db = new CrmDbContext(); //to using to xrisomopioume anti gia to dispose (disconnect apo vasi) ProductOption prOpt = new ProductOption { ProductName = "apples", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); //Console.WriteLine(basket.BasketProducts[0], Product.ProductName); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product.ProductName)); }
public static void Main() { //CustomerOption custOpt = new CustomerOption //{ // FirstName = "Tester222", // LastName = "Test", // Address = "TestCity", // Email = "*****@*****.**", //}; using CrmAppDbContext db = new CrmAppDbContext(); CustomerManagement custMangr = new CustomerManagement(db); ////testing the creation of a customer //Customer customer = custMangr.CreateCustomer(custOpt); //Console.WriteLine( //$"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing reading a customer //customer = custMangr.FindCustomerById(2); //if (customer != null) // Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing updating //CustomerOption custChangingAddress = new CustomerOption //{ // Address = "Lamia" //}; //customer = custMangr.Update(custChangingAddress, 1); //Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); ////testing deletion //bool result = custMangr.DeleteCustomerById(2); //Console.WriteLine($"Result = {result}"); //customer = custMangr.FindCustomerById(2); //if (customer != null) //{ // Console.WriteLine( // $"Id= {customer.CustomerId} Name= {customer.FirstName} Address= {customer.Address}"); //} //else //{ // Console.WriteLine("not found"); //} ProductOption prOpt = new ProductOption { Name = "portokalia", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 5 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; //System.NullReferenceException BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach( baskProduct => Console.WriteLine( db.BasketProducts .Include(b => b.Product) .Where(b => b.Id == baskProduct.Id) .First() .Product.Name) ); Console.ReadLine(); }
static void Main2() { CustomerOption custOpt = new CustomerOption { FirstName = "John", LastName = "XCV", Adress = "Thessaloniki", Email = "*****@*****.**", }; using CrmDbContext db = new CrmDbContext(); CustomerManagement custMngr = new CustomerManagement(db); Customer customer = custMngr.CreateCustomer(custOpt); Console.WriteLine($"Id={customer.Id} Name={customer.FirstName} Adress={customer.Adress}"); Customer cx = custMngr.FindCustomerById(2); Console.WriteLine($"Id={cx.Id} Name={cx.FirstName} Adress={cx.Adress}"); CustomerOption custChangingAdress = new CustomerOption { Adress = "Lamia" }; Customer c2 = custMngr.Update(custChangingAdress, 1); Console.WriteLine($"Id={c2.Id} Name={c2.FirstName} Adress={c2.Adress}"); bool result = custMngr.DeleteCustomerById(2); Console.WriteLine($"Result={result}"); Customer cx2 = custMngr.FindCustomerById(2); if (cx2 != null) { Console.WriteLine($"Id={cx2.Id} Name={cx2.FirstName} Adress={cx2.Adress}"); } else { Console.WriteLine("Not found"); } ProductOption prOpt = new ProductOption { Name = "apples", Price = 1.20m, Quantity = 10 }; ProductManagement prodMngr = new ProductManagement(db); Product product = prodMngr.CreateProduct(prOpt); BasketManagement baskMngr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMngr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = basket.Id, ProductId = 1 }; BasketProduct baskProd = baskMngr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product)); }
public void CreateProductException() { var productManagement = new ProductManagement(); Assert.Throws <FileNotFoundException>(() => productManagement.CreateProduct()); }
static void Main() { CustomerOption custOpt = new CustomerOption { FirstName = "Maria", LastName = "Pentagiotissa", Address = "Athens", Email = "*****@*****.**", }; using CrmDbContext db = new CrmDbContext(); CustomerManagement custMangr = new CustomerManagement(db); // testing the creation of a customer Customer customer = custMangr.CreateCustomer(custOpt); Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); //testing reading a customer customer = custMangr.FindCustomerById(2); if (customer != null) { Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); } //testing updating CustomerOption custChangingAddress = new CustomerOption { Address = "Lamia" }; customer = custMangr.Update(custChangingAddress, 1); Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); //testing deletion bool result = custMangr.DeleteCustomerById(2); Console.WriteLine($"Result = {result}"); customer = custMangr.FindCustomerById(2); if (customer != null) { Console.WriteLine( $"Id= {customer.Id} Name= {customer.FirstName} Address= {customer.Address}"); } else { Console.WriteLine("not found"); } ProductOption prOpt = new ProductOption { Name = "mila", Price = 1.20m, Quantity = 10 }; ProductManagement prodMangr = new ProductManagement(db); Product product = prodMangr.CreateProduct(prOpt); BasketManagement baskMangr = new BasketManagement(db); BasketOption baskOption = new BasketOption { CustomerId = 3 }; Basket basket = baskMangr.CreateBasket(baskOption); BasketProductOption bskProdOpt = new BasketProductOption { BasketId = 1, ProductId = 1 }; BasketProduct baskProd = baskMangr.AddProduct(bskProdOpt); basket.BasketProducts.ForEach(p => Console.WriteLine(p.Product.Name)); }