public async Task <object> Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            string imagePath = string.Empty;

            if (request.Image != null)
            {
                imagePath = await _imageService.UploadAsync(request.Image);
            }

            var product = new OnlineShop.Domain.Entities.Product()
            {
                Name          = request.Name,
                Description   = request.Description,
                Price         = request.Price,
                MeasureUnitId = request.MeasureUnit,
                VendorId      = request.Vendor,
                Qty           = request.Qty,
                ImagePath     = imagePath,
                CategoryId    = request.Category,
                Active        = true
            };

            try
            {
                await dbContext.Products.AddAsync(product);

                await dbContext.SaveChangesAsync();

                return(new { message = "Succesfuly created product" });
            }
            catch (Exception ex)
            {
                return(new { error = ex.Message });
            }
        }
示例#2
0
 public ProductViewModel(Product product)
 {
     this.Id = product.Id;
     this.Name = product.Name;
     this.Type = product.Type.Name;
     this.Manufacture = product.Manufacture.Name;
     this.Price = product.Price;
     this.Thumbnail = product.Thumbnail;
 }
        public async Task<IHttpActionResult> PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            await _productService.UpdateProduct(product);

            return StatusCode(HttpStatusCode.NoContent);
        }
示例#4
0
 public async Task UpdateProduct(Product product)
 {
     await _manageService.EditEntityAsync(product);
 }
示例#5
0
 public async Task AddProduct(Product product)
 {
     await _manageService.AddEntityAsync(product);
 }
        public async Task<IHttpActionResult> PostProduct(Product product)
        {
            await _productService.AddProduct(product);

            return CreatedAtRoute("Product", new { id = product.Id }, product);
        }