public async Task <bool> UpdateProductType(UpdateProductTypeCommand request) { using var conn = await _database.CreateConnectionAsync(); //var db = new QueryFactory(conn, new SqlServerCompiler()); //if (!await IsProductTypeKeyUnique(db, request.ProductTypeKey, request.ProductTypeId)) // return false; //var affectedRecord = await db.Query("ProductType").Where("ProductTypeID", "=", request.ProductTypeId).UpdateAsync(new //{ // ProductTypeKey = request.ProductTypeKey, // ProductTypeName = request.ProductTypeName, // RecordStatus = request.RecordStatus, // UpdatedDate = DateTime.UtcNow, // UpdatedUser = Guid.NewGuid() //}); var parameters = new { ProductTypeID = request.ProductTypeID, ProductTypeKey = request.ProductTypeKey, ProductTypeName = request.ProductTypeName, RecordStatus = request.RecordStatus, UpdatedDate = DateTime.UtcNow, UpdatedUser = Guid.NewGuid() }; var affectedRecords = await conn.ExecuteAsync("UPDATE ProductType SET ProductTypeKey=@ProductTypeKey, ProductTypeName=@ProductTypeName," + " RecordStatus=@RecordStatus, UpdatedDate=@UpdatedDate, UpdatedUser=@UpdatedUser WHERE ProductTypeID = @ProductTypeID", parameters); return(affectedRecords > 0); }
public void Delete(UpdateProductTypeCommand updatedProductTypeCommand, int id) { var repo = new ProductTypeRepository(); var updatedProductType = new ProductType { Name = updatedProductTypeCommand.Name, }; repo.DeleteProductType(updatedProductType, id); }
public async Task UpdateProductType_ValidRequest_SuccessResult() { var id = Guid.NewGuid(); var requestModel = new UpdateProductTypeCommand { 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.Put(id, requestModel); //Assert Assert.True(result.Value); }
public async Task <ActionResult <bool> > Put(Guid id, [FromBody] UpdateProductTypeCommand request) { request.ProductTypeID = id; return(await Mediator.Send(request)); }