public Task <bool> UploadCategoryPicture(IFormFile image, int categoryId) { try { if (image == null || image.Length == 0) { return(Task.FromResult(false)); } byte[] bytesArray; using (var ms = new MemoryStream()) { image.CopyTo(ms); bytesArray = ms.ToArray(); } var category = _categoriesRepository.GetByID(categoryId); category.Picture = bytesArray; _categoriesRepository.Update(category); return(Task.FromResult(true)); } catch (Exception e) { Log.Error("Category service error!" + Environment.NewLine + $"{e}"); throw; } }
public void UpdateProduct(ProductsModel model) { try { var product = _productsRepository.GetByID(model.ProductId); product.Discontinued = model.Discontinued; product.ProductName = model.ProductName; product.QuantityPerUnit = model.QuantityPerUnit; product.ReorderLevel = model.ReorderLevel; product.UnitPrice = model.UnitPrice; product.UnitsInStock = model.UnitsInStock; product.UnitsOnOrder = model.UnitsOnOrder; product.CategoryId = model.Category?.CategoryId; product.SupplierId = model.Supplier?.SupplierId; _productsRepository.Update(product); } catch (Exception e) { Log.Error("Product service error!" + Environment.NewLine + $"{e}"); throw; } }