コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: ProductVM.cs プロジェクト: yamess/DataSmart
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public IProductBusinessManagerCommand createCommand()
        {
            IProducCommand productCommandData             = new ProductCommand(dbSingleton);
            IProductoQuery productQueryData               = new ProductQuery(dbSingleton);
            IProductBusinessManagerCommand productCommand = new ProductBusinessManagerCommand(productQueryData, productCommandData);

            return(productCommand);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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}");
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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");
        }
コード例 #14
0
        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");
        }
コード例 #15
0
        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!");
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
0
        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!");
        }
コード例 #18
0
        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));
            }
        }
コード例 #19
0
        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");
        }
コード例 #20
0
        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));
            }
        }
コード例 #21
0
        public void DeleteProduct(int productId)
        {
            ProductCommand pc = new ProductCommand(context);

            pc.Delete(productId);
        }
コード例 #22
0
 public void SetCommand(ProductCommand command) => _command = command;
コード例 #23
0
ファイル: ProductController.cs プロジェクト: sontv92/CQRS
        public IActionResult MakeOrder([FromBody] ProductCommand requestModel)
        {
            var response = _iMediator.Send(requestModel);

            return(Ok(response));
        }
コード例 #24
0
 public void Execute(ProductCommand productCommand)
 {
     SetCommand(productCommand);
     Invoke();
 }
コード例 #25
0
        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!");
        }
コード例 #26
0
        public int CreateProduct(Product p)
        {
            ProductCommand pc = new ProductCommand(_context);

            return(pc.Create(p));
        }
コード例 #27
0
        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!");
        }
コード例 #28
0
        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");
        }
コード例 #29
0
 public async Task <ActionResult <bool> > Post(ProductCommand command)
 {
     return(await Mediator.Send(command));
 }
コード例 #30
0
ファイル: BusinessManager.cs プロジェクト: jkermes/XProducts
        public int AddProduct(Product p)
        {
            ProductCommand pc = new ProductCommand(context);

            return(pc.Add(p));
        }
コード例 #31
0
ファイル: BusinessManager.cs プロジェクト: jkermes/XProducts
        public void EditProduct(Product p)
        {
            ProductCommand pc = new ProductCommand(context);

            pc.Edit(p);
        }
コード例 #32
0
ファイル: ProductBL.cs プロジェクト: iskandarair/ColorMixERP
 public List <ProductDTO> GetProducts(ProductCommand command, ref int pagesCount)
 {
     return(new ProductDalFacade().GetProducts(command, ref pagesCount));
 }
コード例 #33
0
        public async Task <IActionResult> PostAsync(ProductCommand data)
        {
            var result = await _mediatr.Send(data);

            return(Ok(result));
        }
コード例 #34
0
        public void DeleteProduit(int produitID)
        {
            ProductCommand pc = new ProductCommand(_context);

            pc.Delete(produitID);
        }