public async Task <bool> CreateProductType(CreateProductTypeCommand request)
        {
            using var conn = await _database.CreateConnectionAsync();

            //var db = new QueryFactory(conn, new SqlServerCompiler());

            //if (!await IsProductTypeKeyUnique(db, request.ProductTypeKey, Guid.Empty))
            //    return false;

            //var affectedRecords = await db.Query("ProductType").InsertAsync(new
            //{
            //    ProductTypeId = Guid.NewGuid(),
            //    ProductTypeKey = request.ProductTypeKey,
            //    ProductTypeName = request.ProductTypeName,
            //    RecordStatus = request.RecordStatus,
            //    CreatedDate = DateTime.UtcNow,
            //    UpdatedUser = Guid.NewGuid()
            //});
            var parameters = new {
                ProductTypeKey  = request.ProductTypeKey,
                ProductTypeName = request.ProductTypeName,
                RecordStatus    = request.RecordStatus,
                CreatedDate     = DateTime.UtcNow,
                UpdatedUser     = Guid.NewGuid()
            };
            var affectedRecords = await conn.ExecuteAsync("INSERT INTO ProductType(ProductTypeKey, ProductTypeName, RecordStatus,CreatedDate, UpdatedUser) " +
                                                          "VALUES(@ProductTypeKey, @ProductTypeName, @RecordStatus, @CreatedDate, @UpdatedUser)",
                                                          parameters);

            return(affectedRecords > 0);
        }
        public CreateProductTypeCommandValidatorTests()
        {
            _model = new CreateProductTypeCommand
            {
                ProductTypeKey  = "TypeId1",
                ProductTypeName = "TypeName1"
            };

            _validator = new CreateProductTypeCommandValidator();
        }
        public async Task CreateProductType_ValidRequest_SuccessResult()
        {
            var requestModel = new CreateProductTypeCommand
            {
                ProductTypeKey  = "ProductKey",
                ProductTypeName = "ProductTypeName"
            };


            //Arrange
            BaseMediator.Setup(x => x.Send(requestModel, new CancellationToken())).
            ReturnsAsync(true);
            var productTypesController = new ProductTypesController(BaseMediator.Object);

            //Action
            var result = await productTypesController.Post(requestModel);

            //Assert
            Assert.True(result.Value);
        }
 public async Task <ActionResult <bool> > Post(CreateProductTypeCommand command)
 {
     return(await Mediator.Send(command));
 }
 public async Task <ActionResult <string> > Create(CreateProductTypeCommand command)
 {
     return(await Mediator.Send(command));
 }
Ejemplo n.º 6
0
 public void AddProductType([FromBody] CreateProductTypeCommand command)
 {
     _commandDispatcher.Dispatch(command);
 }