public async Task <bool> CreateProduct(ProductCommand request) { using var conn = await _database.CreateConnectionAsync(); var db = new QueryFactory(conn, new SqlServerCompiler()); if (!await IsProductKeyUnique(db, request.ProductKey, Guid.Empty)) { return(false); } var affectedRecords = await db.Query("Product").InsertAsync(new { ProductId = Guid.NewGuid(), ProductKey = request.ProductKey, ProductName = request.ProductName, ProductImageUri = request.ProductImageUri, ProductTypeID = request.ProductTypeID, RecordStatus = request.RecordStatus, CreatedDate = DateTime.UtcNow, UpdatedUser = Guid.NewGuid() }); return(affectedRecords > 0); }
public ProductVM() { Product = new Product() { DateOfRecord = DateTime.Now, DateOfPurchase = DateTime.Now.ToShortDateString() }; //{ // ProductName = "Samsung Galaxy S9", // ProductCategory_1 = CategoryList[0], // ProductCategory_2 = SubCategoryList[0], // , // DateOfPurchase = DateTime.Now.ToShortDateString(), // UnitPurchasePrice = 600000, // UnitSalePrice = 800000, // MaxDiscount = 50000, // Quantity = 30, // EmployeeId = 25 //}; ProductList = new ObservableCollection <Product>(); FillProductGrid(); // Retrieve data from the database CategoryList = new List <string>(); SubCategoryList = new List <string>(); GetProductStructure(); ProductCmd = new ProductCommand(this); }
public void AddItemToBasket() { //Arrange var item = new ProductCommand { Price = 10, ProductId = 1234 }; //var basket = new BasketCommand { Products = new List<ProductCommand>()}; var customer = new UserModel { UserName = "******", Email = "*****@*****.**", PasswordHash = "password", LoyaltyLevel = CustomerLoyalty.Standard, YearlySpend = 10, BasketId = 1 }; //Act var userRepository = new UserRepository(); var customerResult = userRepository.GetUserByName(customer.UserName).Result; //var basketRepository = new BasketRepository; //basketRepository.AddItem(customerFromJson.UserId, item.ProductId); //Assert Assert.AreEqual(customer.UserName, customerResult.UserName); Assert.AreEqual(customer.Email, customerResult.Email); Assert.AreEqual(customer.PasswordHash, customerResult.PasswordHash); Assert.AreEqual(customer.LoyaltyLevel, customerResult.LoyaltyLevel); Assert.AreEqual(customer.YearlySpend, customerResult.YearlySpend); }
public int AddProduct(Product p) { // TODO : ajouter des contrôles sur le produit (exemple : vérification de champ, etc.) ProductCommand pc = new ProductCommand(context); return(pc.Add(p)); }
public void EditProduct(Product p) { // TODO : ajouter des contrôles sur le produit (exemple : vérification de champ, etc.) ProductCommand pc = new ProductCommand(context); pc.Edit(p); }
public IProductBusinessManagerCommand createCommand() { IProducCommand productCommandData = new ProductCommand(dbSingleton); IProductoQuery productQueryData = new ProductQuery(dbSingleton); IProductBusinessManagerCommand productCommand = new ProductBusinessManagerCommand(productQueryData, productCommandData); return(productCommand); }
private void Create() { double weight = double.Parse(txtWeight.Text); decimal price = decimal.Parse(txtPrice.Text); decimal totalPrice = decimal.Parse(txtTotalPrice.Text); Command = new ProductCommand(txtName.Text, txtBrand.Text, GetCategoryId(), GetPackingTypeId(), price, GetRefrigeratedId(), dateExpiration.Value, weight, txtDescription.Text, totalPrice); CreateHandler.Trigger(Command); }
internal static void Command() { Console.WriteLine("Command pattern demo"); Console.WriteLine("------------------------------------"); var modifyPrice = new ModifyPrice(); var product = new Product("IPhone", 25000); var productCommand = new ProductCommand(product, PriceAction.Increase, 1000); modifyPrice.SetCommand(productCommand); modifyPrice.Invoke(); Console.WriteLine(product); var productCommand2 = new ProductCommand(product, PriceAction.Decrease, 500); modifyPrice.SetCommand(productCommand2); modifyPrice.Invoke(); Console.WriteLine(product); modifyPrice.Undo(); Console.WriteLine(product); Console.WriteLine(""); Console.WriteLine("------------------------------------"); Console.WriteLine("Command pattern demo 2"); Console.WriteLine("------------------------------------"); var bank = new BankAccount(); var cmd = new BankCommand(); bank.Balance = 90000; Console.WriteLine($"Balance: {bank.Balance}"); cmd.Amount = 1000; Console.WriteLine($"Deposit: {cmd.Amount}"); cmd.BalanceAction = _4_Behavioral_Patterns.Command.Demo2.Action.Deposit; bank.Execute(cmd); cmd.Amount = 2000; Console.WriteLine($"Deposit: {cmd.Amount}"); cmd.BalanceAction = _4_Behavioral_Patterns.Command.Demo2.Action.Deposit; bank.Execute(cmd); cmd.Amount = 8000; Console.WriteLine($"Withdraw: {cmd.Amount}"); cmd.BalanceAction = _4_Behavioral_Patterns.Command.Demo2.Action.Withdraw; bank.Execute(cmd); cmd.Amount = 100000; Console.WriteLine($"Withdraw: {cmd.Amount}"); cmd.BalanceAction = _4_Behavioral_Patterns.Command.Demo2.Action.Withdraw; bank.Execute(cmd); Console.WriteLine($"Balance: {bank.Balance}"); }
public void ProductHandler_create_sucess() { var handler = new ProductHandler(new FakeProductRepository()); var command = new ProductCommand(); command.Name = "Product D"; command.Price = 5; var dataResult = handler.Create(command); Assert.IsTrue(dataResult.Success); }
public void ProductHandler_create_productName_less_than_5_characters_invalid() { var handler = new ProductHandler(new FakeProductRepository()); var command = new ProductCommand(); command.Name = "Prod"; command.Price = 5; var dataResult = handler.Create(command); Assert.IsFalse(dataResult.Success); }
public void ProductHandler_updatePrice_null_invalid() { var handler = new ProductHandler(new FakeProductRepository()); var command = new ProductCommand(); command.Id = new Guid("C56A4180-65AA-42EC-A945-5FD21DEC0537"); command.Name = "Product A"; command.Price = null; var dataResult = handler.UpdatePrice(command); Assert.IsFalse(dataResult.Success); }
void HandleProductCommand(ProductCommand cmd) { var productIdStr = cmd.ProductId.ToString(); var child = Context.Child(productIdStr); if (child is Nobody) { // TODO: Handle product does not exist. throw new NotImplementedException(); } child.Forward(cmd); }
public async Task AttemptToGetJsonFromBadHttpUrlToEnsureWebExceptionCaught() { IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://baduritesting.co"))); var command = new ProductCommand(); var result = await handler.SendRequestAsync( command, new MockMusicClientSettings("test", null, null), null, command.HandleRawData, null, null); Assert.IsNotNull(result, "Expected a result"); Assert.IsNotNull(result.Error, "Expected an error"); Assert.IsNull(result.Result, "Expected no result object"); }
public async Task AttemptToGetStatusCodeFromRealUri() { IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com"))); var command = new ProductCommand(); var result = await handler.SendRequestAsync( command, new MockMusicClientSettings("test", null, null), null, command.HandleRawData, null, null); Assert.IsNotNull(result, "Expected a result"); Assert.IsNotNull(result.Error, "Expected an error"); Assert.IsNull(result.Result, "Expected no result object"); Assert.IsNotNull(result.StatusCode, "Expected a status code - this test can fail when you run tests with no internet connection!"); }
static void Main(string[] args) { var product = new ProductCommand(); product.Id = new Guid("C56A4180-65AA-42EC-A945-5FD21DEC0537"); product.Name = "Product E"; product.Price = 99; var handler = new ProductHandler(new FakeProductRepository()); var dataResult = handler.UpdatePromotionPrice(product); if (dataResult.Success) { Console.WriteLine(dataResult.Message); Console.WriteLine(dataResult.Data); } else { Console.WriteLine(dataResult.Message); } }
public async Task RequestWithValidHeaderIsSuccessful() { IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com"))); var command = new ProductCommand(); var result = await handler.SendRequestAsync( command, new MockMusicClientSettings("test", null, null), null, command.HandleRawData, new Dictionary <string, string> { { "Custom", @"test" } }, null); Assert.IsNotNull(result, "Expected a result"); Assert.IsNotNull(result.Error, "Expected an error"); Assert.IsNull(result.Result, "Expected no result object"); Assert.IsNotNull(result.StatusCode, "Expected a status code - this test can fail when you run tests with no internet connection!"); }
public DataResult Create(ProductCommand command) { try { var entity = new Product(command.Name, command.Price); var dataResult = _repository.Create(entity); if (dataResult.Success) { return(new DataResult(true, dataResult.Message, dataResult.Data)); } else { return(new DataResult(false, dataResult.Message, null)); } } catch (Exception ex) { return(new DataResult(false, ex.Message.ToString(), null)); } }
public async Task TimeoutResponseGivesNoStatusCode() { MusicClient.RequestTimeout = 1; IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com"))); var command = new ProductCommand(); var result = await handler.SendRequestAsync( command, new MockMusicClientSettings("test", null, null), null, command.HandleRawData, null, null); // Wait for the response and parsing... Assert.AreEqual(1, MusicClient.RequestTimeout, "Expected timeout to return same value that was set"); Assert.IsNotNull(result, "Expected a result"); Assert.IsNotNull(result.Error, "Expected an error, status code:" + result.StatusCode); Assert.IsNull(result.Result, "Expected no result object"); Assert.IsNull(result.StatusCode, "Expected no status code"); }
public DataResult UpdatePromotionPrice(ProductCommand command) { try { var entity = _repository.GetById(command.Id); entity.UpdatePromotionPrice(command.Price); var dataResult = _repository.Update(entity); if (dataResult.Success) { return(new DataResult(true, dataResult.Message, dataResult.Data)); } else { return(new DataResult(false, dataResult.Message, null)); } } catch (Exception ex) { return(new DataResult(false, ex.Message.ToString(), null)); } }
public void DeleteProduct(int productId) { ProductCommand pc = new ProductCommand(context); pc.Delete(productId); }
public void SetCommand(ProductCommand command) => _command = command;
public IActionResult MakeOrder([FromBody] ProductCommand requestModel) { var response = _iMediator.Send(requestModel); return(Ok(response)); }
public void Execute(ProductCommand productCommand) { SetCommand(productCommand); Invoke(); }
public async Task RequestWithValidHeaderIsSuccessful() { IApiRequestHandler handler = new ApiRequestHandler(new TestHttpUriBuilder(new Uri("http://www.nokia.com"))); var command = new ProductCommand(); var result = await handler.SendRequestAsync( command, new MockMusicClientSettings("test", null, null), null, command.HandleRawData, new Dictionary<string, string> { { "Custom", @"test" } }, null); Assert.IsNotNull(result, "Expected a result"); Assert.IsNotNull(result.Error, "Expected an error"); Assert.IsNull(result.Result, "Expected no result object"); Assert.IsNotNull(result.StatusCode, "Expected a status code - this test can fail when you run tests with no internet connection!"); }
public int CreateProduct(Product p) { ProductCommand pc = new ProductCommand(_context); return(pc.Create(p)); }
public async Task <ActionResult <bool> > Post(ProductCommand command) { return(await Mediator.Send(command)); }
public int AddProduct(Product p) { ProductCommand pc = new ProductCommand(context); return(pc.Add(p)); }
public void EditProduct(Product p) { ProductCommand pc = new ProductCommand(context); pc.Edit(p); }
public List <ProductDTO> GetProducts(ProductCommand command, ref int pagesCount) { return(new ProductDalFacade().GetProducts(command, ref pagesCount)); }
public async Task <IActionResult> PostAsync(ProductCommand data) { var result = await _mediatr.Send(data); return(Ok(result)); }
public void DeleteProduit(int produitID) { ProductCommand pc = new ProductCommand(_context); pc.Delete(produitID); }