public OrdersProductItemsDTO(OrdersProductItems ordersProductItems) { OrderId = ordersProductItems.OrderId; ProductItemId = ordersProductItems.ProductItemId; ProductItem = new ProductItemDTO(ordersProductItems.ProductItem); QuantityOfItem = ordersProductItems.QuantityOfItem; }
// ******************************************************************************************************************************* #region - CRUD - public async Task <string> CreateItemAsync(ProductItemDTO dto) { var msgCode = CheckItemDTO(dto); if (!msgCode.IsSuccess()) { return(msgCode); } // ^^^^^^^^^^ var existsItem = await ProductItemDAL.GetItemAsync(dto.ASIN, dto.SKU).ConfigureAwait(false); if (existsItem.IsNotNull()) { return("Item already exists."); } msgCode = await ProductItemDAL.InsertItemAsync(dto).ConfigureAwait(false); if (msgCode.IsSuccess()) { // 抛出Item更改事件 _ = MessageDispatcher.PublishAsync(new ProductItemChangedEvent(dto.ASIN)); } return(msgCode); }
// ******************************************************************************************************************************* #region - CRUD - public Task <string> InsertItemAsync(ProductItemDTO dto) { return(base.TryExecuteAsync(@"INSERT INTO ProductItem (SKU, ASIN, Alias, Color, Size, Url, InvQty, HoldInvQty) VALUES (@SKU, @ASIN, @Alias, @Color, @Size, @Url, @InvQty, @HoldInvQty)", dto)); }
private async Task ValidateShopCartItem(ProductItemDTO product, int quantity) { if (product == null) { AddProcessingError("Product doesn't exist!"); } if (quantity > 1) { AddProcessingError($"Choose at least an unit of {product.Name}"); } var shopCart = await _shopCartService.GetShopCart(); var shopCartItem = shopCart.Items.FirstOrDefault(i => i.ProductId == product.Id); if (shopCartItem != null && shopCartItem.Quantity + quantity > product.StockQuantity) { AddProcessingError($"Product {product.Name} has {product.StockQuantity} stock units, you have selected {quantity}"); return; } if (quantity > product.StockQuantity) { AddProcessingError($"Product {product.Name} has {product.StockQuantity} stock units, you have selected {quantity}"); } }
public async Task SetupAsync() { // ¹¹ÔìProductItem _productItem = _fixture.Create <ProductItemDTO>(); _productItem.ASIN = "test_product"; _productItem.SKU = "test_item_0001"; _productItem.Alias = "test_alias"; _productItem.Color = "test_color"; _productItem.Size = "test_szie"; }
/// <summary> /// borrar un producto /// </summary> /// <param name="item"></param> public void DeleteProduct(ProductItemDTO item) { var _page = source.Where(o => o.Id == 1).FirstOrDefault(); if (_page != null) { var page = _page as ProductListDTO; page.Delete(item); page.RenderCost(); } }
public async Task <IActionResult> Create([FromBody] ProductItemDTO productItem) { if (!ModelState.IsValid) { return(BadRequest("invalid model state")); } var category = _mapper.Map <ProductItem>(productItem); var r = await _dbContext.ProductItems.AddAsync(category); await _dbContext.SaveChangesAsync(); return(Ok(_mapper.Map <ProductItemDTO>(category))); }
public ProductItemDTO GetProduct([FromRoute] int id) { var data = _context.Products.FirstOrDefault(t => t.Id == id); ProductItemDTO prod = new ProductItemDTO(); prod.Name = data.Name; prod.CompanyName = data.CompanyName; prod.Price = data.Price; prod.Description = data.Description; prod.Image = data.Image; prod.Data = data.Data; return(prod); }
// ******************************************************************************************************************************* #region - Utilities - private string CheckItemDTO(ProductItemDTO dto) { if (dto.ASIN.IsNull()) { return(MsgCodes.ASINCannotBeEmpty); } if (dto.SKU.IsNull()) { return(MsgCodes.SKUCannotBeEmpty); } if (dto.ASIN.IsNotNull() && dto.ASIN.Length > 20) { return(MsgCodes.InvalidASINLength); } if (dto.SKU.IsNotNull() && dto.SKU.Length > 20) { return(MsgCodes.InvalidSKULength); } if (dto.Alias.IsNotNull() && dto.Alias.Length > 200) { return(MsgCodes.InvalidAliasLength); } if (dto.Color.IsNotNull() && dto.Color.Length > 30) { return(MsgCodes.InvalidColorLength); } if (dto.Size.IsNotNull() && dto.Size.Length > 30) { return(MsgCodes.InvalidSizeLength); } if (dto.Url.IsNotNull() && dto.Url.Length > 200) { return(MsgCodes.InvalidImageUrlLength); } if (dto.InvQty < 0) { return(MsgCodes.InvalidInventoryQuantity); } return(MsgCodes.SUCCESS); }
public IEnumerable <ProductItemDTO> getProducts() { List <ProductItemDTO> data = new List <ProductItemDTO>(); var dataFormDB = _context.Products.ToList(); foreach (var item in dataFormDB) { ProductItemDTO temp = new ProductItemDTO(); temp.CompanyName = item.CompanyName; temp.Data = item.Data; temp.Id = item.Id; temp.Image = item.Image; temp.Name = item.Name; temp.Price = item.Price; data.Add(temp); } return(data); }
public async Task <string> UpdateItemAsync(ProductItemDTO dto) { var msgCode = CheckItemDTO(dto); if (!msgCode.IsSuccess()) { return(msgCode); } // ^^^^^^^^^^ msgCode = await ProductItemDAL.UpdateItemAsync(dto).ConfigureAwait(false); if (msgCode.IsSuccess()) { // 抛出库存更改事件 _ = MessageDispatcher.PublishAsync(new ItemInventoryChangedEvent(dto.SKU, dto.InvQty)); // 抛出Item更改事件 _ = MessageDispatcher.PublishAsync(new ProductItemChangedEvent(dto.ASIN)); } return(msgCode); }
// ******************************************************************************************************************************* #region - CRUD - public Task <string> InsertItemAsync(ProductItemDTO dto) => DB.ProductItems.TryInsertOneAsync(dto);
public Task <string> UpdateItemAsync(ProductItemDTO dto) { return(base.TryExecuteAsync(@"UPDATE ProductItem SET Alias = @Alias, Color = @Color, Size = @Size, Url = @Url, InvQty = @InvQty WHERE SKU = @SKU AND ASIN = @ASIN", dto)); }