Ejemplo n.º 1
0
        public async Task <IActionResult> Put(Guid id, [FromBody] InsertProduct data)
        {
            var product = await _unitOfWork.Products.GetById(id);

            product.Name         = data.Name;
            product.Price        = data.Price;
            product.Status       = (int)Status.Active;
            product.ModifiedBy   = data.ModifiedBy;
            product.DateModified = DateTime.Now;
            if (data.FileData == null)
            {
                product.ProductImage = "default.jpg";
            }
            else
            {
                if (product.ProductImage != "default.jpg")
                {
                    SaveFile.DeteFile(product.ProductImage);
                }
                product.ProductImage = SaveFile.SaveB64File(data.FileData);
            }
            product = _unitOfWork.Products.CreateNewAddReturnObject(product);
            if (_unitOfWork.Commit())
            {
                return(Created(Url.Action("Get"), _mapper.Map <ProductMv>(product)));
            }
            return(BadRequest());
        }